Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Resource ../lib/utils.robot |
| 3 | Resource ../lib/connection_client.robot |
| 4 | Resource ../lib/boot_utils.robot |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 5 | Library ../lib/gen_misc.py |
George Keishing | bf72477 | 2018-02-21 08:57:16 -0600 | [diff] [blame] | 6 | Library ../lib/utils.py |
Tony Lee | 9f6b204 | 2020-04-27 20:20:43 +0800 | [diff] [blame] | 7 | Library ../lib/bmc_network_utils.py |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 8 | |
| 9 | *** Variables *** |
| 10 | # MAC input from user. |
| 11 | ${MAC_ADDRESS} ${EMPTY} |
| 12 | |
| 13 | |
| 14 | *** Keywords *** |
| 15 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 16 | Check And Reset MAC |
| 17 | [Documentation] Update BMC with user input MAC address. |
| 18 | [Arguments] ${mac_address}=${MAC_ADDRESS} |
| 19 | |
| 20 | # Description of argument(s): |
| 21 | # mac_address The mac address (e.g. 00:01:6c:80:02:28). |
| 22 | |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 23 | ${active_channel_config}= Get Active Channel Config |
| 24 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 25 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 26 | Should Not Be Empty ${mac_address} |
| 27 | Open Connection And Log In |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 28 | ${bmc_mac_addr} ${stderr} ${rc}= BMC Execute Command |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 29 | ... cat /sys/class/net/${ethernet_interface}/address |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 30 | Run Keyword If '${mac_address.lower()}' != '${bmc_mac_addr.lower()}' |
| 31 | ... Set MAC Address |
| 32 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 33 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 34 | Set MAC Address |
| 35 | [Documentation] Update eth0 with input MAC address. |
| 36 | [Arguments] ${mac_address}=${MAC_ADDRESS} |
| 37 | |
| 38 | # Description of argument(s): |
| 39 | # mac_address The mac address (e.g. 00:01:6c:80:02:28). |
| 40 | |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 41 | ${active_channel_config}= Get Active Channel Config |
| 42 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 43 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 44 | Write fw_setenv ethaddr ${mac_address} |
| 45 | OBMC Reboot (off) |
Sunil M | d1c4f27 | 2017-07-07 09:03:24 -0500 | [diff] [blame] | 46 | |
| 47 | # Take SSH session post BMC reboot. |
| 48 | Open Connection And Log In |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 49 | ${bmc_mac_addr} ${stderr} ${rc}= BMC Execute Command |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 50 | ... cat /sys/class/net/${ethernet_interface}/address |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 51 | Should Be Equal ${bmc_mac_addr} ${mac_address} ignore_case=True |
| 52 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 53 | |
| 54 | Get BMC IP Info |
| 55 | [Documentation] Get system IP address and prefix length. |
| 56 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 57 | |
| 58 | # Get system IP address and prefix length details using "ip addr" |
| 59 | # Sample Output of "ip addr": |
| 60 | # 1: eth0: <BROADCAST,MULTIAST> mtu 1500 qdisc mq state UP qlen 1000 |
| 61 | # link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff |
| 62 | # inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0 |
| 63 | |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 64 | ${active_channel_config}= Get Active Channel Config |
| 65 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 66 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 67 | ... /sbin/ip addr | grep ${ethernet_interface} |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 68 | |
| 69 | # Get line having IP address details. |
| 70 | ${lines}= Get Lines Containing String ${cmd_output} inet |
| 71 | |
| 72 | # List IP address details. |
| 73 | @{ip_components}= Split To Lines ${lines} |
| 74 | |
| 75 | @{ip_data}= Create List |
| 76 | |
| 77 | # Get all IP addresses and prefix lengths on system. |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 78 | FOR ${ip_component} IN @{ip_components} |
| 79 | @{if_info}= Split String ${ip_component} |
| 80 | ${ip_n_prefix}= Get From List ${if_info} 1 |
| 81 | Append To List ${ip_data} ${ip_n_prefix} |
| 82 | END |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 83 | |
| 84 | [Return] ${ip_data} |
| 85 | |
| 86 | Get BMC Route Info |
| 87 | [Documentation] Get system route info. |
| 88 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 89 | |
| 90 | # Sample output of "ip route": |
| 91 | # default via xx.xx.xx.x dev eth0 |
| 92 | # xx.xx.xx.0/23 dev eth0 src xx.xx.xx.xx |
| 93 | # xx.xx.xx.0/24 dev eth0 src xx.xx.xx.xx |
| 94 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 95 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 96 | ... /sbin/ip route |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 97 | |
| 98 | [Return] ${cmd_output} |
| 99 | |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 100 | # TODO: openbmc/openbmc-test-automation#1331 |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 101 | Get BMC MAC Address |
| 102 | [Documentation] Get system MAC address. |
| 103 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 104 | |
| 105 | # Sample output of "ip addr | grep ether": |
| 106 | # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff |
| 107 | |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 108 | ${active_channel_config}= Get Active Channel Config |
| 109 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 110 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 111 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 112 | ... /sbin/ip addr | grep ${ethernet_interface} -A 1 | grep ether |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 113 | |
Prashanth Katti | 9819b16 | 2017-12-12 05:38:59 -0600 | [diff] [blame] | 114 | # Split the line and return MAC address. |
| 115 | # Split list data: |
| 116 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 117 | |
| 118 | @{words}= Split String ${cmd_output} |
| 119 | |
| 120 | [Return] ${words[1]} |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 121 | |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 122 | |
| 123 | Get BMC MAC Address List |
| 124 | [Documentation] Get system MAC address |
| 125 | |
| 126 | # Sample output of "ip addr | grep ether": |
| 127 | # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff |
| 128 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 129 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 130 | ... /sbin/ip addr | grep ether |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 131 | |
| 132 | # Split the line and return MAC address. |
| 133 | # Split list data: |
| 134 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 135 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 136 | |
| 137 | ${mac_list}= Create List |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 138 | @{lines}= Split To Lines ${cmd_output} |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 139 | FOR ${line} IN @{lines} |
| 140 | @{words}= Split String ${line} |
| 141 | Append To List ${mac_list} ${words[1]} |
| 142 | END |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 143 | |
| 144 | [Return] ${mac_list} |
| 145 | |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 146 | Get BMC Hostname |
| 147 | [Documentation] Get BMC hostname. |
| 148 | |
Prashanth Katti | c068faa | 2019-04-16 00:57:22 -0500 | [diff] [blame] | 149 | # Sample output of "hostname": |
| 150 | # test_hostname |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 151 | |
Prashanth Katti | c068faa | 2019-04-16 00:57:22 -0500 | [diff] [blame] | 152 | ${output} ${stderr} ${rc}= BMC Execute Command hostname |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 153 | |
| 154 | [Return] ${output} |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 155 | |
| 156 | Get List Of IP Address Via REST |
| 157 | [Documentation] Get list of IP address via REST. |
| 158 | [Arguments] @{ip_uri_list} |
| 159 | |
| 160 | # Description of argument(s): |
| 161 | # ip_uri_list List of IP objects. |
| 162 | # Example: |
| 163 | # "data": [ |
| 164 | # "/xyz/openbmc_project/network/eth0/ipv4/e9767624", |
| 165 | # "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b" |
| 166 | # ], |
| 167 | |
| 168 | ${ip_list}= Create List |
| 169 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 170 | FOR ${ip_uri} IN @{ip_uri_list} |
| 171 | ${ip_addr}= Read Attribute ${ip_uri} Address |
| 172 | Append To List ${ip_list} ${ip_addr} |
| 173 | END |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 174 | |
| 175 | [Return] @{ip_list} |
| 176 | |
| 177 | Delete IP And Object |
| 178 | [Documentation] Delete IP and object. |
| 179 | [Arguments] ${ip_addr} @{ip_uri_list} |
| 180 | |
| 181 | # Description of argument(s): |
| 182 | # ip_addr IP address to be deleted. |
| 183 | # ip_uri_list List of IP object URIs. |
| 184 | |
| 185 | # Find IP object having this IP address. |
| 186 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 187 | FOR ${ip_uri} IN @{ip_uri_list} |
| 188 | ${ip_addr1}= Read Attribute ${ip_uri} Address |
| 189 | Run Keyword If '${ip_addr}' == '${ip_addr1}' Exit For Loop |
| 190 | END |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 191 | |
| 192 | # If the given IP address is not configured, return. |
| 193 | # Otherwise, delete the IP and object. |
| 194 | |
| 195 | Run Keyword And Return If '${ip_addr}' != '${ip_addr1}' |
| 196 | ... Pass Execution IP address to be deleted is not configured. |
| 197 | |
| 198 | Run Keyword And Ignore Error OpenBMC Delete Request ${ip_uri} |
| 199 | |
| 200 | # After any modification on network interface, BMC restarts network |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 201 | # module, wait until it is reachable. Then wait 15 seconds for new |
| 202 | # configuration to be updated on BMC. |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 203 | |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 204 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 205 | ... ${NETWORK_RETRY_TIME} |
| 206 | Sleep 15s |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 207 | |
| 208 | # Verify whether deleted IP address is removed from BMC system. |
| 209 | |
| 210 | ${ip_data}= Get BMC IP Info |
Prashanth Katti | 160faf6 | 2017-09-07 01:05:56 -0500 | [diff] [blame] | 211 | Should Not Contain Match ${ip_data} ${ip_addr}* |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 212 | ... msg=IP address not deleted. |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 213 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 214 | Get First Non Pingable IP From Subnet |
| 215 | [Documentation] Find first non-pingable IP from the subnet and return it. |
| 216 | [Arguments] ${host}=${OPENBMC_HOST} |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 217 | |
| 218 | # Description of argument(s): |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 219 | # host Any valid host name or IP address |
| 220 | # (e.g. "machine1" or "9.xx.xx.31"). |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 221 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 222 | # Non-pingable IP is unused IP address in the subnet. |
| 223 | ${host_name} ${ip_addr}= Get Host Name IP |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 224 | |
| 225 | # Split IP address into network part and host part. |
| 226 | # IP address will have 4 octets xx.xx.xx.xx. |
| 227 | # Sample output after split: |
| 228 | # split_ip [xx.xx.xx, xx] |
| 229 | |
| 230 | ${split_ip}= Split String From Right ${ip_addr} . 1 |
| 231 | # First element in list is Network part. |
| 232 | ${network_part}= Get From List ${split_ip} 0 |
| 233 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 234 | FOR ${octet4} IN RANGE 1 255 |
| 235 | ${new_ip}= Catenate ${network_part}.${octet4} |
| 236 | ${status}= Run Keyword And Return Status Ping Host ${new_ip} |
| 237 | # If IP is non-pingable, return it. |
| 238 | Return From Keyword If '${status}' == 'False' ${new_ip} |
| 239 | END |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 240 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 241 | Fail msg=No non-pingable IP could be found in subnet ${network_part}. |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 242 | |
George Keishing | bf72477 | 2018-02-21 08:57:16 -0600 | [diff] [blame] | 243 | |
| 244 | Validate MAC On BMC |
| 245 | [Documentation] Validate MAC on BMC. |
| 246 | [Arguments] ${mac_addr} |
| 247 | |
| 248 | # Description of argument(s): |
| 249 | # mac_addr MAC address of the BMC. |
| 250 | |
| 251 | ${system_mac}= Get BMC MAC Address |
| 252 | |
| 253 | ${status}= Compare MAC Address ${system_mac} ${mac_addr} |
| 254 | Should Be True ${status} |
| 255 | ... msg=MAC address ${system_mac} does not match ${mac_addr}. |
| 256 | |
Daniel Gonzalez | bfd8aff | 2018-03-27 10:20:37 -0600 | [diff] [blame] | 257 | |
| 258 | Run Build Net |
| 259 | [Documentation] Run build_net to preconfigure the ethernet interfaces. |
| 260 | |
| 261 | OS Execute Command build_net help y y |
Gunnar Mills | 7732c7e | 2018-08-14 11:54:24 -0500 | [diff] [blame] | 262 | # Run pingum to check if the "build_net" was run correctly done. |
Daniel Gonzalez | bfd8aff | 2018-03-27 10:20:37 -0600 | [diff] [blame] | 263 | ${output} ${stderr} ${rc}= OS Execute Command pingum |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 264 | Should Contain ${output} All networks ping Ok |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 265 | |
| 266 | |
| 267 | Configure Hostname |
| 268 | [Documentation] Configure hostname on BMC via Redfish. |
| 269 | [Arguments] ${hostname} |
| 270 | |
| 271 | # Description of argument(s): |
| 272 | # hostname A hostname value which is to be configured on BMC. |
| 273 | |
| 274 | ${data}= Create Dictionary HostName=${hostname} |
| 275 | Redfish.patch ${REDFISH_NW_PROTOCOL_URI} body=&{data} |
George Keishing | 5041d6d | 2020-01-14 12:19:06 -0600 | [diff] [blame] | 276 | ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 277 | |
Naman Navin Hegde | 5369145 | 2019-07-30 00:22:37 -0500 | [diff] [blame] | 278 | |
| 279 | Verify IP On BMC |
| 280 | [Documentation] Verify IP on BMC. |
| 281 | [Arguments] ${ip} |
| 282 | |
| 283 | # Description of argument(s): |
| 284 | # ip IP address to be verified (e.g. "10.7.7.7"). |
| 285 | |
| 286 | # Get IP address details on BMC using IP command. |
| 287 | @{ip_data}= Get BMC IP Info |
| 288 | Should Contain Match ${ip_data} ${ip}/* |
| 289 | ... msg=IP address does not exist. |
| 290 | |
| 291 | |
| 292 | Verify Gateway On BMC |
| 293 | [Documentation] Verify gateway on BMC. |
| 294 | [Arguments] ${gateway_ip}=0.0.0.0 |
| 295 | |
| 296 | # Description of argument(s): |
| 297 | # gateway_ip Gateway IP address. |
| 298 | |
| 299 | ${route_info}= Get BMC Route Info |
| 300 | |
| 301 | # If gateway IP is empty or 0.0.0.0 it will not have route entry. |
| 302 | |
| 303 | Run Keyword If '${gateway_ip}' == '0.0.0.0' |
| 304 | ... Pass Execution Gateway IP is "0.0.0.0". |
| 305 | ... ELSE |
| 306 | ... Should Contain ${route_info} ${gateway_ip} |
| 307 | ... msg=Gateway IP address not matching. |
| 308 | |
| 309 | |
| 310 | Get BMC DNS Info |
| 311 | [Documentation] Get system DNS info. |
| 312 | |
| 313 | |
| 314 | # Sample output of "resolv.conf": |
| 315 | # ### Generated manually via dbus settings ### |
| 316 | # nameserver 8.8.8.8 |
| 317 | |
| 318 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 319 | ... cat /etc/resolv.conf |
| 320 | |
| 321 | [Return] ${cmd_output} |
| 322 | |
| 323 | |
| 324 | CLI Get Nameservers |
| 325 | [Documentation] Get the nameserver IPs from /etc/resolv.conf and return as a list. |
| 326 | |
| 327 | # Example of /etc/resolv.conf data: |
| 328 | # nameserver x.x.x.x |
| 329 | # nameserver y.y.y.y |
| 330 | |
| 331 | ${stdout} ${stderr} ${rc}= BMC Execute Command egrep nameserver /etc/resolv.conf | cut -f2- -d ' ' |
| 332 | ${nameservers}= Split String ${stdout} |
| 333 | |
| 334 | [Return] ${nameservers} |
Anvesh Kumar Rayankula | ada25db | 2020-02-19 01:29:17 -0600 | [diff] [blame] | 335 | |
| 336 | |
| 337 | Get Network Configuration |
| 338 | [Documentation] Get network configuration. |
| 339 | # Sample output: |
| 340 | #{ |
| 341 | # "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface", |
| 342 | # "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0", |
| 343 | # "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface", |
| 344 | # "Description": "Management Network Interface", |
| 345 | # "IPv4Addresses": [ |
| 346 | # { |
| 347 | # "Address": "169.254.xx.xx", |
| 348 | # "AddressOrigin": "IPv4LinkLocal", |
| 349 | # "Gateway": "0.0.0.0", |
| 350 | # "SubnetMask": "255.255.0.0" |
| 351 | # }, |
| 352 | # { |
| 353 | # "Address": "xx.xx.xx.xx", |
| 354 | # "AddressOrigin": "Static", |
| 355 | # "Gateway": "xx.xx.xx.1", |
| 356 | # "SubnetMask": "xx.xx.xx.xx" |
| 357 | # } |
| 358 | # ], |
| 359 | # "Id": "eth0", |
| 360 | # "MACAddress": "xx:xx:xx:xx:xx:xx", |
| 361 | # "Name": "Manager Ethernet Interface", |
| 362 | # "SpeedMbps": 0, |
| 363 | # "VLAN": { |
| 364 | # "VLANEnable": false, |
| 365 | # "VLANId": 0 |
| 366 | # } |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 367 | |
| 368 | |
Tony Lee | 9f6b204 | 2020-04-27 20:20:43 +0800 | [diff] [blame] | 369 | ${active_channel_config}= Get Active Channel Config |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 370 | ${resp}= Redfish.Get ${REDFISH_NW_ETH_IFACE}${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 371 | |
Anvesh Kumar Rayankula | ada25db | 2020-02-19 01:29:17 -0600 | [diff] [blame] | 372 | @{network_configurations}= Get From Dictionary ${resp.dict} IPv4StaticAddresses |
| 373 | [Return] @{network_configurations} |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 374 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 375 | |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 376 | Add IP Address |
| 377 | [Documentation] Add IP Address To BMC. |
| 378 | [Arguments] ${ip} ${subnet_mask} ${gateway} |
| 379 | ... ${valid_status_codes}=${HTTP_OK} |
| 380 | |
| 381 | # Description of argument(s): |
| 382 | # ip IP address to be added (e.g. "10.7.7.7"). |
| 383 | # subnet_mask Subnet mask for the IP to be added |
| 384 | # (e.g. "255.255.0.0"). |
| 385 | # gateway Gateway for the IP to be added (e.g. "10.7.7.1"). |
| 386 | # valid_status_codes Expected return code from patch operation |
| 387 | # (e.g. "200"). See prolog of rest_request |
| 388 | # method in redfish_plus.py for details. |
| 389 | |
| 390 | ${empty_dict}= Create Dictionary |
| 391 | ${ip_data}= Create Dictionary Address=${ip} |
| 392 | ... SubnetMask=${subnet_mask} Gateway=${gateway} |
| 393 | |
| 394 | ${patch_list}= Create List |
| 395 | ${network_configurations}= Get Network Configuration |
| 396 | ${num_entries}= Get Length ${network_configurations} |
| 397 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 398 | FOR ${INDEX} IN RANGE 0 ${num_entries} |
| 399 | Append To List ${patch_list} ${empty_dict} |
| 400 | END |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 401 | |
| 402 | # We need not check for existence of IP on BMC while adding. |
| 403 | Append To List ${patch_list} ${ip_data} |
| 404 | ${data}= Create Dictionary IPv4StaticAddresses=${patch_list} |
| 405 | |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 406 | ${active_channel_config}= Get Active Channel Config |
| 407 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 408 | |
| 409 | Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data} |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 410 | ... valid_status_codes=[${valid_status_codes}] |
| 411 | |
| 412 | Return From Keyword If '${valid_status_codes}' != '${HTTP_OK}' |
| 413 | |
| 414 | # Note: Network restart takes around 15-18s after patch request processing. |
| 415 | Sleep ${NETWORK_TIMEOUT}s |
| 416 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 417 | |
| 418 | Verify IP On BMC ${ip} |
| 419 | Validate Network Config On BMC |
| 420 | |
| 421 | |
| 422 | Delete IP Address |
| 423 | [Documentation] Delete IP Address Of BMC. |
| 424 | [Arguments] ${ip} ${valid_status_codes}=${HTTP_OK} |
| 425 | |
| 426 | # Description of argument(s): |
| 427 | # ip IP address to be deleted (e.g. "10.7.7.7"). |
| 428 | # valid_status_codes Expected return code from patch operation |
| 429 | # (e.g. "200"). See prolog of rest_request |
| 430 | # method in redfish_plus.py for details. |
| 431 | |
| 432 | ${empty_dict}= Create Dictionary |
| 433 | ${patch_list}= Create List |
| 434 | |
| 435 | @{network_configurations}= Get Network Configuration |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 436 | FOR ${network_configuration} IN @{network_configurations} |
| 437 | Run Keyword If '${network_configuration['Address']}' == '${ip}' |
| 438 | ... Append To List ${patch_list} ${null} |
| 439 | ... ELSE Append To List ${patch_list} ${empty_dict} |
| 440 | END |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 441 | |
| 442 | ${ip_found}= Run Keyword And Return Status List Should Contain Value |
| 443 | ... ${patch_list} ${null} msg=${ip} does not exist on BMC |
| 444 | Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC |
| 445 | |
| 446 | # Run patch command only if given IP is found on BMC |
| 447 | ${data}= Create Dictionary IPv4StaticAddresses=${patch_list} |
| 448 | |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 449 | ${active_channel_config}= Get Active Channel Config |
| 450 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 451 | |
| 452 | Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data} |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 453 | ... valid_status_codes=[${valid_status_codes}] |
| 454 | |
| 455 | # Note: Network restart takes around 15-18s after patch request processing |
| 456 | Sleep ${NETWORK_TIMEOUT}s |
| 457 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 458 | |
| 459 | ${delete_status}= Run Keyword And Return Status Verify IP On BMC ${ip} |
| 460 | Run Keyword If '${valid_status_codes}' == '${HTTP_OK}' |
| 461 | ... Should Be True '${delete_status}' == '${False}' |
| 462 | ... ELSE Should Be True '${delete_status}' == '${True}' |
| 463 | |
| 464 | Validate Network Config On BMC |
| 465 | |
| 466 | |
| 467 | Validate Network Config On BMC |
| 468 | [Documentation] Check that network info obtained via redfish matches info |
| 469 | ... obtained via CLI. |
| 470 | |
| 471 | @{network_configurations}= Get Network Configuration |
| 472 | ${ip_data}= Get BMC IP Info |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 473 | FOR ${network_configuration} IN @{network_configurations} |
| 474 | Should Contain Match ${ip_data} ${network_configuration['Address']}/* |
| 475 | ... msg=IP address does not exist. |
| 476 | END |
| 477 | |
| 478 | |
| 479 | Create VLAN |
| 480 | [Documentation] Create a VLAN. |
| 481 | [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid |
| 482 | |
| 483 | # Description of argument(s): |
| 484 | # id The VLAN ID (e.g. '53'). |
| 485 | # interface The physical interface for the VLAN(e.g. 'eth0'). |
| 486 | # expected_result Expected status of VLAN configuration. |
| 487 | |
| 488 | @{data_vlan_id}= Create List ${interface} ${id} |
| 489 | ${data}= Create Dictionary data=@{data_vlan_id} |
| 490 | ${resp}= OpenBMC Post Request ${vlan_resource} data=${data} |
| 491 | ${resp.status_code}= Convert To String ${resp.status_code} |
| 492 | ${status}= Run Keyword And Return Status |
| 493 | ... Valid Value resp.status_code ["${HTTP_OK}"] |
| 494 | |
| 495 | Run Keyword If '${expected_result}' == 'error' |
| 496 | ... Should Be Equal ${status} ${False} |
| 497 | ... msg=Configuration of an invalid VLAN ID Failed. |
| 498 | ... ELSE |
| 499 | ... Should Be Equal ${status} ${True} |
| 500 | ... msg=Configuration of a valid VLAN ID Failed. |
| 501 | |
| 502 | Sleep ${NETWORK_TIMEOUT}s |
| 503 | |
| 504 | |
| 505 | Configure Network Settings On VLAN |
| 506 | [Documentation] Configure network settings. |
| 507 | [Arguments] ${id} ${ip_addr} ${prefix_len} ${gateway_ip}=${gateway} |
| 508 | ... ${expected_result}=valid ${interface}=eth0 |
| 509 | |
| 510 | # Description of argument(s): |
| 511 | # id The VLAN ID (e.g. '53'). |
| 512 | # ip_addr IP address of VLAN Interface. |
| 513 | # prefix_len Prefix length of VLAN Interface. |
| 514 | # gateway_ip Gateway IP address of VLAN Interface. |
| 515 | # expected_result Expected status of network setting configuration. |
| 516 | # interface Physical Interface on which the VLAN is defined. |
| 517 | |
| 518 | @{ip_parm_list}= Create List ${network_resource} |
| 519 | ... ${ip_addr} ${prefix_len} ${gateway_ip} |
| 520 | |
| 521 | ${data}= Create Dictionary data=@{ip_parm_list} |
| 522 | |
| 523 | Run Keyword And Ignore Error OpenBMC Post Request |
| 524 | ... ${NETWORK_MANAGER}${interface}_${id}/action/IP data=${data} |
| 525 | |
| 526 | # After any modification on network interface, BMC restarts network |
| 527 | # module, wait until it is reachable. Then wait 15 seconds for new |
| 528 | # configuration to be updated on BMC. |
| 529 | |
| 530 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 531 | ... ${NETWORK_RETRY_TIME} |
| 532 | Sleep ${NETWORK_TIMEOUT}s |
| 533 | |
| 534 | # Verify whether new IP address is populated on BMC system. |
| 535 | # It should not allow to configure invalid settings. |
| 536 | ${status}= Run Keyword And Return Status |
| 537 | ... Verify IP On BMC ${ip_addr} |
| 538 | |
| 539 | Run Keyword If '${expected_result}' == 'error' |
| 540 | ... Should Be Equal ${status} ${False} |
| 541 | ... msg=Configuration of invalid IP Failed. |
| 542 | ... ELSE |
| 543 | ... Should Be Equal ${status} ${True} |
| 544 | ... msg=Configuration of valid IP Failed. |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 545 | |
Prashanth Katti | b478d90 | 2020-05-08 10:05:32 -0500 | [diff] [blame] | 546 | |
| 547 | Get BMC Default Gateway |
| 548 | [Documentation] Get system default gateway. |
| 549 | |
| 550 | ${route_info}= Get BMC Route Info |
| 551 | |
| 552 | ${lines}= Get Lines Containing String ${route_info} default via |
| 553 | @{gateway_list}= Split To Lines ${lines} |
| 554 | |
| 555 | # Extract first default gateway and return. |
| 556 | @{default_gw}= Split String ${gateway_list[0]} |
| 557 | |
| 558 | [Return] ${default_gw[2]} |