1*** Settings *** 2Documentation Vmi network utilities keywords. 3 4Resource ../../lib/resource.robot 5Resource ../../lib/bmc_redfish_resource.robot 6Resource ../../lib/openbmc_ffdc.robot 7Resource ../../lib/bmc_redfish_utils.robot 8Resource ../../lib/state_manager.robot 9Resource ../../lib/bmc_network_utils.robot 10Library ../../lib/bmc_network_utils.py 11 12*** Variables *** 13 14&{DHCP_ENABLED} DHCPEnabled=${True} 15&{DHCP_DISABLED} DHCPEnabled=${False} 16 17&{ENABLE_DHCP} DHCPv4=&{DHCP_ENABLED} 18&{DISABLE_DHCP} DHCPv4=&{DHCP_DISABLED} 19 20&{SLAAC_ENABLED} IPv6AutoConfigEnabled=${True} 21&{SLAAC_DISABLED} IPv6AutoConfigEnabled=${False} 22 23&{ENABLE_SLAAC} StatelessAddressAutoConfig=&{SLAAC_ENABLED} 24&{DISABLE_SLAAC} StatelessAddressAutoConfig=&{SLAAC_DISABLED} 25 26&{DHCPv6_ENABLED} OperatingMode=Enabled 27&{DHCPv6_DISABLED} OperatingMode=Disabled 28 29&{ENABLE_DHCPv6} DHCPv6=&{DHCPv6_ENABLED} 30&{DISABLE_DHCPv6} DHCPv6=&{DHCPv6_DISABLED} 31 32${wait_time} 40s 33${ethernet_interface} eth0 34${ipv4_hexword_addr} 10.5.5.6:1A:1B:1C:1D:1E:1F 35 36*** Keywords *** 37 38Set Static IPv4 Address To VMI And Verify 39 [Documentation] Set static IPv4 address to VMI. 40 [Arguments] ${ip} ${gateway} ${netmask} ${valid_status_code}=${HTTP_ACCEPTED} 41 ... ${interface}=${ethernet_interface} 42 43 # Description of argument(s): 44 # ip VMI IPv4 address. 45 # gateway Gateway for VMI IP. 46 # netmask Subnetmask for VMI IP. 47 # valid_status_code Expected valid status code from GET request. Default is HTTP_ACCEPTED. 48 # interface VMI interface (eg. eth0 or eth1). 49 50 ${ip_details}= Create dictionary Address=${ip} SubnetMask=${netmask} Gateway=${gateway} 51 ${ip_data}= Create List ${ip_details} 52 ${resp}= Redfish.Patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 53 ... body={'IPv4StaticAddresses':${ip_data}} valid_status_codes=[${valid_status_code}] 54 55 # Wait few seconds for new configuration to get populated on runtime. 56 Sleep ${wait_time} 57 58 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED} 59 ${host_power_state} ${host_state}= Redfish Get Host State 60 IF '${host_power_state}' == 'On' and '${host_state}' == 'Enabled' 61 Verify VMI Network Interface Details ${ip} Static ${gateway} ${netmask} ${interface} 62 END 63 64 65Verify VMI Network Interface Details 66 [Documentation] Verify VMI network interface details. 67 [Arguments] ${ip} ${origin} ${gateway} ${netmask} 68 ... ${interface}=${ethernet_interface} ${valid_status_code}=${HTTP_OK} 69 70 # Description of argument(s): 71 # ip VMI IPv4 address. 72 # origin Origin of IPv4 address eg. Static or DHCP. 73 # gateway Gateway for VMI IP. 74 # netmask Subnetmask for VMI IP. 75 # interface VMI interface (eg. eth0 or eth1). 76 # valid_status_code Expected valid status code from GET request. Default is HTTP_OK. 77 78 ${vmi_ip}= Get VMI Network Interface Details ${interface} ${valid_status_code} 79 Should Be Equal As Strings ${origin} ${vmi_ip["IPv4_AddressOrigin"]} 80 Should Be Equal As Strings ${gateway} ${vmi_ip["IPv4_Gateway"]} 81 Should Be Equal As Strings ${netmask} ${vmi_ip["IPv4_SubnetMask"]} 82 Should Be Equal As Strings ${ip} ${vmi_ip["IPv4_Address"]} 83 84Delete VMI IPv4 Address 85 [Documentation] Delete VMI IPv4 address. 86 [Arguments] ${delete_param}=IPv4StaticAddresses ${valid_status_code}=${HTTP_ACCEPTED} 87 ... ${interface}=${ethernet_interface} 88 89 # Description of argument(s): 90 # delete_param Parameter to be deleted eg. IPv4StaticAddresses or IPv4Addresses. 91 # Default is IPv4StaticAddresses. 92 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK. 93 # interface VMI interface (eg. eth0 or eth1). 94 95 ${data}= Set Variable {"${delete_param}": [${Null}]} 96 ${resp}= Redfish.Patch 97 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 98 ... body=${data} valid_status_codes=[${valid_status_code}] 99 100 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED} 101 102 # Wait few seconds for configuration to get effective. 103 Sleep ${wait_time} 104 ${vmi_ip}= Get VMI Network Interface Details ${interface} 105 ${default}= Set Variable 0.0.0.0 106 Verify VMI Network Interface Details ${default} Static ${default} ${default} 107 108Set VMI IPv4 Origin 109 [Documentation] Set VMI IPv4 origin. 110 [Arguments] ${dhcp_enabled}=${False} ${valid_status_code}=${HTTP_ACCEPTED} 111 ... ${interface}=${ethernet_interface} 112 113 # Description of argument(s): 114 # dhcp_enabled True if user wants to enable DHCP. Default is Static, hence value is set to False. 115 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK. 116 # interface VMI interface (eg. eth0 or eth1). 117 118 ${data}= Set Variable If ${dhcp_enabled} == ${False} ${DISABLE_DHCP} ${ENABLE_DHCP} 119 ${resp}= Redfish.Patch 120 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 121 ... body=${data} valid_status_codes=[${valid_status_code}] 122 123 Sleep ${wait_time} 124 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED} 125 ${resp}= Redfish.Get 126 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 127 Should Be Equal ${resp.dict["DHCPv4"]["DHCPEnabled"]} ${dhcp_enabled} 128 129 130Get VMI Network Interface Details 131 [Documentation] Get VMI network interface details. 132 [Arguments] ${interface}=${ethernet_interface} ${valid_status_code}=${HTTP_OK} 133 134 # Description of argument(s): 135 # interface VMI interface (eg. eth0 or eth1). 136 # valid_status_code Expected valid status code from GET request. 137 138 # Note: It returns a dictionary of VMI ethernet interface parameters. 139 140 ${resp}= Redfish.Get 141 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 142 ... valid_status_codes=[${valid_status_code}] 143 144 ${ip_resp}= Evaluate json.loads(r'''${resp.text}''') json 145 146 ${ip_exists}= Set Variable If ${ip_resp["IPv4Addresses"]} == @{empty} ${False} ${True} 147 ${static_exists}= Set Variable If ${ip_resp["IPv4StaticAddresses"]} == @{empty} ${False} ${True} 148 149 ${vmi_ip}= Set Variable If ${ip_exists} == ${True} 150 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]} 151 ... Description=${ip_resp["Description"]} IPv4_Address=${ip_resp["IPv4Addresses"][0]["Address"]} 152 ... IPv4_AddressOrigin=${ip_resp["IPv4Addresses"][0]["AddressOrigin"]} Name=${ip_resp["Name"]} 153 ... IPv4_Gateway=${ip_resp["IPv4Addresses"][0]["Gateway"]} 154 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}} 155 ... IPv4_SubnetMask=${ip_resp["IPv4Addresses"][0]["SubnetMask"]} 156 ... IPv4StaticAddresses=${${static_exists}} 157 ... ELSE 158 ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]} 159 ... Description=${ip_resp["Description"]} IPv4StaticAddresses=${ip_resp["IPv4StaticAddresses"]} 160 ... IPv4_Address=${ip_resp["IPv4Addresses"]} Name=${ip_resp["Name"]} 161 ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}} 162 163 RETURN &{vmi_ip} 164 165 166Get VMI Interfaces 167 [Documentation] Get VMI network interface. 168 [Arguments] ${valid_status_code}=${HTTP_OK} 169 170 # Description of argument(s): 171 # valid_status_code Expected valid status code from GET request. 172 # By default set to ${HTTP_OK}. 173 174 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces 175 ... valid_status_codes=[${valid_status_code}] 176 177 ${resp}= Evaluate json.loads(r'''${resp.text}''') json 178 ${interfaces_uri}= Set Variable ${resp["Members"]} 179 ${interface_list}= Create List 180 ${number_of_interfaces}= Get Length ${interfaces_uri} 181 FOR ${interface} IN RANGE ${number_of_interfaces} 182 ${_} ${interface_value}= Split String From Right ${interfaces_uri[${interface}]}[@odata.id] / 1 183 Append To List ${interface_list} ${interface_value} 184 END 185 186 RETURN @{interface_list} 187 188 189Verify VMI EthernetInterfaces 190 [Documentation] Verify VMI ethernet interfaces. 191 [Arguments] ${valid_status_code}=${HTTP_OK} 192 193 # Description of argument(s): 194 # valid_status_code Expected valid status code from GET request. 195 196 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces 197 ... valid_status_codes=[${valid_status_code}] 198 199 ${resp}= Evaluate json.loads(r'''${resp.text}''') json 200 ${interfaces}= Set Variable ${resp["Members"]} 201 202 ${number_of_interfaces}= Get Length ${interfaces} 203 FOR ${i} IN RANGE ${number_of_interfaces} 204 Should Be Equal As Strings ${interfaces[${i}]}[@odata.id] 205 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth${i} 206 END 207 Should Be Equal ${resp["Members@odata.count"]} ${number_of_interfaces} 208 209Get And Set Static VMI IP 210 [Documentation] Get a suitable VMI IP and set it. 211 [Arguments] ${host}=${OPENBMC_HOST} ${network_active_channel}=${CHANNEL_NUMBER} 212 ... ${interface}=eth0 ${valid_status_code}=${HTTP_ACCEPTED} 213 214 # Description of argument(s): 215 # host BMC host name or IP address. 216 # network_active_channel Ethernet channel number (e.g.1 or 2). 217 # interface VMI interface (eg. eth0 or eth1). 218 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_ACCEPTED. 219 220 ${vmi_ip}= Get First Non Pingable IP From Subnet ${host} 221 ${bmc_ip_data}= Get Network Configuration ${network_active_channel} 222 223 Set Static IPv4 Address To VMI And Verify ${vmi_ip} ${bmc_ip_data[0]['Gateway']} 224 ... ${bmc_ip_data[0]['SubnetMask']} ${valid_status_code} ${interface} 225 226 RETURN ${vmi_ip} ${bmc_ip_data} 227 228 229Set VMI SLAACv6 Origin 230 [Documentation] Set VMI SLAACv6 origin. 231 [Arguments] ${slaac_enabled}=${False} ${valid_status_code}=${HTTP_ACCEPTED} 232 ... ${interface}=${ethernet_interface} 233 234 # Description of argument(s): 235 # slaacv6_enabled True if user wants to enable SLAACv6. Default is Static, hence value is set to False. 236 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK. 237 # interface VMI interface (eg. eth0 or eth1). 238 239 ${data}= Set Variable If ${slaac_enabled} == ${False} ${DISABLE_SLAAC} ${ENABLE_SLAAC} 240 ${resp}= Redfish.Patch 241 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 242 ... body=${data} valid_status_codes=[${valid_status_code}] 243 244 Sleep ${wait_time} 245 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED} 246 ${resp}= Redfish.Get 247 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 248 Should Be Equal ${resp.dict["StatelessAddressAutoConfig"]["IPv6AutoConfigEnabled"]} ${slaac_enabled} 249 250 251Verify VMI IPv6 Address 252 [Documentation] Verify VMI IPv6 address configurations. 253 [Arguments] ${ipv6_origin} ${interface}=${ethernet_interface} 254 255 # Description of argument(s): 256 # ipv6_origin Origin of IPv6 address eg. Static or DHCPv6 or SLAAC. 257 # interface VMI interface (eg. eth0 or eth1). 258 259 ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 260 261 @{vmi_ipv6_configurations}= Get From Dictionary ${resp.dict} IPv6Addresses 262 ${vmi_ipv6_config}= Get From List ${vmi_ipv6_configurations} 0 263 Should Not Be Empty ${vmi_ipv6_config["Address"]} 264 Should Be Equal As Strings ${vmi_ipv6_config["AddressOrigin"]} ${ipv6_origin} 265 RETURN &{vmi_ipv6_config} 266 267 268Set VMI DHCPv6 Property 269 [Documentation] Set VMI DHCPv6 attribute. 270 [Arguments] ${dhcpv6_operatingmode}=${Disabled} ${valid_status_code}=${HTTP_ACCEPTED} 271 ... ${interface}=${ethernet_interface} 272 273 # Description of argument(s): 274 # dhcpv6_operatingmode Enabled if user wants to enable DHCPv6. 275 # ... Default is Static, hence value is set to Disabled. 276 # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK. 277 # interface VMI interface (eg. eth0 or eth1). 278 279 ${data}= Set Variable If '${dhcpv6_operatingmode}' == 'Disabled' ${DISABLE_DHCPv6} ${ENABLE_DHCPv6} 280 ${resp}= Redfish.Patch 281 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 282 ... body=${data} valid_status_codes=[${valid_status_code}] 283 284 Sleep ${wait_time} 285 Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED} 286 ${resp}= Redfish.Get 287 ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 288 Should Be Equal ${resp.dict["DHCPv6"]["OperatingMode"]} ${dhcpv6_operatingmode} 289 290 291Set Static VMI IPv6 Address 292 [Documentation] Add static VMI IPv6 address. 293 [Arguments] ${vmi_ipv6_addr} ${prefix_len} ${valid_status_codes}=${HTTP_ACCEPTED} 294 ... ${interface}=${ethernet_interface} 295 296 # Description of argument(s): 297 # vmi_ipv6_addr VMI IPv6 address to be added. 298 # prefix_len Prefix length for the VMI IPv6 to be added. 299 # valid_status_codes Expected valid status code from PATCH request. 300 # interface VMI interface (eg. eth0 or eth1). 301 302 ${prefix_length}= Convert To Integer ${prefix_len} 303 ${empty_dict}= Create Dictionary 304 ${vmi_ipv6_data}= Create Dictionary Address=${vmi_ipv6_addr} 305 ... PrefixLength=${prefix_length} 306 307 ${patch_list}= Create List 308 309 Append To List ${patch_list} ${vmi_ipv6_data} 310 ${data}= Create Dictionary IPv6StaticAddresses=${patch_list} 311 312 ${active_channel_config}= Get Active Channel Config 313 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} 314 315 Redfish.patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 316 ... body=&{data} valid_status_codes=[${valid_status_codes}] 317 318 Sleep 5s 319 320Set VMI IPv6 Static Default Gateway 321 [Documentation] Set VMI IPv6 static default gateway address. 322 [Arguments] ${vmi_staticipv6_gateway} ${valid_status_codes}=${HTTP_ACCEPTED} 323 ... ${interface}=${ethernet_interface} 324 325 # Description of argument(s): 326 # vmi_staticipv6_gateway VMI static IPv6 default gateway address. 327 # valid_status_codes Expected valid status code from PATCH request. 328 # interface VMI interface (eg. eth0 or eth1). 329 330 ${patch_list}= Create List ${vmi_staticipv6_gateway} 331 ${data}= Create Dictionary IPv6StaticDefaultGateways=${patch_list} 332 333 Redfish.patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 334 ... body=&{data} valid_status_codes=[${valid_status_codes}] 335 336 337Delete VMI IPv6 Static Address 338 [Documentation] Delete VMI IPv6 static address. 339 [Arguments] ${valid_status_codes}=${HTTP_ACCEPTED} 340 ... ${interface}=${ethernet_interface} 341 342 # Description of argument(s): 343 # valid_status_codes Expected valid status code from PATCH request. 344 # interface VMI interface (eg. eth0 or eth1). 345 346 ${data}= Set Variable {"IPv6StaticAddresses": [${Null}]} 347 Redfish.Patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} 348 ... body=${data} valid_status_codes=[${valid_status_codes}] 349 350 Sleep 5s 351