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