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