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