Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Vmi network utilities keywords. |
| 3 | |
| 4 | Resource ../../lib/resource.robot |
| 5 | Resource ../../lib/bmc_redfish_resource.robot |
| 6 | Resource ../../lib/openbmc_ffdc.robot |
| 7 | Resource ../../lib/bmc_redfish_utils.robot |
| 8 | Resource ../../lib/state_manager.robot |
shrsuman123 | 7ba02f3 | 2021-08-26 04:50:56 -0500 | [diff] [blame^] | 9 | Resource ../../lib/bmc_network_utils.robot |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 10 | Library ../../lib/bmc_network_utils.py |
| 11 | |
| 12 | *** Variables *** |
| 13 | |
| 14 | ${wait_time} 10s |
| 15 | |
| 16 | *** Keywords *** |
| 17 | |
| 18 | Set Static IPv4 Address To VMI And Verify |
| 19 | [Documentation] Set static IPv4 address to VMI. |
| 20 | [Arguments] ${ip} ${gateway} ${netmask} ${valid_status_code}=${HTTP_ACCEPTED} |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 21 | ... ${interface}=eth0 |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 22 | |
| 23 | # Description of argument(s): |
| 24 | # ip VMI IPv4 address. |
| 25 | # gateway Gateway for VMI IP. |
| 26 | # netmask Subnetmask for VMI IP. |
| 27 | # valid_status_code Expected valid status code from GET request. Default is HTTP_ACCEPTED. |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 28 | # interface VMI interface (eg. eth0 or eth1). |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 29 | |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 30 | ${ip_details}= Create dictionary Address=${ip} SubnetMask=${netmask} Gateway=${gateway} |
| 31 | ${ip_data}= Create List ${ip_details} |
| 32 | ${resp}= Redfish.Patch /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} |
| 33 | ... body={'IPv4StaticAddresses':${ip_data}} valid_status_codes=[${valid_status_code}] |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 34 | |
| 35 | # Wait few seconds for new configuration to get populated on runtime. |
| 36 | Sleep ${wait_time} |
| 37 | |
| 38 | Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED} |
| 39 | ${host_power_state} ${host_state}= Redfish Get Host State |
| 40 | Run Keyword If '${host_power_state}' == 'On' and '${host_state}' == 'Enabled' |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 41 | ... Verify VMI Network Interface Details ${ip} Static ${gateway} ${netmask} ${interface} |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 42 | |
| 43 | Verify VMI Network Interface Details |
| 44 | [Documentation] Verify VMI network interface details. |
| 45 | [Arguments] ${ip} ${origin} ${gateway} ${netmask} |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 46 | ... ${interface}=eth0 ${valid_status_code}=${HTTP_OK} |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 47 | |
| 48 | # Description of argument(s): |
| 49 | # ip VMI IPv4 address. |
| 50 | # origin Origin of IPv4 address eg. Static or DHCP. |
| 51 | # gateway Gateway for VMI IP. |
| 52 | # netmask Subnetmask for VMI IP. |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 53 | # interface VMI interface (eg. eth0 or eth1). |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 54 | # valid_status_code Expected valid status code from GET request. Default is HTTP_OK. |
| 55 | |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 56 | ${vmi_ip}= Get VMI Network Interface Details ${interface} ${valid_status_code} |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 57 | Should Be Equal As Strings ${origin} ${vmi_ip["IPv4_AddressOrigin"]} |
| 58 | Should Be Equal As Strings ${gateway} ${vmi_ip["IPv4_Gateway"]} |
| 59 | Should Be Equal As Strings ${netmask} ${vmi_ip["IPv4_SubnetMask"]} |
| 60 | Should Be Equal As Strings ${ip} ${vmi_ip["IPv4_Address"]} |
| 61 | |
| 62 | Delete VMI IPv4 Address |
| 63 | [Documentation] Delete VMI IPv4 address. |
| 64 | [Arguments] ${delete_param}=IPv4StaticAddresses ${valid_status_code}=${HTTP_ACCEPTED} |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 65 | ... ${interface}=eth0 |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 66 | |
| 67 | # Description of argument(s): |
| 68 | # delete_param Parameter to be deleted eg. IPv4StaticAddresses or IPv4Addresses. |
| 69 | # Default is IPv4StaticAddresses. |
| 70 | # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK. |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 71 | # interface VMI interface (eg. eth0 or eth1). |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 72 | |
| 73 | ${data}= Set Variable {"${delete_param}": [${Null}]} |
| 74 | ${resp}= Redfish.Patch |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 75 | ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 76 | ... body=${data} valid_status_codes=[${valid_status_code}] |
| 77 | |
| 78 | Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED} |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 79 | ${vmi_ip}= Get VMI Network Interface Details ${interface} |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 80 | Should Be Empty ${vmi_ip["IPv4_Address"]} |
| 81 | |
| 82 | Set VMI IPv4 Origin |
| 83 | [Documentation] Set VMI IPv4 origin. |
| 84 | [Arguments] ${dhcp_enabled}=${False} ${valid_status_code}=${HTTP_ACCEPTED} |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 85 | ... ${interface}=eth0 |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 86 | |
| 87 | # Description of argument(s): |
| 88 | # dhcp_enabled True if user wants to enable DHCP. Default is Static, hence value is set to False. |
| 89 | # valid_status_code Expected valid status code from PATCH request. Default is HTTP_OK. |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 90 | # interface VMI interface (eg. eth0 or eth1). |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 91 | |
| 92 | ${data}= Set Variable If ${dhcp_enabled} == ${False} ${DISABLE_DHCP} ${ENABLE_DHCP} |
| 93 | ${resp}= Redfish.Patch |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 94 | ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 95 | ... body=${data} valid_status_codes=[${valid_status_code}] |
| 96 | |
| 97 | Sleep ${wait_time} |
| 98 | Return From Keyword If ${valid_status_code} != ${HTTP_ACCEPTED} |
| 99 | ${resp}= Redfish.Get |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 100 | ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 101 | Should Be Equal ${resp.dict["DHCPv4"]["DHCPEnabled"]} ${dhcp_enabled} |
| 102 | |
| 103 | Get VMI Network Interface Details |
| 104 | [Documentation] Get VMI network interface details. |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 105 | [Arguments] ${interface}=eth0 ${valid_status_code}=${HTTP_OK} |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 106 | |
| 107 | # Description of argument(s): |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 108 | # interface VMI interface (eg. eth0 or eth1). |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 109 | # valid_status_code Expected valid status code from GET request. |
| 110 | |
| 111 | # Note: It returns a dictionary of VMI ethernet interface parameters. |
| 112 | |
| 113 | ${resp}= Redfish.Get |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 114 | ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/${interface} |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 115 | ... valid_status_codes=[${valid_status_code}] |
| 116 | |
| 117 | ${ip_resp}= Evaluate json.loads(r'''${resp.text}''') json |
| 118 | |
| 119 | ${ip_exists}= Set Variable If ${ip_resp["IPv4Addresses"]} == @{empty} ${False} ${True} |
| 120 | ${static_exists}= Set Variable If ${ip_resp["IPv4StaticAddresses"]} == @{empty} ${False} ${True} |
| 121 | |
| 122 | ${vmi_ip}= Run Keyword If ${ip_exists} == ${True} |
| 123 | ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]} |
| 124 | ... Description=${ip_resp["Description"]} IPv4_Address=${ip_resp["IPv4Addresses"][0]["Address"]} |
| 125 | ... IPv4_AddressOrigin=${ip_resp["IPv4Addresses"][0]["AddressOrigin"]} Name=${ip_resp["Name"]} |
| 126 | ... IPv4_Gateway=${ip_resp["IPv4Addresses"][0]["Gateway"]} |
| 127 | ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}} |
| 128 | ... IPv4_SubnetMask=${ip_resp["IPv4Addresses"][0]["SubnetMask"]} |
| 129 | ... IPv4StaticAddresses=${${static_exists}} |
| 130 | ... ELSE |
| 131 | ... Create Dictionary DHCPv4=${${ip_resp["DHCPv4"]["DHCPEnabled"]}} Id=${ip_resp["Id"]} |
| 132 | ... Description=${ip_resp["Description"]} IPv4StaticAddresses=${ip_resp["IPv4StaticAddresses"]} |
| 133 | ... IPv4_Address=${ip_resp["IPv4Addresses"]} Name=${ip_resp["Name"]} |
| 134 | ... InterfaceEnabled=${${ip_resp["InterfaceEnabled"]}} |
| 135 | |
| 136 | [Return] &{vmi_ip} |
| 137 | |
shrsuman123 | 298e804 | 2021-08-20 07:36:21 -0500 | [diff] [blame] | 138 | |
| 139 | Get VMI Interfaces |
| 140 | [Documentation] Get VMI network interface. |
| 141 | [Arguments] ${valid_status_code}=${HTTP_OK} |
| 142 | |
| 143 | # Description of argument(s): |
| 144 | # valid_status_code Expected valid status code from GET request. |
| 145 | # By default set to ${HTTP_OK}. |
| 146 | |
| 147 | ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces |
| 148 | ... valid_status_codes=[${valid_status_code}] |
| 149 | |
| 150 | ${resp}= Evaluate json.loads(r'''${resp.text}''') json |
| 151 | ${interfaces_uri}= Set Variable ${resp["Members"]} |
| 152 | ${interface_list}= Create List |
| 153 | ${number_of_interfaces}= Get Length ${interfaces_uri} |
| 154 | FOR ${interface} IN RANGE ${number_of_interfaces} |
| 155 | ${_} ${interface_value}= Split String From Right ${interfaces_uri[${interface}]}[@odata.id] / 1 |
| 156 | Append To List ${interface_list} ${interface_value} |
| 157 | END |
| 158 | |
| 159 | [Return] @{interface_list} |
| 160 | |
| 161 | |
Sweta Potthuri | d52b273 | 2021-08-12 12:48:24 -0500 | [diff] [blame] | 162 | Verify VMI EthernetInterfaces |
| 163 | [Documentation] Verify VMI ethernet interfaces. |
| 164 | [Arguments] ${valid_status_code}=${HTTP_OK} |
| 165 | |
| 166 | # Description of argument(s): |
| 167 | # valid_status_code Expected valid status code from GET request. |
| 168 | |
| 169 | ${resp}= Redfish.Get /redfish/v1/Systems/hypervisor/EthernetInterfaces |
| 170 | ... valid_status_codes=[${valid_status_code}] |
| 171 | |
| 172 | ${resp}= Evaluate json.loads(r'''${resp.text}''') json |
| 173 | ${interfaces}= Set Variable ${resp["Members"]} |
| 174 | |
| 175 | ${number_of_interfaces}= Get Length ${interfaces} |
| 176 | FOR ${i} IN RANGE ${number_of_interfaces} |
| 177 | Should Be Equal As Strings ${interfaces[${i}]}[@odata.id] |
| 178 | ... /redfish/v1/Systems/hypervisor/EthernetInterfaces/eth${i} |
| 179 | END |
| 180 | Should Be Equal ${resp["Members@odata.count"]} ${number_of_interfaces} |
shrsuman123 | 7ba02f3 | 2021-08-26 04:50:56 -0500 | [diff] [blame^] | 181 | |
| 182 | Get And Set Static VMI IP |
| 183 | [Documentation] Get a suitable VMI IP and set it. |
| 184 | [Arguments] ${host}=${OPENBMC_HOST} ${network_active_channel}=${CHANNEL_NUMBER} |
| 185 | ... ${interface}=eth0 ${valid_status_code}=${HTTP_ACCEPTED} |
| 186 | |
| 187 | # Description of argument(s): |
| 188 | # host BMC host name or IP address. |
| 189 | # network_active_channel Ethernet channel number (e.g.1 or 2). |
| 190 | # interface VMI interface (eg. eth0 or eth1). |
| 191 | # valid_status_code Expected valid status code from PATCH request. Default is HTTP_ACCEPTED. |
| 192 | |
| 193 | ${vmi_ip}= Get First Non Pingable IP From Subnet ${host} |
| 194 | ${bmc_ip_data}= Get Network Configuration ${network_active_channel} |
| 195 | |
| 196 | Set Static IPv4 Address To VMI And Verify ${vmi_ip} ${bmc_ip_data[0]['Gateway']} |
| 197 | ... ${bmc_ip_data[0]['SubnetMask']} ${valid_status_code} ${interface} |
| 198 | |
| 199 | [Return] ${vmi_ip} ${bmc_ip_data} |