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