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