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 | |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 156 | Get FW_Env MAC Address |
| 157 | [Documentation] Get FW_Env MAC address. |
| 158 | |
| 159 | # Sample output of "fw_printenv | grep ethaddr" |
| 160 | # ethaddr=xx:xx:xx:xx:xx:xx:xx |
| 161 | |
| 162 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 163 | ... /sbin/fw_printenv | grep ethaddr |
| 164 | |
| 165 | # Split the line and return MAC address. |
| 166 | # Split list data: |
| 167 | # ethaddr | xx:xx:xx:xx:xx:xx:xx |
| 168 | |
| 169 | @{words}= Split String ${cmd_output} = |
| 170 | |
| 171 | [Return] ${words[1]} |
| 172 | |
| 173 | |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 174 | Get List Of IP Address Via REST |
| 175 | [Documentation] Get list of IP address via REST. |
| 176 | [Arguments] @{ip_uri_list} |
| 177 | |
| 178 | # Description of argument(s): |
| 179 | # ip_uri_list List of IP objects. |
| 180 | # Example: |
| 181 | # "data": [ |
| 182 | # "/xyz/openbmc_project/network/eth0/ipv4/e9767624", |
| 183 | # "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b" |
| 184 | # ], |
| 185 | |
| 186 | ${ip_list}= Create List |
| 187 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 188 | FOR ${ip_uri} IN @{ip_uri_list} |
| 189 | ${ip_addr}= Read Attribute ${ip_uri} Address |
| 190 | Append To List ${ip_list} ${ip_addr} |
| 191 | END |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 192 | |
| 193 | [Return] @{ip_list} |
| 194 | |
| 195 | Delete IP And Object |
| 196 | [Documentation] Delete IP and object. |
| 197 | [Arguments] ${ip_addr} @{ip_uri_list} |
| 198 | |
| 199 | # Description of argument(s): |
| 200 | # ip_addr IP address to be deleted. |
| 201 | # ip_uri_list List of IP object URIs. |
| 202 | |
| 203 | # Find IP object having this IP address. |
| 204 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 205 | FOR ${ip_uri} IN @{ip_uri_list} |
| 206 | ${ip_addr1}= Read Attribute ${ip_uri} Address |
| 207 | Run Keyword If '${ip_addr}' == '${ip_addr1}' Exit For Loop |
| 208 | END |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 209 | |
| 210 | # If the given IP address is not configured, return. |
| 211 | # Otherwise, delete the IP and object. |
| 212 | |
| 213 | Run Keyword And Return If '${ip_addr}' != '${ip_addr1}' |
| 214 | ... Pass Execution IP address to be deleted is not configured. |
| 215 | |
| 216 | Run Keyword And Ignore Error OpenBMC Delete Request ${ip_uri} |
| 217 | |
| 218 | # After any modification on network interface, BMC restarts network |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 219 | # module, wait until it is reachable. Then wait 15 seconds for new |
| 220 | # configuration to be updated on BMC. |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 221 | |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 222 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 223 | ... ${NETWORK_RETRY_TIME} |
| 224 | Sleep 15s |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 225 | |
| 226 | # Verify whether deleted IP address is removed from BMC system. |
| 227 | |
| 228 | ${ip_data}= Get BMC IP Info |
Prashanth Katti | 160faf6 | 2017-09-07 01:05:56 -0500 | [diff] [blame] | 229 | Should Not Contain Match ${ip_data} ${ip_addr}* |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 230 | ... msg=IP address not deleted. |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 231 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 232 | Get First Non Pingable IP From Subnet |
| 233 | [Documentation] Find first non-pingable IP from the subnet and return it. |
| 234 | [Arguments] ${host}=${OPENBMC_HOST} |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 235 | |
| 236 | # Description of argument(s): |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 237 | # host Any valid host name or IP address |
| 238 | # (e.g. "machine1" or "9.xx.xx.31"). |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 239 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 240 | # Non-pingable IP is unused IP address in the subnet. |
| 241 | ${host_name} ${ip_addr}= Get Host Name IP |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 242 | |
| 243 | # Split IP address into network part and host part. |
| 244 | # IP address will have 4 octets xx.xx.xx.xx. |
| 245 | # Sample output after split: |
| 246 | # split_ip [xx.xx.xx, xx] |
| 247 | |
| 248 | ${split_ip}= Split String From Right ${ip_addr} . 1 |
| 249 | # First element in list is Network part. |
| 250 | ${network_part}= Get From List ${split_ip} 0 |
| 251 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 252 | FOR ${octet4} IN RANGE 1 255 |
| 253 | ${new_ip}= Catenate ${network_part}.${octet4} |
| 254 | ${status}= Run Keyword And Return Status Ping Host ${new_ip} |
| 255 | # If IP is non-pingable, return it. |
| 256 | Return From Keyword If '${status}' == 'False' ${new_ip} |
| 257 | END |
Prashanth Katti | df2e4fdf | 2018-02-07 07:04:13 -0600 | [diff] [blame] | 258 | |
George Keishing | 58e4723 | 2018-02-12 10:35:15 -0600 | [diff] [blame] | 259 | 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] | 260 | |
George Keishing | bf72477 | 2018-02-21 08:57:16 -0600 | [diff] [blame] | 261 | |
| 262 | Validate MAC On BMC |
| 263 | [Documentation] Validate MAC on BMC. |
| 264 | [Arguments] ${mac_addr} |
| 265 | |
| 266 | # Description of argument(s): |
| 267 | # mac_addr MAC address of the BMC. |
| 268 | |
| 269 | ${system_mac}= Get BMC MAC Address |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 270 | ${mac_new_addr}= Truncate MAC Address ${system_mac} ${mac_addr} |
George Keishing | bf72477 | 2018-02-21 08:57:16 -0600 | [diff] [blame] | 271 | |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 272 | ${status}= Compare MAC Address ${system_mac} ${mac_new_addr} |
George Keishing | bf72477 | 2018-02-21 08:57:16 -0600 | [diff] [blame] | 273 | Should Be True ${status} |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 274 | ... msg=MAC address ${system_mac} does not match ${mac_new_addr}. |
| 275 | |
| 276 | Validate MAC On FW_Env |
| 277 | [Documentation] Validate MAC on FW_Env. |
| 278 | [Arguments] ${mac_addr} |
| 279 | |
| 280 | # Description of argument(s): |
| 281 | # mac_addr MAC address of the BMC. |
| 282 | |
| 283 | ${fw_env_addr}= Get FW_Env MAC Address |
| 284 | ${mac_new_addr}= Truncate MAC Address ${fw_env_addr} ${mac_addr} |
| 285 | |
| 286 | ${status}= Compare MAC Address ${fw_env_addr} ${mac_new_addr} |
| 287 | Should Be True ${status} |
| 288 | ... msg=MAC address ${fw_env_addr} does not match ${mac_new_addr}. |
| 289 | |
| 290 | Truncate MAC Address |
Anves Kumar rayankula | 0b9efea | 2021-05-28 08:52:28 -0500 | [diff] [blame] | 291 | [Documentation] Truncates and returns user provided MAC address. |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 292 | [Arguments] ${sys_mac_addr} ${user_mac_addr} |
Anves Kumar rayankula | 0b9efea | 2021-05-28 08:52:28 -0500 | [diff] [blame] | 293 | |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 294 | # Description of argument(s): |
| 295 | # sys_mac_addr MAC address of the BMC. |
| 296 | # user_mac_addr user provided MAC address. |
| 297 | |
| 298 | ${mac_byte}= Set Variable ${0} |
| 299 | @{user_mac_list}= Split String ${user_mac_addr} : |
| 300 | @{sys_mac_list}= Split String ${sys_mac_addr} : |
| 301 | ${user_new_mac_list} Create List |
| 302 | |
| 303 | # Truncate extra bytes and bits from MAC address |
| 304 | FOR ${mac_item} IN @{sys_mac_list} |
| 305 | ${invalid_mac_byte} = Get Regexp Matches ${user_mac_list}[${mac_byte}] [^A-Za-z0-9]+ |
| 306 | Return From Keyword If ${invalid_mac_byte} ${user_mac_addr} |
| 307 | ${mac_int} = Convert To Integer ${user_mac_list}[${mac_byte}] 16 |
| 308 | ${user_mac_len} = Get Length ${user_mac_list} |
Anves Kumar rayankula | 0b9efea | 2021-05-28 08:52:28 -0500 | [diff] [blame] | 309 | ${user_mac_byte}= Run Keyword IF |
| 310 | ... ${mac_int} >= ${256} Truncate MAC Bits ${user_mac_list}[${mac_byte}] |
| 311 | ... ELSE Set Variable ${user_mac_list}[${mac_byte}] |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 312 | |
| 313 | Append To List ${user_new_mac_list} ${user_mac_byte} |
| 314 | ${mac_byte} = Set Variable ${mac_byte + 1} |
| 315 | Exit For Loop If '${mac_byte}' == '${user_mac_len}' |
| 316 | |
| 317 | END |
| 318 | ${user_new_mac_string}= Evaluate ":".join(${user_new_mac_list}) |
| 319 | [Return] ${user_new_mac_string} |
| 320 | |
| 321 | Truncate MAC Bits |
Anves Kumar rayankula | 0b9efea | 2021-05-28 08:52:28 -0500 | [diff] [blame] | 322 | [Documentation] Truncates user provided MAC address byte to bits. |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 323 | [Arguments] ${user_mac_addr_byte} |
Anves Kumar rayankula | 0b9efea | 2021-05-28 08:52:28 -0500 | [diff] [blame] | 324 | |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 325 | # Description of argument(s): |
| 326 | # user_mac_addr_byte user provided MAC address byte to truncate bits |
| 327 | |
| 328 | ${user_mac_addr_int}= Convert To List ${user_mac_addr_byte} |
| 329 | ${user_mac_addr_byte}= Get Slice From List ${user_mac_addr_int} 0 2 |
| 330 | ${user_mac_addr_byte_string}= Evaluate "".join(${user_mac_addr_byte}) |
| 331 | [Return] ${user_mac_addr_byte_string} |
George Keishing | bf72477 | 2018-02-21 08:57:16 -0600 | [diff] [blame] | 332 | |
Daniel Gonzalez | bfd8aff | 2018-03-27 10:20:37 -0600 | [diff] [blame] | 333 | |
| 334 | Run Build Net |
| 335 | [Documentation] Run build_net to preconfigure the ethernet interfaces. |
| 336 | |
| 337 | OS Execute Command build_net help y y |
Gunnar Mills | 7732c7e | 2018-08-14 11:54:24 -0500 | [diff] [blame] | 338 | # Run pingum to check if the "build_net" was run correctly done. |
Daniel Gonzalez | bfd8aff | 2018-03-27 10:20:37 -0600 | [diff] [blame] | 339 | ${output} ${stderr} ${rc}= OS Execute Command pingum |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 340 | Should Contain ${output} All networks ping Ok |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 341 | |
| 342 | |
| 343 | Configure Hostname |
| 344 | [Documentation] Configure hostname on BMC via Redfish. |
| 345 | [Arguments] ${hostname} |
| 346 | |
| 347 | # Description of argument(s): |
| 348 | # hostname A hostname value which is to be configured on BMC. |
| 349 | |
Anves Kumar rayankula | 1cc996d | 2021-05-31 01:14:19 -0500 | [diff] [blame] | 350 | ${active_channel_config}= Get Active Channel Config |
| 351 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 352 | |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 353 | ${data}= Create Dictionary HostName=${hostname} |
Anves Kumar rayankula | 1cc996d | 2021-05-31 01:14:19 -0500 | [diff] [blame] | 354 | Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data} |
George Keishing | 5041d6d | 2020-01-14 12:19:06 -0600 | [diff] [blame] | 355 | ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}] |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 356 | |
Naman Navin Hegde | 5369145 | 2019-07-30 00:22:37 -0500 | [diff] [blame] | 357 | |
| 358 | Verify IP On BMC |
| 359 | [Documentation] Verify IP on BMC. |
| 360 | [Arguments] ${ip} |
| 361 | |
| 362 | # Description of argument(s): |
| 363 | # ip IP address to be verified (e.g. "10.7.7.7"). |
| 364 | |
| 365 | # Get IP address details on BMC using IP command. |
| 366 | @{ip_data}= Get BMC IP Info |
| 367 | Should Contain Match ${ip_data} ${ip}/* |
| 368 | ... msg=IP address does not exist. |
| 369 | |
| 370 | |
| 371 | Verify Gateway On BMC |
| 372 | [Documentation] Verify gateway on BMC. |
| 373 | [Arguments] ${gateway_ip}=0.0.0.0 |
| 374 | |
| 375 | # Description of argument(s): |
| 376 | # gateway_ip Gateway IP address. |
| 377 | |
| 378 | ${route_info}= Get BMC Route Info |
| 379 | |
| 380 | # If gateway IP is empty or 0.0.0.0 it will not have route entry. |
| 381 | |
| 382 | Run Keyword If '${gateway_ip}' == '0.0.0.0' |
| 383 | ... Pass Execution Gateway IP is "0.0.0.0". |
| 384 | ... ELSE |
| 385 | ... Should Contain ${route_info} ${gateway_ip} |
| 386 | ... msg=Gateway IP address not matching. |
| 387 | |
| 388 | |
| 389 | Get BMC DNS Info |
| 390 | [Documentation] Get system DNS info. |
| 391 | |
| 392 | |
| 393 | # Sample output of "resolv.conf": |
| 394 | # ### Generated manually via dbus settings ### |
| 395 | # nameserver 8.8.8.8 |
| 396 | |
| 397 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 398 | ... cat /etc/resolv.conf |
| 399 | |
| 400 | [Return] ${cmd_output} |
| 401 | |
| 402 | |
| 403 | CLI Get Nameservers |
| 404 | [Documentation] Get the nameserver IPs from /etc/resolv.conf and return as a list. |
| 405 | |
| 406 | # Example of /etc/resolv.conf data: |
| 407 | # nameserver x.x.x.x |
| 408 | # nameserver y.y.y.y |
| 409 | |
| 410 | ${stdout} ${stderr} ${rc}= BMC Execute Command egrep nameserver /etc/resolv.conf | cut -f2- -d ' ' |
| 411 | ${nameservers}= Split String ${stdout} |
| 412 | |
| 413 | [Return] ${nameservers} |
Anvesh Kumar Rayankula | ada25db | 2020-02-19 01:29:17 -0600 | [diff] [blame] | 414 | |
| 415 | |
| 416 | Get Network Configuration |
| 417 | [Documentation] Get network configuration. |
| 418 | # Sample output: |
| 419 | #{ |
| 420 | # "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface", |
| 421 | # "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0", |
| 422 | # "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface", |
| 423 | # "Description": "Management Network Interface", |
| 424 | # "IPv4Addresses": [ |
| 425 | # { |
| 426 | # "Address": "169.254.xx.xx", |
| 427 | # "AddressOrigin": "IPv4LinkLocal", |
| 428 | # "Gateway": "0.0.0.0", |
| 429 | # "SubnetMask": "255.255.0.0" |
| 430 | # }, |
| 431 | # { |
| 432 | # "Address": "xx.xx.xx.xx", |
| 433 | # "AddressOrigin": "Static", |
| 434 | # "Gateway": "xx.xx.xx.1", |
| 435 | # "SubnetMask": "xx.xx.xx.xx" |
| 436 | # } |
| 437 | # ], |
| 438 | # "Id": "eth0", |
| 439 | # "MACAddress": "xx:xx:xx:xx:xx:xx", |
| 440 | # "Name": "Manager Ethernet Interface", |
| 441 | # "SpeedMbps": 0, |
| 442 | # "VLAN": { |
| 443 | # "VLANEnable": false, |
| 444 | # "VLANId": 0 |
| 445 | # } |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 446 | |
| 447 | |
Tony Lee | 9f6b204 | 2020-04-27 20:20:43 +0800 | [diff] [blame] | 448 | ${active_channel_config}= Get Active Channel Config |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 449 | ${resp}= Redfish.Get ${REDFISH_NW_ETH_IFACE}${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 450 | |
Anvesh Kumar Rayankula | ada25db | 2020-02-19 01:29:17 -0600 | [diff] [blame] | 451 | @{network_configurations}= Get From Dictionary ${resp.dict} IPv4StaticAddresses |
| 452 | [Return] @{network_configurations} |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 453 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 454 | |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 455 | Add IP Address |
| 456 | [Documentation] Add IP Address To BMC. |
| 457 | [Arguments] ${ip} ${subnet_mask} ${gateway} |
| 458 | ... ${valid_status_codes}=${HTTP_OK} |
| 459 | |
| 460 | # Description of argument(s): |
| 461 | # ip IP address to be added (e.g. "10.7.7.7"). |
| 462 | # subnet_mask Subnet mask for the IP to be added |
| 463 | # (e.g. "255.255.0.0"). |
| 464 | # gateway Gateway for the IP to be added (e.g. "10.7.7.1"). |
| 465 | # valid_status_codes Expected return code from patch operation |
| 466 | # (e.g. "200"). See prolog of rest_request |
| 467 | # method in redfish_plus.py for details. |
| 468 | |
| 469 | ${empty_dict}= Create Dictionary |
| 470 | ${ip_data}= Create Dictionary Address=${ip} |
| 471 | ... SubnetMask=${subnet_mask} Gateway=${gateway} |
| 472 | |
| 473 | ${patch_list}= Create List |
| 474 | ${network_configurations}= Get Network Configuration |
| 475 | ${num_entries}= Get Length ${network_configurations} |
| 476 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 477 | FOR ${INDEX} IN RANGE 0 ${num_entries} |
| 478 | Append To List ${patch_list} ${empty_dict} |
| 479 | END |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 480 | |
Anves Kumar rayankula | 53b8030 | 2021-05-21 01:50:03 -0500 | [diff] [blame] | 481 | ${valid_status_codes}= Run Keyword If '${valid_status_codes}' == '${HTTP_OK}' |
| 482 | ... Set Variable ${HTTP_OK},${HTTP_NO_CONTENT} |
| 483 | ... ELSE Set Variable ${valid_status_codes} |
| 484 | |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 485 | # We need not check for existence of IP on BMC while adding. |
| 486 | Append To List ${patch_list} ${ip_data} |
| 487 | ${data}= Create Dictionary IPv4StaticAddresses=${patch_list} |
| 488 | |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 489 | ${active_channel_config}= Get Active Channel Config |
| 490 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 491 | |
| 492 | Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data} |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 493 | ... valid_status_codes=[${valid_status_codes}] |
| 494 | |
Anves Kumar rayankula | 53b8030 | 2021-05-21 01:50:03 -0500 | [diff] [blame] | 495 | Return From Keyword If '${valid_status_codes}' != '${HTTP_OK},${HTTP_NO_CONTENT}' |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 496 | |
| 497 | # Note: Network restart takes around 15-18s after patch request processing. |
| 498 | Sleep ${NETWORK_TIMEOUT}s |
| 499 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 500 | |
| 501 | Verify IP On BMC ${ip} |
| 502 | Validate Network Config On BMC |
| 503 | |
| 504 | |
| 505 | Delete IP Address |
| 506 | [Documentation] Delete IP Address Of BMC. |
| 507 | [Arguments] ${ip} ${valid_status_codes}=${HTTP_OK} |
| 508 | |
| 509 | # Description of argument(s): |
| 510 | # ip IP address to be deleted (e.g. "10.7.7.7"). |
| 511 | # valid_status_codes Expected return code from patch operation |
| 512 | # (e.g. "200"). See prolog of rest_request |
| 513 | # method in redfish_plus.py for details. |
| 514 | |
| 515 | ${empty_dict}= Create Dictionary |
| 516 | ${patch_list}= Create List |
| 517 | |
| 518 | @{network_configurations}= Get Network Configuration |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 519 | FOR ${network_configuration} IN @{network_configurations} |
| 520 | Run Keyword If '${network_configuration['Address']}' == '${ip}' |
| 521 | ... Append To List ${patch_list} ${null} |
| 522 | ... ELSE Append To List ${patch_list} ${empty_dict} |
| 523 | END |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 524 | |
| 525 | ${ip_found}= Run Keyword And Return Status List Should Contain Value |
| 526 | ... ${patch_list} ${null} msg=${ip} does not exist on BMC |
| 527 | Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC |
| 528 | |
| 529 | # Run patch command only if given IP is found on BMC |
| 530 | ${data}= Create Dictionary IPv4StaticAddresses=${patch_list} |
| 531 | |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 532 | ${active_channel_config}= Get Active Channel Config |
| 533 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 534 | |
| 535 | Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data} |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 536 | ... valid_status_codes=[${valid_status_codes}] |
| 537 | |
| 538 | # Note: Network restart takes around 15-18s after patch request processing |
| 539 | Sleep ${NETWORK_TIMEOUT}s |
| 540 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 541 | |
| 542 | ${delete_status}= Run Keyword And Return Status Verify IP On BMC ${ip} |
| 543 | Run Keyword If '${valid_status_codes}' == '${HTTP_OK}' |
| 544 | ... Should Be True '${delete_status}' == '${False}' |
| 545 | ... ELSE Should Be True '${delete_status}' == '${True}' |
| 546 | |
| 547 | Validate Network Config On BMC |
| 548 | |
| 549 | |
| 550 | Validate Network Config On BMC |
| 551 | [Documentation] Check that network info obtained via redfish matches info |
| 552 | ... obtained via CLI. |
| 553 | |
| 554 | @{network_configurations}= Get Network Configuration |
| 555 | ${ip_data}= Get BMC IP Info |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 556 | FOR ${network_configuration} IN @{network_configurations} |
| 557 | Should Contain Match ${ip_data} ${network_configuration['Address']}/* |
| 558 | ... msg=IP address does not exist. |
| 559 | END |
| 560 | |
| 561 | |
| 562 | Create VLAN |
| 563 | [Documentation] Create a VLAN. |
| 564 | [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid |
| 565 | |
| 566 | # Description of argument(s): |
| 567 | # id The VLAN ID (e.g. '53'). |
| 568 | # interface The physical interface for the VLAN(e.g. 'eth0'). |
| 569 | # expected_result Expected status of VLAN configuration. |
| 570 | |
| 571 | @{data_vlan_id}= Create List ${interface} ${id} |
| 572 | ${data}= Create Dictionary data=@{data_vlan_id} |
| 573 | ${resp}= OpenBMC Post Request ${vlan_resource} data=${data} |
| 574 | ${resp.status_code}= Convert To String ${resp.status_code} |
| 575 | ${status}= Run Keyword And Return Status |
| 576 | ... Valid Value resp.status_code ["${HTTP_OK}"] |
| 577 | |
| 578 | Run Keyword If '${expected_result}' == 'error' |
| 579 | ... Should Be Equal ${status} ${False} |
| 580 | ... msg=Configuration of an invalid VLAN ID Failed. |
| 581 | ... ELSE |
| 582 | ... Should Be Equal ${status} ${True} |
| 583 | ... msg=Configuration of a valid VLAN ID Failed. |
| 584 | |
| 585 | Sleep ${NETWORK_TIMEOUT}s |
| 586 | |
| 587 | |
| 588 | Configure Network Settings On VLAN |
| 589 | [Documentation] Configure network settings. |
| 590 | [Arguments] ${id} ${ip_addr} ${prefix_len} ${gateway_ip}=${gateway} |
| 591 | ... ${expected_result}=valid ${interface}=eth0 |
| 592 | |
| 593 | # Description of argument(s): |
| 594 | # id The VLAN ID (e.g. '53'). |
| 595 | # ip_addr IP address of VLAN Interface. |
| 596 | # prefix_len Prefix length of VLAN Interface. |
| 597 | # gateway_ip Gateway IP address of VLAN Interface. |
| 598 | # expected_result Expected status of network setting configuration. |
| 599 | # interface Physical Interface on which the VLAN is defined. |
| 600 | |
| 601 | @{ip_parm_list}= Create List ${network_resource} |
| 602 | ... ${ip_addr} ${prefix_len} ${gateway_ip} |
| 603 | |
| 604 | ${data}= Create Dictionary data=@{ip_parm_list} |
| 605 | |
| 606 | Run Keyword And Ignore Error OpenBMC Post Request |
| 607 | ... ${NETWORK_MANAGER}${interface}_${id}/action/IP data=${data} |
| 608 | |
| 609 | # After any modification on network interface, BMC restarts network |
| 610 | # module, wait until it is reachable. Then wait 15 seconds for new |
| 611 | # configuration to be updated on BMC. |
| 612 | |
| 613 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 614 | ... ${NETWORK_RETRY_TIME} |
| 615 | Sleep ${NETWORK_TIMEOUT}s |
| 616 | |
| 617 | # Verify whether new IP address is populated on BMC system. |
| 618 | # It should not allow to configure invalid settings. |
| 619 | ${status}= Run Keyword And Return Status |
| 620 | ... Verify IP On BMC ${ip_addr} |
| 621 | |
| 622 | Run Keyword If '${expected_result}' == 'error' |
| 623 | ... Should Be Equal ${status} ${False} |
| 624 | ... msg=Configuration of invalid IP Failed. |
| 625 | ... ELSE |
| 626 | ... Should Be Equal ${status} ${True} |
| 627 | ... msg=Configuration of valid IP Failed. |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 628 | |
Prashanth Katti | b478d90 | 2020-05-08 10:05:32 -0500 | [diff] [blame] | 629 | |
| 630 | Get BMC Default Gateway |
| 631 | [Documentation] Get system default gateway. |
| 632 | |
| 633 | ${route_info}= Get BMC Route Info |
| 634 | |
| 635 | ${lines}= Get Lines Containing String ${route_info} default via |
| 636 | @{gateway_list}= Split To Lines ${lines} |
| 637 | |
| 638 | # Extract first default gateway and return. |
| 639 | @{default_gw}= Split String ${gateway_list[0]} |
| 640 | |
| 641 | [Return] ${default_gw[2]} |
Anves Kumar rayankula | 55d5192 | 2021-07-01 06:37:00 -0500 | [diff] [blame] | 642 | |
| 643 | |
| 644 | Validate Hostname On BMC |
| 645 | [Documentation] Verify that the hostname read via Redfish is the same as the |
| 646 | ... hostname configured on system. |
| 647 | [Arguments] ${hostname} |
| 648 | |
| 649 | # Description of argument(s): |
| 650 | # hostname A hostname value which is to be compared to the hostname |
| 651 | # configured on system. |
| 652 | |
| 653 | ${sys_hostname}= Get BMC Hostname |
| 654 | Should Be Equal ${sys_hostname} ${hostname} |
| 655 | ... ignore_case=True msg=Hostname does not exist. |