1*** Settings *** 2Documentation Network interface configuration and verification 3 ... tests. 4 5Resource ../../lib/bmc_redfish_resource.robot 6Resource ../../lib/bmc_network_utils.robot 7Resource ../../lib/openbmc_ffdc.robot 8Library ../../lib/bmc_network_utils.py 9Library Collections 10 11Test Setup Test Setup Execution 12Test Teardown Test Teardown Execution 13 14Force Tags Network_Conf_Test 15 16*** Variables *** 17${test_hostname} openbmc 18${test_ipv4_addr} 10.7.7.7 19${test_ipv4_invalid_addr} 0.0.1.a 20${test_subnet_mask} 255.255.0.0 21${test_gateway} 10.7.7.1 22${broadcast_ip} 10.7.7.255 23${loopback_ip} 127.0.0.2 24${multicast_ip} 224.6.6.6 25${out_of_range_ip} 10.7.7.256 26 27# Valid netmask is 4 bytes long and has continuos block of 1s. 28# Maximum valid value in each octet is 255 and least value is 0. 29# 253 is not valid, as binary value is 11111101. 30${invalid_netmask} 255.255.253.0 31${alpha_netmask} ff.ff.ff.ff 32# Maximum value of octet in netmask is 255. 33${out_of_range_netmask} 255.256.255.0 34${more_byte_netmask} 255.255.255.0.0 35${less_byte_netmask} 255.255.255 36${threshold_netmask} 255.255.255.255 37${lowest_netmask} 128.0.0.0 38 39# There will be 4 octets in IP address (e.g. xx.xx.xx.xx) 40# but trying to configure xx.xx.xx 41${less_octet_ip} 10.3.36 42 43# For the address 10.6.6.6, the 10.6.6.0 portion describes the 44# network ID and the 6 describe the host. 45 46${network_id} 10.7.7.0 47${hex_ip} 0xa.0xb.0xc.0xd 48${negative_ip} 10.-7.-7.7 49${hex_ip} 0xa.0xb.0xc.0xd 50 51*** Test Cases *** 52 53Get IP Address And Verify 54 [Documentation] Get IP Address And Verify. 55 [Tags] Get_IP_Address_And_Verify 56 57 : FOR ${network_configuration} IN @{network_configurations} 58 \ Verify IP On BMC ${network_configuration['Address']} 59 60Get Netmask And Verify 61 [Documentation] Get Netmask And Verify. 62 [Tags] Get_Netmask_And_Verify 63 64 : FOR ${network_configuration} IN @{network_configurations} 65 \ Verify Netmask On BMC ${network_configuration['SubnetMask']} 66 67Get Gateway And Verify 68 [Documentation] Get gateway and verify it's existence on the BMC. 69 [Tags] Get_Gateway_And_Verify 70 71 : FOR ${network_configuration} IN @{network_configurations} 72 \ Verify Gateway On BMC ${network_configuration['Gateway']} 73 74Get MAC Address And Verify 75 [Documentation] Get MAC address and verify it's existence on the BMC. 76 [Tags] Get_MAC_Address_And_Verify 77 78 ${resp}= Redfish.Get ${REDFISH_NW_ETH0_URI} 79 ${macaddr}= Get From Dictionary ${resp.dict} MACAddress 80 Validate MAC On BMC ${macaddr} 81 82Verify All Configured IP And Netmask 83 [Documentation] Verify all configured IP and netmask on BMC. 84 [Tags] Verify_All_Configured_IP_And_Netmask 85 86 : FOR ${network_configuration} IN @{network_configurations} 87 \ Verify IP And Netmask On BMC ${network_configuration['Address']} 88 ... ${network_configuration['SubnetMask']} 89 90Get Hostname And Verify 91 [Documentation] Get hostname via Redfish and verify. 92 [Tags] Get_Hostname_And_Verify 93 94 ${hostname}= Redfish_Utils.Get Attribute ${REDFISH_NW_PROTOCOL_URI} HostName 95 96 Validate Hostname On BMC ${hostname} 97 98Configure Hostname And Verify 99 [Documentation] Configure hostname via Redfish and verify. 100 [Tags] Configure_Hostname_And_Verify 101 102 ${hostname}= Redfish_Utils.Get Attribute ${REDFISH_NW_PROTOCOL_URI} HostName 103 104 Configure Hostname ${test_hostname} 105 Validate Hostname On BMC ${test_hostname} 106 107 # Revert back to initial hostname. 108 Configure Hostname ${hostname} 109 Validate Hostname On BMC ${hostname} 110 111Add Valid IPv4 Address And Verify 112 [Documentation] Add IPv4 Address via Redfish and verify. 113 [Tags] Add_Valid_IPv4_Addres_And_Verify 114 115 Add IP Address ${test_ipv4_addr} ${test_subnet_mask} ${test_gateway} 116 Delete IP Address ${test_ipv4_addr} 117 118Add Invalid IPv4 Address And Verify 119 [Documentation] Add Invalid IPv4 Address via Redfish and verify. 120 [Tags] Add_Invalid_IPv4_Addres_And_Verify 121 122 Add IP Address ${test_ipv4_invalid_addr} ${test_subnet_mask} 123 ... ${test_gateway} valid_status_codes=${HTTP_BAD_REQUEST} 124 125Configure Out Of Range IP 126 [Documentation] Configure out-of-range IP address. 127 [Tags] Configure_Out_Of_Range_IP 128 [Template] Add IP Address 129 130 # ip subnet_mask gateway valid_status_codes 131 ${out_of_range_ip} ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 132 133Configure Broadcast IP 134 [Documentation] Configure broadcast IP address. 135 [Tags] Configure_Broadcast_IP 136 [Template] Add IP Address 137 [Teardown] Clear IP Settings On Fail ${broadcast_ip} 138 139 # ip subnet_mask gateway valid_status_codes 140 ${broadcast_ip} ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 141 142Configure Multicast IP 143 [Documentation] Configure multicast IP address. 144 [Tags] Configure_Multicast_IP 145 [Template] Add IP Address 146 [Teardown] Clear IP Settings On Fail ${multicast_ip} 147 148 # ip subnet_mask gateway valid_status_codes 149 ${multicast_ip} ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 150 151Configure Loopback IP 152 [Documentation] Configure loopback IP address. 153 [Tags] Configure_Loopback_IP 154 [Template] Add IP Address 155 [Teardown] Clear IP Settings On Fail ${loopback_ip} 156 157 # ip subnet_mask gateway valid_status_codes 158 ${loopback_ip} ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 159 160Add Valid IPv4 Address And Check Persistency 161 [Documentation] Add IPv4 address and check peristency. 162 [Tags] Add_Valid_IPv4_Addres_And_Check_Persistency 163 164 Add IP Address ${test_ipv4_addr} ${test_subnet_mask} ${test_gateway} 165 166 # Reboot BMC and verify persistency. 167 OBMC Reboot (off) 168 Verify IP On BMC ${test_ipv4_addr} 169 Delete IP Address ${test_ipv4_addr} 170 171Add Fourth Octet Threshold IP And Verify 172 [Documentation] Add fourth octet threshold IP and verify. 173 [Tags] Add_Fourth_Octet_Threshold_IP_And_Verify 174 175 Add IP Address 10.7.7.254 ${test_subnet_mask} ${test_gateway} 176 Delete IP Address 10.7.7.254 177 178Add Fourth Octet Lowest IP And Verify 179 [Documentation] Add fourth octet lowest IP and verify. 180 [Tags] Add_Fourth_Octet_Lowest_IP_And_Verify 181 182 Add IP Address 10.7.7.1 ${test_subnet_mask} ${test_gateway} 183 Delete IP Address 10.7.7.1 184 185Add Third Octet Threshold IP And Verify 186 [Documentation] Add third octet threshold IP and verify. 187 [Tags] Add_Third_Octet_Threshold_IP_And_Verify 188 189 Add IP Address 10.7.255.7 ${test_subnet_mask} ${test_gateway} 190 Delete IP Address 10.7.255.7 191 192Add Third Octet Lowest IP And Verify 193 [Documentation] Add third octet lowest IP and verify. 194 [Tags] Add_Third_Octet_Lowest_IP_And_Verify 195 196 Add IP Address 10.7.0.7 ${test_subnet_mask} ${test_gateway} 197 Delete IP Address 10.7.0.7 198 199Add Second Octet Threshold IP And Verify 200 [Documentation] Add second octet threshold IP and verify. 201 [Tags] Add_Second_Octet_Threshold_IP_And_Verify 202 203 Add IP Address 10.255.7.7 ${test_subnet_mask} ${test_gateway} 204 Delete IP Address 10.255.7.7 205 206Add Second Octet Lowest IP And Verify 207 [Documentation] Add second octet lowest IP and verify. 208 [Tags] Add_Second_Octet_Lowest_IP_And_Verify 209 210 Add IP Address 10.0.7.7 ${test_subnet_mask} ${test_gateway} 211 Delete IP Address 10.0.7.7 212 213Add First Octet Threshold IP And Verify 214 [Documentation] Add first octet threshold IP and verify. 215 [Tags] Add_First_Octet_Threshold_IP_And_Verify 216 217 Add IP Address 223.7.7.7 ${test_subnet_mask} ${test_gateway} 218 Delete IP Address 223.7.7.7 219 220Add First Octet Lowest IP And Verify 221 [Documentation] Add first octet lowest IP and verify. 222 [Tags] Add_First_Octet_Lowest_IP_And_Verify 223 224 Add IP Address 1.7.7.7 ${test_subnet_mask} ${test_gateway} 225 Delete IP Address 1.7.7.7 226 227Configure Invalid Netmask 228 [Documentation] Verify error while setting invalid netmask. 229 [Tags] Configure_Invalid_Netmask 230 [Template] Add IP Address 231 232 # ip subnet_mask gateway valid_status_codes 233 ${test_ipv4_addr} ${invalid_netmask} ${test_gateway} ${HTTP_BAD_REQUEST} 234 235Configure Out Of Range Netmask 236 [Documentation] Verify error while setting out of range netmask. 237 [Tags] Configure_Out_Of_Range_Netmask 238 [Template] Add IP Address 239 240 # ip subnet_mask gateway valid_status_codes 241 ${test_ipv4_addr} ${out_of_range_netmask} ${test_gateway} ${HTTP_BAD_REQUEST} 242 243Configure Alpha Netmask 244 [Documentation] Verify error while setting alpha netmask. 245 [Tags] Configure_Alpha_Netmask 246 [Template] Add IP Address 247 248 # ip subnet_mask gateway valid_status_codes 249 ${test_ipv4_addr} ${alpha_netmask} ${test_gateway} ${HTTP_BAD_REQUEST} 250 251Configure More Byte Netmask 252 [Documentation] Verify error while setting more byte netmask. 253 [Tags] Configure_More_Byte_Netmask 254 [Template] Add IP Address 255 256 # ip subnet_mask gateway valid_status_codes 257 ${test_ipv4_addr} ${more_byte_netmask} ${test_gateway} ${HTTP_BAD_REQUEST} 258 259Configure Less Byte Netmask 260 [Documentation] Verify error while setting less byte netmask. 261 [Tags] Configure_Less_Byte_Netmask 262 [Template] Add IP Address 263 264 # ip subnet_mask gateway valid_status_codes 265 ${test_ipv4_addr} ${less_byte_netmask} ${test_gateway} ${HTTP_BAD_REQUEST} 266 267Configure Threshold Netmask And Verify 268 [Documentation] Configure threshold netmask and verify. 269 [Tags] Configure_Threshold_Netmask_And_verify 270 271 Add IP Address ${test_ipv4_addr} ${threshold_netmask} ${test_gateway} 272 Delete IP Address ${test_ipv4_addr} 273 274Configure Lowest Netmask And Verify 275 [Documentation] Configure lowest netmask and verify. 276 [Tags] Configure_Lowest_Netmask_And_verify 277 278 Add IP Address ${test_ipv4_addr} ${lowest_netmask} ${test_gateway} 279 Delete IP Address ${test_ipv4_addr} 280 281Configure Network ID 282 [Documentation] Verify error while configuring network ID. 283 [Tags] Configure_Network_ID 284 [Template] Add IP Address 285 [Teardown] Clear IP Settings On Fail ${network_id} 286 287 # ip subnet_mask gateway valid_status_codes 288 ${network_id} ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 289 290Configure Less Octet IP 291 [Documentation] Verify error while Configuring less octet IP address. 292 [Tags] Configure_Less_Octet_IP 293 [Template] Add IP Address 294 295 # ip subnet_mask gateway valid_status_codes 296 ${less_octet_ip} ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 297 298Configure Empty IP 299 [Documentation] Verify error while Configuring empty IP address. 300 [Tags] Configure_Empty_IP 301 [Template] Add IP Address 302 303 # ip subnet_mask gateway valid_status_codes 304 ${EMPTY} ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 305 306Configure Special Char IP 307 [Documentation] Configure invalid IP address containing special chars. 308 [Tags] Configure_Special_Char_IP 309 [Template] Add IP Address 310 311 # ip subnet_mask gateway valid_status_codes 312 @@@.%%.44.11 ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 313 314Configure Hexadecimal IP 315 [Documentation] Configure invalid IP address containing hex value. 316 [Tags] Configure_Hexadecimal_IP 317 [Template] Add IP Address 318 319 # ip subnet_mask gateway valid_status_codes 320 ${hex_ip} ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 321 322Configure Negative Octet IP 323 [Documentation] Configure invalid IP address containing negative octet. 324 [Tags] Configure_Negative_Octet_IP 325 [Template] Add IP Address 326 327 # ip subnet_mask gateway valid_status_codes 328 ${negative_ip} ${test_subnet_mask} ${test_gateway} ${HTTP_BAD_REQUEST} 329 330Configure Incomplete IP For Gateway 331 [Documentation] Configure incomplete IP for gateway and expect an error. 332 [Tags] Configure_Incomplete_IP_For_Gateway 333 [Template] Add IP Address 334 335 # ip subnet_mask gateway valid_status_codes 336 ${test_ipv4_addr} ${test_subnet_mask} ${less_octet_ip} ${HTTP_BAD_REQUEST} 337 338Configure Special Char IP For Gateway 339 [Documentation] Configure special char IP for gateway and expect an error. 340 [Tags] Configure_Special_Char_IP_For_Gateway 341 [Template] Add IP Address 342 343 # ip subnet_mask gateway valid_status_codes 344 ${test_ipv4_addr} ${test_subnet_mask} @@@.%%.44.11 ${HTTP_BAD_REQUEST} 345 346Configure Hexadecimal IP For Gateway 347 [Documentation] Configure hexadecimal IP for gateway and expect an error. 348 [Tags] Configure_Hexadecimal_IP_For_Gateway 349 [Template] Add IP Address 350 351 # ip subnet_mask gateway valid_status_codes 352 ${test_ipv4_addr} ${test_subnet_mask} ${hex_ip} ${HTTP_BAD_REQUEST} 353 354*** Keywords *** 355 356Test Setup Execution 357 [Documentation] Test setup execution. 358 359 Redfish.Login 360 361 @{network_configurations}= Get Network Configuration 362 Set Test Variable @{network_configurations} 363 364 # Get BMC IP address and prefix length. 365 ${ip_data}= Get BMC IP Info 366 Set Test Variable ${ip_data} 367 368 369Get Network Configuration 370 [Documentation] Get network configuration. 371 372 # Sample output: 373 #{ 374 # "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface", 375 # "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0", 376 # "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface", 377 # "Description": "Management Network Interface", 378 # "IPv4Addresses": [ 379 # { 380 # "Address": "169.254.xx.xx", 381 # "AddressOrigin": "IPv4LinkLocal", 382 # "Gateway": "0.0.0.0", 383 # "SubnetMask": "255.255.0.0" 384 # }, 385 # { 386 # "Address": "xx.xx.xx.xx", 387 # "AddressOrigin": "Static", 388 # "Gateway": "xx.xx.xx.1", 389 # "SubnetMask": "xx.xx.xx.xx" 390 # } 391 # ], 392 # "Id": "eth0", 393 # "MACAddress": "xx:xx:xx:xx:xx:xx", 394 # "Name": "Manager Ethernet Interface", 395 # "SpeedMbps": 0, 396 # "VLAN": { 397 # "VLANEnable": false, 398 # "VLANId": 0 399 # } 400 401 ${resp}= Redfish.Get ${REDFISH_NW_ETH0_URI} 402 @{network_configurations}= Get From Dictionary ${resp.dict} IPv4Addresses 403 [Return] @{network_configurations} 404 405 406Verify IP On BMC 407 [Documentation] Verify IP on BMC. 408 [Arguments] ${ip} 409 410 # Description of argument(s): 411 # ip IP address to be verified (e.g. "10.7.7.7"). 412 413 # Get IP address details on BMC using IP command. 414 @{ip_data}= Get BMC IP Info 415 Should Contain Match ${ip_data} ${ip}/* 416 ... msg=IP address does not exist. 417 418Add IP Address 419 [Documentation] Add IP Address To BMC. 420 [Arguments] ${ip} ${subnet_mask} ${gateway} 421 ... ${valid_status_codes}=${HTTP_OK} 422 423 # Description of argument(s): 424 # ip IP address to be added (e.g. "10.7.7.7"). 425 # subnet_mask Subnet mask for the IP to be added 426 # (e.g. "255.255.0.0"). 427 # gateway Gateway for the IP to be added (e.g. "10.7.7.1"). 428 # valid_status_codes Expected return code from patch operation 429 # (e.g. "200"). See prolog of rest_request 430 # method in redfish_plut.py for details. 431 432 ${empty_dict}= Create Dictionary 433 ${ip_data}= Create Dictionary Address=${ip} 434 ... AddressOrigin=Static SubnetMask=${subnet_mask} 435 ... Gateway=${gateway} 436 437 ${patch_list}= Create List 438 ${network_configurations}= Get Network Configuration 439 ${num_entries}= Get Length ${network_configurations} 440 441 : FOR ${INDEX} IN RANGE 0 ${num_entries} 442 \ Append To List ${patch_list} ${empty_dict} 443 444 # We need not check for existence of IP on BMC while adding. 445 Append To List ${patch_list} ${ip_data} 446 ${data}= Create Dictionary IPv4Addresses=${patch_list} 447 448 Redfish.patch ${REDFISH_NW_ETH0_URI} body=&{data} 449 ... valid_status_codes=[${valid_status_codes}] 450 451 Return From Keyword If '${valid_status_codes}' != '${HTTP_OK}' 452 453 # Note: Network restart takes around 15-18s after patch request processing. 454 Sleep ${NETWORK_TIMEOUT}s 455 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} 456 457 Verify IP On BMC ${ip} 458 Validate Network Config On BMC 459 460 461Delete IP Address 462 [Documentation] Delete IP Address Of BMC. 463 [Arguments] ${ip} ${valid_status_codes}=${HTTP_OK} 464 465 # Description of argument(s): 466 # ip IP address to be deleted (e.g. "10.7.7.7"). 467 # valid_status_codes Expected return code from patch operation 468 # (e.g. "200"). See prolog of rest_request 469 # method in redfish_plut.py for details. 470 471 ${empty_dict}= Create Dictionary 472 ${patch_list}= Create List 473 474 @{network_configurations}= Get Network Configuration 475 : FOR ${network_configuration} IN @{network_configurations} 476 \ Run Keyword If '${network_configuration['Address']}' == '${ip}' 477 ... Append To List ${patch_list} ${null} 478 ... ELSE Append To List ${patch_list} ${empty_dict} 479 480 ${ip_found}= Run Keyword And Return Status List Should Contain Value 481 ... ${patch_list} ${null} msg=${ip} does not exist on BMC 482 Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC 483 484 # Run patch command only if given IP is found on BMC 485 ${data}= Create Dictionary IPv4Addresses=${patch_list} 486 487 Redfish.patch ${REDFISH_NW_ETH0_URI} body=&{data} 488 ... valid_status_codes=[${valid_status_codes}] 489 490 # Note: Network restart takes around 15-18s after patch request processing 491 Sleep ${NETWORK_TIMEOUT}s 492 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} 493 494 ${delete_status}= Run Keyword And Return Status Verify IP On BMC ${ip} 495 Run Keyword If '${valid_status_codes}' == '${HTTP_OK}' 496 ... Should Be True ${delete_status} == ${False} 497 ... ELSE Should Be True ${delete_status} == ${True} 498 499 Validate Network Config On BMC 500 501 502Validate Network Config On BMC 503 [Documentation] Check that network info obtained via redfish matches info 504 ... obtained via CLI. 505 506 @{network_configurations}= Get Network Configuration 507 ${ip_data}= Get BMC IP Info 508 : FOR ${network_configuration} IN @{network_configurations} 509 \ Should Contain Match ${ip_data} ${network_configuration['Address']}/* 510 ... msg=IP address does not exist. 511 512 513Verify Netmask On BMC 514 [Documentation] Verify netmask on BMC. 515 [Arguments] ${netmask} 516 517 # Description of the argument(s): 518 # netmask netmask value to be verified. 519 520 ${prefix_length}= Netmask Prefix Length ${netmask} 521 522 Should Contain Match ${ip_data} */${prefix_length} 523 ... msg=Prefix length does not exist. 524 525Verify Gateway On BMC 526 [Documentation] Verify gateway on BMC. 527 [Arguments] ${gateway_ip}=0.0.0.0 528 529 # Description of argument(s): 530 # gateway_ip Gateway IP address. 531 532 ${route_info}= Get BMC Route Info 533 534 # If gateway IP is empty or 0.0.0.0 it will not have route entry. 535 536 Run Keyword If '${gateway_ip}' == '0.0.0.0' 537 ... Pass Execution Gateway IP is "0.0.0.0". 538 ... ELSE 539 ... Should Contain ${route_info} ${gateway_ip} 540 ... msg=Gateway IP address not matching. 541 542Verify IP And Netmask On BMC 543 [Documentation] Verify IP and netmask on BMC. 544 [Arguments] ${ip} ${netmask} 545 546 # Description of the argument(s): 547 # ip IP address to be verified. 548 # netmask netmask value to be verified. 549 550 ${prefix_length}= Netmask Prefix Length ${netmask} 551 @{ip_data}= Get BMC IP Info 552 553 ${ip_with_netmask}= Catenate ${ip}/${prefix_length} 554 Should Contain ${ip_data} ${ip_with_netmask} 555 ... msg=IP and netmask pair does not exist. 556 557Validate Hostname On BMC 558 [Documentation] Verify that the hostname read via Redfish is the same as the 559 ... hostname configured on system. 560 [Arguments] ${hostname} 561 562 # Description of argument(s): 563 # hostname A hostname value which is to be compared to the hostname 564 # configured on system. 565 566 ${sys_hostname}= Get BMC Hostname 567 Should Be Equal ${sys_hostname} ${hostname} 568 ... ignore_case=True msg=Hostname does not exist. 569 570Test Teardown Execution 571 [Documentation] Test teardown execution. 572 573 FFDC On Test Case Fail 574 Redfish.Logout 575 576Clear IP Settings On Fail 577 [Documentation] Clear IP settings on fail. 578 [Arguments] ${ip} 579 580 # Description of argument(s): 581 # ip IP address to be deleted. 582 583 Run Keyword If '${TEST STATUS}' == 'FAIL' 584 ... Delete IP Address ${ip} 585 586 Test Teardown Execution 587 588