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 |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 7 | |
| 8 | *** Variables *** |
| 9 | # MAC input from user. |
| 10 | ${MAC_ADDRESS} ${EMPTY} |
| 11 | |
| 12 | |
| 13 | *** Keywords *** |
| 14 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 15 | Check And Reset MAC |
| 16 | [Documentation] Update BMC with user input MAC address. |
| 17 | [Arguments] ${mac_address}=${MAC_ADDRESS} |
| 18 | |
| 19 | # Description of argument(s): |
| 20 | # mac_address The mac address (e.g. 00:01:6c:80:02:28). |
| 21 | |
| 22 | Should Not Be Empty ${mac_address} |
| 23 | Open Connection And Log In |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 24 | ${bmc_mac_addr} ${stderr} ${rc}= BMC Execute Command |
| 25 | ... cat /sys/class/net/eth0/address |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 26 | Run Keyword If '${mac_address.lower()}' != '${bmc_mac_addr.lower()}' |
| 27 | ... Set MAC Address |
| 28 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 29 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 30 | Set MAC Address |
| 31 | [Documentation] Update eth0 with input MAC address. |
| 32 | [Arguments] ${mac_address}=${MAC_ADDRESS} |
| 33 | |
| 34 | # Description of argument(s): |
| 35 | # mac_address The mac address (e.g. 00:01:6c:80:02:28). |
| 36 | |
| 37 | Write fw_setenv ethaddr ${mac_address} |
| 38 | OBMC Reboot (off) |
Sunil M | d1c4f27 | 2017-07-07 09:03:24 -0500 | [diff] [blame] | 39 | |
| 40 | # Take SSH session post BMC reboot. |
| 41 | Open Connection And Log In |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 42 | ${bmc_mac_addr} ${stderr} ${rc}= BMC Execute Command |
| 43 | ... cat /sys/class/net/eth0/address |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 44 | Should Be Equal ${bmc_mac_addr} ${mac_address} ignore_case=True |
| 45 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 46 | |
| 47 | Get BMC IP Info |
| 48 | [Documentation] Get system IP address and prefix length. |
| 49 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 50 | |
| 51 | # Get system IP address and prefix length details using "ip addr" |
| 52 | # Sample Output of "ip addr": |
| 53 | # 1: eth0: <BROADCAST,MULTIAST> mtu 1500 qdisc mq state UP qlen 1000 |
| 54 | # link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff |
| 55 | # inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0 |
| 56 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 57 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 58 | ... /sbin/ip addr | grep eth0 |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 59 | |
| 60 | # Get line having IP address details. |
| 61 | ${lines}= Get Lines Containing String ${cmd_output} inet |
| 62 | |
| 63 | # List IP address details. |
| 64 | @{ip_components}= Split To Lines ${lines} |
| 65 | |
| 66 | @{ip_data}= Create List |
| 67 | |
| 68 | # Get all IP addresses and prefix lengths on system. |
| 69 | :FOR ${ip_component} IN @{ip_components} |
| 70 | \ @{if_info}= Split String ${ip_component} |
| 71 | \ ${ip_n_prefix}= Get From List ${if_info} 1 |
| 72 | \ Append To List ${ip_data} ${ip_n_prefix} |
| 73 | |
| 74 | [Return] ${ip_data} |
| 75 | |
| 76 | Get BMC Route Info |
| 77 | [Documentation] Get system route info. |
| 78 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 79 | |
| 80 | # Sample output of "ip route": |
| 81 | # default via xx.xx.xx.x dev eth0 |
| 82 | # xx.xx.xx.0/23 dev eth0 src xx.xx.xx.xx |
| 83 | # xx.xx.xx.0/24 dev eth0 src xx.xx.xx.xx |
| 84 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 85 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 86 | ... /sbin/ip route |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 87 | |
| 88 | [Return] ${cmd_output} |
| 89 | |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 90 | # TODO: openbmc/openbmc-test-automation#1331 |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 91 | Get BMC MAC Address |
| 92 | [Documentation] Get system MAC address. |
| 93 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 94 | |
| 95 | # Sample output of "ip addr | grep ether": |
| 96 | # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff |
| 97 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 98 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 99 | ... /sbin/ip addr | grep ether |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 100 | |
Prashanth Katti | 9819b16 | 2017-12-12 05:38:59 -0600 | [diff] [blame] | 101 | # Split the line and return MAC address. |
| 102 | # Split list data: |
| 103 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 104 | |
| 105 | @{words}= Split String ${cmd_output} |
| 106 | |
| 107 | [Return] ${words[1]} |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 108 | |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 109 | |
| 110 | Get BMC MAC Address List |
| 111 | [Documentation] Get system MAC address |
| 112 | |
| 113 | # Sample output of "ip addr | grep ether": |
| 114 | # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff |
| 115 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 116 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 117 | ... /sbin/ip addr | grep ether |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 118 | |
| 119 | # Split the line and return MAC address. |
| 120 | # Split list data: |
| 121 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 122 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 123 | |
| 124 | ${mac_list}= Create List |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 125 | @{lines}= Split To Lines ${cmd_output} |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 126 | :FOR ${line} IN @{lines} |
| 127 | \ @{words}= Split String ${line} |
| 128 | \ Append To List ${mac_list} ${words[1]} |
| 129 | |
| 130 | [Return] ${mac_list} |
| 131 | |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 132 | Get BMC Hostname |
| 133 | [Documentation] Get BMC hostname. |
| 134 | |
| 135 | # Sample output of "hostnamectl": |
| 136 | # Static hostname: xxyyxxyyxx |
| 137 | # Icon name: computer |
| 138 | # Machine ID: 6939927dc0db409ea09289d5b56eef08 |
| 139 | # Boot ID: bb806955fd904d47b6aa4bc7c34df482 |
| 140 | # Operating System: Phosphor OpenBMC (xxx xx xx) v1.xx.x-xx |
| 141 | # Kernel: Linux 4.10.17-d6ae40dc4c4dff3265cc254d404ed6b03fcc2206 |
| 142 | # Architecture: arm |
| 143 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 144 | ${output} ${stderr} ${rc}= BMC Execute Command |
| 145 | ... hostnamectl | grep hostname |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 146 | |
| 147 | [Return] ${output} |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 148 | |
| 149 | Get List Of IP Address Via REST |
| 150 | [Documentation] Get list of IP address via REST. |
| 151 | [Arguments] @{ip_uri_list} |
| 152 | |
| 153 | # Description of argument(s): |
| 154 | # ip_uri_list List of IP objects. |
| 155 | # Example: |
| 156 | # "data": [ |
| 157 | # "/xyz/openbmc_project/network/eth0/ipv4/e9767624", |
| 158 | # "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b" |
| 159 | # ], |
| 160 | |
| 161 | ${ip_list}= Create List |
| 162 | |
| 163 | : FOR ${ip_uri} IN @{ip_uri_list} |
| 164 | \ ${ip_addr}= Read Attribute ${ip_uri} Address |
| 165 | \ Append To List ${ip_list} ${ip_addr} |
| 166 | |
| 167 | [Return] @{ip_list} |
| 168 | |
| 169 | Delete IP And Object |
| 170 | [Documentation] Delete IP and object. |
| 171 | [Arguments] ${ip_addr} @{ip_uri_list} |
| 172 | |
| 173 | # Description of argument(s): |
| 174 | # ip_addr IP address to be deleted. |
| 175 | # ip_uri_list List of IP object URIs. |
| 176 | |
| 177 | # Find IP object having this IP address. |
| 178 | |
| 179 | : FOR ${ip_uri} IN @{ip_uri_list} |
| 180 | \ ${ip_addr1}= Read Attribute ${ip_uri} Address |
| 181 | \ Run Keyword If '${ip_addr}' == '${ip_addr1}' Exit For Loop |
| 182 | |
| 183 | # If the given IP address is not configured, return. |
| 184 | # Otherwise, delete the IP and object. |
| 185 | |
| 186 | Run Keyword And Return If '${ip_addr}' != '${ip_addr1}' |
| 187 | ... Pass Execution IP address to be deleted is not configured. |
| 188 | |
| 189 | Run Keyword And Ignore Error OpenBMC Delete Request ${ip_uri} |
| 190 | |
| 191 | # After any modification on network interface, BMC restarts network |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 192 | # module, wait until it is reachable. Then wait 15 seconds for new |
| 193 | # configuration to be updated on BMC. |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 194 | |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 195 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 196 | ... ${NETWORK_RETRY_TIME} |
| 197 | Sleep 15s |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 198 | |
| 199 | # Verify whether deleted IP address is removed from BMC system. |
| 200 | |
| 201 | ${ip_data}= Get BMC IP Info |
Prashanth Katti | 160faf6 | 2017-09-07 01:05:56 -0500 | [diff] [blame] | 202 | Should Not Contain Match ${ip_data} ${ip_addr}* |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 203 | ... msg=IP address not deleted. |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 204 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 205 | Get First Non Pingable IP From Subnet |
| 206 | [Documentation] Find first non-pingable IP from the subnet and return it. |
| 207 | [Arguments] ${host}=${OPENBMC_HOST} |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 208 | |
| 209 | # Description of argument(s): |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 210 | # host Any valid host name or IP address |
| 211 | # (e.g. "machine1" or "9.xx.xx.31"). |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 212 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 213 | # Non-pingable IP is unused IP address in the subnet. |
| 214 | ${host_name} ${ip_addr}= Get Host Name IP |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 215 | |
| 216 | # Split IP address into network part and host part. |
| 217 | # IP address will have 4 octets xx.xx.xx.xx. |
| 218 | # Sample output after split: |
| 219 | # split_ip [xx.xx.xx, xx] |
| 220 | |
| 221 | ${split_ip}= Split String From Right ${ip_addr} . 1 |
| 222 | # First element in list is Network part. |
| 223 | ${network_part}= Get From List ${split_ip} 0 |
| 224 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 225 | : FOR ${octet4} IN RANGE 1 255 |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 226 | \ ${new_ip}= Catenate ${network_part}.${octet4} |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 227 | \ ${status}= Run Keyword And Return Status Ping Host ${new_ip} |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 228 | # If IP is non-pingable, return it. |
| 229 | \ Return From Keyword If '${status}' == 'False' ${new_ip} |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 230 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 231 | 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] | 232 | |
George Keishing | bf72477 | 2018-02-21 08:57:16 -0600 | [diff] [blame] | 233 | |
| 234 | Validate MAC On BMC |
| 235 | [Documentation] Validate MAC on BMC. |
| 236 | [Arguments] ${mac_addr} |
| 237 | |
| 238 | # Description of argument(s): |
| 239 | # mac_addr MAC address of the BMC. |
| 240 | |
| 241 | ${system_mac}= Get BMC MAC Address |
| 242 | |
| 243 | ${status}= Compare MAC Address ${system_mac} ${mac_addr} |
| 244 | Should Be True ${status} |
| 245 | ... msg=MAC address ${system_mac} does not match ${mac_addr}. |
| 246 | |
Daniel Gonzalez | bfd8aff | 2018-03-27 10:20:37 -0600 | [diff] [blame] | 247 | |
| 248 | Run Build Net |
| 249 | [Documentation] Run build_net to preconfigure the ethernet interfaces. |
| 250 | |
| 251 | OS Execute Command build_net help y y |
Gunnar Mills | 7732c7e | 2018-08-14 11:54:24 -0500 | [diff] [blame] | 252 | # Run pingum to check if the "build_net" was run correctly done. |
Daniel Gonzalez | bfd8aff | 2018-03-27 10:20:37 -0600 | [diff] [blame] | 253 | ${output} ${stderr} ${rc}= OS Execute Command pingum |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 254 | Should Contain ${output} All networks ping Ok |