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