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 |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 30 | IF '${mac_address.lower()}' != '${bmc_mac_addr.lower()}' |
| 31 | Set MAC Address |
| 32 | END |
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 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 35 | Set MAC Address |
| 36 | [Documentation] Update eth0 with input MAC address. |
| 37 | [Arguments] ${mac_address}=${MAC_ADDRESS} |
| 38 | |
| 39 | # Description of argument(s): |
| 40 | # mac_address The mac address (e.g. 00:01:6c:80:02:28). |
| 41 | |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 42 | ${active_channel_config}= Get Active Channel Config |
| 43 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 44 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 45 | Write fw_setenv ethaddr ${mac_address} |
| 46 | OBMC Reboot (off) |
Sunil M | d1c4f27 | 2017-07-07 09:03:24 -0500 | [diff] [blame] | 47 | |
| 48 | # Take SSH session post BMC reboot. |
| 49 | Open Connection And Log In |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 50 | ${bmc_mac_addr} ${stderr} ${rc}= BMC Execute Command |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 51 | ... cat /sys/class/net/${ethernet_interface}/address |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 52 | Should Be Equal ${bmc_mac_addr} ${mac_address} ignore_case=True |
| 53 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 54 | |
| 55 | Get BMC IP Info |
| 56 | [Documentation] Get system IP address and prefix length. |
| 57 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 58 | |
| 59 | # Get system IP address and prefix length details using "ip addr" |
| 60 | # Sample Output of "ip addr": |
| 61 | # 1: eth0: <BROADCAST,MULTIAST> mtu 1500 qdisc mq state UP qlen 1000 |
| 62 | # link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff |
| 63 | # inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0 |
| 64 | |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 65 | ${active_channel_config}= Get Active Channel Config |
| 66 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 67 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 68 | ... /sbin/ip addr | grep ${ethernet_interface} |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 69 | |
| 70 | # Get line having IP address details. |
| 71 | ${lines}= Get Lines Containing String ${cmd_output} inet |
| 72 | |
| 73 | # List IP address details. |
| 74 | @{ip_components}= Split To Lines ${lines} |
| 75 | |
| 76 | @{ip_data}= Create List |
| 77 | |
| 78 | # Get all IP addresses and prefix lengths on system. |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 79 | FOR ${ip_component} IN @{ip_components} |
| 80 | @{if_info}= Split String ${ip_component} |
| 81 | ${ip_n_prefix}= Get From List ${if_info} 1 |
| 82 | Append To List ${ip_data} ${ip_n_prefix} |
| 83 | END |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 84 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 85 | RETURN ${ip_data} |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 86 | |
| 87 | Get BMC Route Info |
| 88 | [Documentation] Get system route info. |
| 89 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 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 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 98 | RETURN ${cmd_output} |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 99 | |
| 100 | Get BMC MAC Address |
| 101 | [Documentation] Get system MAC address. |
| 102 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 103 | # Sample output of "ip addr | grep ether": |
| 104 | # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff |
| 105 | |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 106 | ${active_channel_config}= Get Active Channel Config |
| 107 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 108 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 109 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
Tony Lee | 8094d38 | 2020-04-02 13:14:47 +0800 | [diff] [blame] | 110 | ... /sbin/ip addr | grep ${ethernet_interface} -A 1 | grep ether |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 111 | |
Prashanth Katti | 9819b16 | 2017-12-12 05:38:59 -0600 | [diff] [blame] | 112 | # Split the line and return MAC address. |
| 113 | # Split list data: |
| 114 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 115 | |
| 116 | @{words}= Split String ${cmd_output} |
| 117 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 118 | RETURN ${words[1]} |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 119 | |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 120 | |
| 121 | Get BMC MAC Address List |
| 122 | [Documentation] Get system MAC address |
| 123 | |
| 124 | # Sample output of "ip addr | grep ether": |
| 125 | # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff |
| 126 | |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 127 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 128 | ... /sbin/ip addr | grep ether |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 129 | |
| 130 | # Split the line and return MAC address. |
| 131 | # Split list data: |
| 132 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 133 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 134 | |
| 135 | ${mac_list}= Create List |
Joy Onyerikwu | 9b66897 | 2018-05-22 19:10:43 -0500 | [diff] [blame] | 136 | @{lines}= Split To Lines ${cmd_output} |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 137 | FOR ${line} IN @{lines} |
| 138 | @{words}= Split String ${line} |
| 139 | Append To List ${mac_list} ${words[1]} |
| 140 | END |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 141 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 142 | RETURN ${mac_list} |
George Keishing | 02651f0 | 2018-04-11 02:07:16 -0500 | [diff] [blame] | 143 | |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 144 | Get BMC Hostname |
| 145 | [Documentation] Get BMC hostname. |
| 146 | |
Prashanth Katti | c068faa | 2019-04-16 00:57:22 -0500 | [diff] [blame] | 147 | # Sample output of "hostname": |
| 148 | # test_hostname |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 149 | |
Prashanth Katti | c068faa | 2019-04-16 00:57:22 -0500 | [diff] [blame] | 150 | ${output} ${stderr} ${rc}= BMC Execute Command hostname |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 151 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 152 | RETURN ${output} |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 153 | |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 154 | Get FW_Env MAC Address |
| 155 | [Documentation] Get FW_Env MAC address. |
| 156 | |
| 157 | # Sample output of "fw_printenv | grep ethaddr" |
| 158 | # ethaddr=xx:xx:xx:xx:xx:xx:xx |
| 159 | |
Sweta Potthuri | 9a77ac5 | 2021-10-04 00:30:43 -0500 | [diff] [blame] | 160 | ${active_channel_config}= Get Active Channel Config |
| 161 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 162 | |
Sweta Potthuri | b461a98 | 2021-10-25 09:03:26 -0500 | [diff] [blame] | 163 | ${ethernet_interface}= Set Variable If |
| 164 | ... "${ethernet_interface}"=="eth0" ethaddr eth1addr |
| 165 | |
| 166 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command /sbin/fw_printenv | grep ${ethernet_interface} |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 167 | |
| 168 | # Split the line and return MAC address. |
| 169 | # Split list data: |
| 170 | # ethaddr | xx:xx:xx:xx:xx:xx:xx |
| 171 | |
| 172 | @{words}= Split String ${cmd_output} = |
| 173 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 174 | RETURN ${words[1]} |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 175 | |
| 176 | |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 177 | Get List Of IP Address Via REST |
| 178 | [Documentation] Get list of IP address via REST. |
| 179 | [Arguments] @{ip_uri_list} |
| 180 | |
| 181 | # Description of argument(s): |
| 182 | # ip_uri_list List of IP objects. |
| 183 | # Example: |
| 184 | # "data": [ |
| 185 | # "/xyz/openbmc_project/network/eth0/ipv4/e9767624", |
| 186 | # "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b" |
| 187 | # ], |
| 188 | |
| 189 | ${ip_list}= Create List |
| 190 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 191 | FOR ${ip_uri} IN @{ip_uri_list} |
| 192 | ${ip_addr}= Read Attribute ${ip_uri} Address |
| 193 | Append To List ${ip_list} ${ip_addr} |
| 194 | END |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 195 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 196 | RETURN @{ip_list} |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 197 | |
| 198 | Delete IP And Object |
| 199 | [Documentation] Delete IP and object. |
| 200 | [Arguments] ${ip_addr} @{ip_uri_list} |
| 201 | |
| 202 | # Description of argument(s): |
| 203 | # ip_addr IP address to be deleted. |
| 204 | # ip_uri_list List of IP object URIs. |
| 205 | |
| 206 | # Find IP object having this IP address. |
| 207 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 208 | FOR ${ip_uri} IN @{ip_uri_list} |
| 209 | ${ip_addr1}= Read Attribute ${ip_uri} Address |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 210 | IF '${ip_addr}' == '${ip_addr1}' |
| 211 | Exit For Loop |
| 212 | END |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 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} |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 314 | IF ${mac_int} >= ${256} |
| 315 | ${user_mac_byte}= Truncate MAC Bits ${user_mac_list}[${mac_byte}] |
| 316 | ELSE |
| 317 | ${user_mac_byte}= Set Variable ${user_mac_list}[${mac_byte}] |
| 318 | END |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 319 | Append To List ${user_new_mac_list} ${user_mac_byte} |
| 320 | ${mac_byte} = Set Variable ${mac_byte + 1} |
| 321 | Exit For Loop If '${mac_byte}' == '${user_mac_len}' |
| 322 | |
| 323 | END |
| 324 | ${user_new_mac_string}= Evaluate ":".join(${user_new_mac_list}) |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 325 | RETURN ${user_new_mac_string} |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 326 | |
| 327 | Truncate MAC Bits |
Anves Kumar rayankula | 0b9efea | 2021-05-28 08:52:28 -0500 | [diff] [blame] | 328 | [Documentation] Truncates user provided MAC address byte to bits. |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 329 | [Arguments] ${user_mac_addr_byte} |
Anves Kumar rayankula | 0b9efea | 2021-05-28 08:52:28 -0500 | [diff] [blame] | 330 | |
shrsuman123 | fdc51d2 | 2020-08-18 06:51:09 -0500 | [diff] [blame] | 331 | # Description of argument(s): |
| 332 | # user_mac_addr_byte user provided MAC address byte to truncate bits |
| 333 | |
| 334 | ${user_mac_addr_int}= Convert To List ${user_mac_addr_byte} |
| 335 | ${user_mac_addr_byte}= Get Slice From List ${user_mac_addr_int} 0 2 |
| 336 | ${user_mac_addr_byte_string}= Evaluate "".join(${user_mac_addr_byte}) |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 337 | RETURN ${user_mac_addr_byte_string} |
George Keishing | bf72477 | 2018-02-21 08:57:16 -0600 | [diff] [blame] | 338 | |
Daniel Gonzalez | bfd8aff | 2018-03-27 10:20:37 -0600 | [diff] [blame] | 339 | |
| 340 | Run Build Net |
| 341 | [Documentation] Run build_net to preconfigure the ethernet interfaces. |
| 342 | |
| 343 | OS Execute Command build_net help y y |
Gunnar Mills | 7732c7e | 2018-08-14 11:54:24 -0500 | [diff] [blame] | 344 | # Run pingum to check if the "build_net" was run correctly done. |
Daniel Gonzalez | bfd8aff | 2018-03-27 10:20:37 -0600 | [diff] [blame] | 345 | ${output} ${stderr} ${rc}= OS Execute Command pingum |
Prashanth Katti | 549c63a | 2018-07-17 06:13:37 -0500 | [diff] [blame] | 346 | Should Contain ${output} All networks ping Ok |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 347 | |
| 348 | |
| 349 | Configure Hostname |
| 350 | [Documentation] Configure hostname on BMC via Redfish. |
Sushil Singh | 44bfc20 | 2023-02-08 09:53:36 -0600 | [diff] [blame] | 351 | [Arguments] ${hostname} ${status_code}=[${HTTP_OK}, ${HTTP_NO_CONTENT}] |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 352 | |
| 353 | # Description of argument(s): |
Sridevi Ramesh | 8924229 | 2025-07-20 02:36:56 -0500 | [diff] [blame] | 354 | # hostname A hostname value which is to be configured on BMC. |
| 355 | # status_codes Expected return code from patch operation |
| 356 | # (e.g. "200"). See prolog of rest_request |
| 357 | # method in redfish_plus.py for details. |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 358 | |
Anves Kumar rayankula | 1cc996d | 2021-05-31 01:14:19 -0500 | [diff] [blame] | 359 | ${active_channel_config}= Get Active Channel Config |
| 360 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 361 | |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 362 | ${data}= Create Dictionary HostName=${hostname} |
Anves Kumar rayankula | 1cc996d | 2021-05-31 01:14:19 -0500 | [diff] [blame] | 363 | Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data} |
Sushil Singh | 44bfc20 | 2023-02-08 09:53:36 -0600 | [diff] [blame] | 364 | ... valid_status_codes=${status_code} |
Sushil Singh | f661a10 | 2019-06-04 00:52:48 -0500 | [diff] [blame] | 365 | |
Naman Navin Hegde | 5369145 | 2019-07-30 00:22:37 -0500 | [diff] [blame] | 366 | |
| 367 | Verify IP On BMC |
| 368 | [Documentation] Verify IP on BMC. |
| 369 | [Arguments] ${ip} |
| 370 | |
| 371 | # Description of argument(s): |
| 372 | # ip IP address to be verified (e.g. "10.7.7.7"). |
| 373 | |
| 374 | # Get IP address details on BMC using IP command. |
| 375 | @{ip_data}= Get BMC IP Info |
| 376 | Should Contain Match ${ip_data} ${ip}/* |
| 377 | ... msg=IP address does not exist. |
| 378 | |
| 379 | |
| 380 | Verify Gateway On BMC |
| 381 | [Documentation] Verify gateway on BMC. |
| 382 | [Arguments] ${gateway_ip}=0.0.0.0 |
| 383 | |
| 384 | # Description of argument(s): |
| 385 | # gateway_ip Gateway IP address. |
| 386 | |
| 387 | ${route_info}= Get BMC Route Info |
| 388 | |
| 389 | # If gateway IP is empty or 0.0.0.0 it will not have route entry. |
| 390 | |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 391 | IF '${gateway_ip}' == '0.0.0.0' |
| 392 | Pass Execution Gateway IP is "0.0.0.0". |
| 393 | ELSE |
| 394 | Should Contain ${route_info} ${gateway_ip} msg=Gateway IP address not matching. |
| 395 | END |
Naman Navin Hegde | 5369145 | 2019-07-30 00:22:37 -0500 | [diff] [blame] | 396 | |
| 397 | |
| 398 | Get BMC DNS Info |
| 399 | [Documentation] Get system DNS info. |
| 400 | |
| 401 | |
| 402 | # Sample output of "resolv.conf": |
| 403 | # ### Generated manually via dbus settings ### |
| 404 | # nameserver 8.8.8.8 |
| 405 | |
| 406 | ${cmd_output} ${stderr} ${rc}= BMC Execute Command |
| 407 | ... cat /etc/resolv.conf |
| 408 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 409 | RETURN ${cmd_output} |
Naman Navin Hegde | 5369145 | 2019-07-30 00:22:37 -0500 | [diff] [blame] | 410 | |
| 411 | |
| 412 | CLI Get Nameservers |
| 413 | [Documentation] Get the nameserver IPs from /etc/resolv.conf and return as a list. |
| 414 | |
| 415 | # Example of /etc/resolv.conf data: |
| 416 | # nameserver x.x.x.x |
| 417 | # nameserver y.y.y.y |
| 418 | |
Sweta Potthuri | dc32593 | 2022-06-15 12:51:27 -0500 | [diff] [blame] | 419 | ${stdout} ${stderr} ${rc}= BMC Execute Command |
| 420 | ... egrep nameserver /etc/resolv.conf | cut -f2- -d ' ' |
Naman Navin Hegde | 5369145 | 2019-07-30 00:22:37 -0500 | [diff] [blame] | 421 | ${nameservers}= Split String ${stdout} |
| 422 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 423 | RETURN ${nameservers} |
Anvesh Kumar Rayankula | ada25db | 2020-02-19 01:29:17 -0600 | [diff] [blame] | 424 | |
kothais | 878f4f9 | 2023-11-02 11:43:37 +0000 | [diff] [blame] | 425 | CLI Get and Verify Name Servers |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 426 | [Documentation] Get and Verify the nameserver IPs from /etc/resolv.conf |
| 427 | ... and compare with redfish nameserver. |
kothais | 878f4f9 | 2023-11-02 11:43:37 +0000 | [diff] [blame] | 428 | [Arguments] ${static_name_servers} |
| 429 | ... ${valid_status_codes}=${HTTP_OK} |
| 430 | |
| 431 | # Description of Argument(s): |
Sridevi Ramesh | 8924229 | 2025-07-20 02:36:56 -0500 | [diff] [blame] | 432 | # static_name_servers Address for static name server |
| 433 | # valid_status_codes Expected return code from patch operation |
| 434 | # (e.g. "200"). See prolog of rest_request |
| 435 | # method in redfish_plus.py for details. |
kothais | 878f4f9 | 2023-11-02 11:43:37 +0000 | [diff] [blame] | 436 | |
| 437 | ${cli_nameservers}= CLI Get Nameservers |
| 438 | ${cmd_status}= Run Keyword And Return Status |
| 439 | ... List Should Contain Sub List ${cli_nameservers} ${static_name_servers} |
| 440 | |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 441 | IF '${valid_status_codes}' == '${HTTP_OK}' |
| 442 | Should Be True ${cmd_status} |
| 443 | ELSE |
| 444 | Should Not Be True ${cmd_status} |
| 445 | END |
Anvesh Kumar Rayankula | ada25db | 2020-02-19 01:29:17 -0600 | [diff] [blame] | 446 | |
| 447 | Get Network Configuration |
| 448 | [Documentation] Get network configuration. |
| 449 | # Sample output: |
| 450 | #{ |
| 451 | # "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface", |
ganesanb | 4d43028 | 2023-04-27 14:33:23 +0000 | [diff] [blame] | 452 | # "@odata.id": "/redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/eth0", |
Anvesh Kumar Rayankula | ada25db | 2020-02-19 01:29:17 -0600 | [diff] [blame] | 453 | # "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface", |
| 454 | # "Description": "Management Network Interface", |
| 455 | # "IPv4Addresses": [ |
| 456 | # { |
| 457 | # "Address": "169.254.xx.xx", |
| 458 | # "AddressOrigin": "IPv4LinkLocal", |
| 459 | # "Gateway": "0.0.0.0", |
| 460 | # "SubnetMask": "255.255.0.0" |
| 461 | # }, |
| 462 | # { |
| 463 | # "Address": "xx.xx.xx.xx", |
| 464 | # "AddressOrigin": "Static", |
| 465 | # "Gateway": "xx.xx.xx.1", |
| 466 | # "SubnetMask": "xx.xx.xx.xx" |
| 467 | # } |
| 468 | # ], |
| 469 | # "Id": "eth0", |
| 470 | # "MACAddress": "xx:xx:xx:xx:xx:xx", |
| 471 | # "Name": "Manager Ethernet Interface", |
| 472 | # "SpeedMbps": 0, |
| 473 | # "VLAN": { |
| 474 | # "VLANEnable": false, |
| 475 | # "VLANId": 0 |
| 476 | # } |
shrsuman123 | 7ba02f3 | 2021-08-26 04:50:56 -0500 | [diff] [blame] | 477 | [Arguments] ${network_active_channel}=${CHANNEL_NUMBER} |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 478 | |
shrsuman123 | 7ba02f3 | 2021-08-26 04:50:56 -0500 | [diff] [blame] | 479 | # Description of argument(s): |
| 480 | # network_active_channel Ethernet channel number (eg. 1 or 2) |
George Keishing | 33be359 | 2022-03-08 08:52:25 -0600 | [diff] [blame] | 481 | |
Tony Lee | 9f6b204 | 2020-04-27 20:20:43 +0800 | [diff] [blame] | 482 | ${active_channel_config}= Get Active Channel Config |
shrsuman123 | 7ba02f3 | 2021-08-26 04:50:56 -0500 | [diff] [blame] | 483 | ${resp}= Redfish.Get |
| 484 | ... ${REDFISH_NW_ETH_IFACE}${active_channel_config['${network_active_channel}']['name']} |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 485 | |
Anvesh Kumar Rayankula | ada25db | 2020-02-19 01:29:17 -0600 | [diff] [blame] | 486 | @{network_configurations}= Get From Dictionary ${resp.dict} IPv4StaticAddresses |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 487 | RETURN @{network_configurations} |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 488 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 489 | |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 490 | Add IP Address |
| 491 | [Documentation] Add IP Address To BMC. |
| 492 | [Arguments] ${ip} ${subnet_mask} ${gateway} |
| 493 | ... ${valid_status_codes}=${HTTP_OK} |
| 494 | |
| 495 | # Description of argument(s): |
| 496 | # ip IP address to be added (e.g. "10.7.7.7"). |
| 497 | # subnet_mask Subnet mask for the IP to be added |
| 498 | # (e.g. "255.255.0.0"). |
| 499 | # gateway Gateway for the IP to be added (e.g. "10.7.7.1"). |
| 500 | # valid_status_codes Expected return code from patch operation |
| 501 | # (e.g. "200"). See prolog of rest_request |
| 502 | # method in redfish_plus.py for details. |
| 503 | |
| 504 | ${empty_dict}= Create Dictionary |
| 505 | ${ip_data}= Create Dictionary Address=${ip} |
| 506 | ... SubnetMask=${subnet_mask} Gateway=${gateway} |
| 507 | |
| 508 | ${patch_list}= Create List |
| 509 | ${network_configurations}= Get Network Configuration |
| 510 | ${num_entries}= Get Length ${network_configurations} |
| 511 | |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 512 | FOR ${INDEX} IN RANGE 0 ${num_entries} |
| 513 | Append To List ${patch_list} ${empty_dict} |
| 514 | END |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 515 | |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 516 | ${valid_status_codes}= Set Variable If '${valid_status_codes}' == '${HTTP_OK}' |
| 517 | ... ${HTTP_OK},${HTTP_NO_CONTENT} ${valid_status_codes} |
Anves Kumar rayankula | 53b8030 | 2021-05-21 01:50:03 -0500 | [diff] [blame] | 518 | |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 519 | # We need not check for existence of IP on BMC while adding. |
| 520 | Append To List ${patch_list} ${ip_data} |
| 521 | ${data}= Create Dictionary IPv4StaticAddresses=${patch_list} |
| 522 | |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 523 | ${active_channel_config}= Get Active Channel Config |
| 524 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 525 | |
| 526 | Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data} |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 527 | ... valid_status_codes=[${valid_status_codes}] |
| 528 | |
Anves Kumar rayankula | 53b8030 | 2021-05-21 01:50:03 -0500 | [diff] [blame] | 529 | Return From Keyword If '${valid_status_codes}' != '${HTTP_OK},${HTTP_NO_CONTENT}' |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 530 | |
| 531 | # Note: Network restart takes around 15-18s after patch request processing. |
| 532 | Sleep ${NETWORK_TIMEOUT}s |
| 533 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 534 | |
| 535 | Verify IP On BMC ${ip} |
| 536 | Validate Network Config On BMC |
| 537 | |
| 538 | |
| 539 | Delete IP Address |
| 540 | [Documentation] Delete IP Address Of BMC. |
Sweta Potthuri | c9649ca | 2025-05-07 00:48:43 -0500 | [diff] [blame] | 541 | [Arguments] ${ip} ${valid_status_codes}=[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}] |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 542 | |
| 543 | # Description of argument(s): |
| 544 | # ip IP address to be deleted (e.g. "10.7.7.7"). |
| 545 | # valid_status_codes Expected return code from patch operation |
| 546 | # (e.g. "200"). See prolog of rest_request |
| 547 | # method in redfish_plus.py for details. |
| 548 | |
| 549 | ${empty_dict}= Create Dictionary |
| 550 | ${patch_list}= Create List |
| 551 | |
| 552 | @{network_configurations}= Get Network Configuration |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 553 | FOR ${network_configuration} IN @{network_configurations} |
| 554 | Run Keyword If '${network_configuration['Address']}' == '${ip}' |
| 555 | ... Append To List ${patch_list} ${null} |
| 556 | ... ELSE Append To List ${patch_list} ${empty_dict} |
| 557 | END |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 558 | |
| 559 | ${ip_found}= Run Keyword And Return Status List Should Contain Value |
| 560 | ... ${patch_list} ${null} msg=${ip} does not exist on BMC |
| 561 | Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC |
| 562 | |
| 563 | # Run patch command only if given IP is found on BMC |
| 564 | ${data}= Create Dictionary IPv4StaticAddresses=${patch_list} |
| 565 | |
Tony Lee | 412c668 | 2020-04-01 17:34:30 +0800 | [diff] [blame] | 566 | ${active_channel_config}= Get Active Channel Config |
| 567 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 568 | |
| 569 | Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data} |
Sweta Potthuri | c9649ca | 2025-05-07 00:48:43 -0500 | [diff] [blame] | 570 | ... valid_status_codes=${valid_status_codes} |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 571 | |
| 572 | # Note: Network restart takes around 15-18s after patch request processing |
| 573 | Sleep ${NETWORK_TIMEOUT}s |
| 574 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 575 | |
| 576 | ${delete_status}= Run Keyword And Return Status Verify IP On BMC ${ip} |
Sweta Potthuri | c9649ca | 2025-05-07 00:48:43 -0500 | [diff] [blame] | 577 | IF '${valid_status_codes}' == '[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}]' |
| 578 | Should Be True '${delete_status}' == '${False}' |
| 579 | ELSE |
| 580 | Should Be True '${delete_status}' == '${True}' |
| 581 | END |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 582 | |
| 583 | Validate Network Config On BMC |
| 584 | |
| 585 | |
| 586 | Validate Network Config On BMC |
| 587 | [Documentation] Check that network info obtained via redfish matches info |
| 588 | ... obtained via CLI. |
| 589 | |
| 590 | @{network_configurations}= Get Network Configuration |
| 591 | ${ip_data}= Get BMC IP Info |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 592 | FOR ${network_configuration} IN @{network_configurations} |
| 593 | Should Contain Match ${ip_data} ${network_configuration['Address']}/* |
| 594 | ... msg=IP address does not exist. |
| 595 | END |
| 596 | |
| 597 | |
| 598 | Create VLAN |
| 599 | [Documentation] Create a VLAN. |
| 600 | [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid |
| 601 | |
| 602 | # Description of argument(s): |
Sridevi Ramesh | 8924229 | 2025-07-20 02:36:56 -0500 | [diff] [blame] | 603 | # id The VLAN ID (e.g. '53'). |
| 604 | # interface The physical interface for the VLAN(e.g. 'eth0'). |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 605 | # expected_result Expected status of VLAN configuration. |
| 606 | |
| 607 | @{data_vlan_id}= Create List ${interface} ${id} |
| 608 | ${data}= Create Dictionary data=@{data_vlan_id} |
| 609 | ${resp}= OpenBMC Post Request ${vlan_resource} data=${data} |
| 610 | ${resp.status_code}= Convert To String ${resp.status_code} |
| 611 | ${status}= Run Keyword And Return Status |
| 612 | ... Valid Value resp.status_code ["${HTTP_OK}"] |
| 613 | |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 614 | IF '${expected_result}' == 'error' |
| 615 | Should Be Equal ${status} ${False} msg=Configuration of an invalid VLAN ID Failed. |
| 616 | ELSE |
| 617 | Should Be Equal ${status} ${True} msg=Configuration of a valid VLAN ID Failed. |
| 618 | END |
Anvesh Kumar Rayankula | e354c1c | 2020-03-09 06:01:13 -0500 | [diff] [blame] | 619 | |
| 620 | Sleep ${NETWORK_TIMEOUT}s |
| 621 | |
| 622 | |
| 623 | Configure Network Settings On VLAN |
| 624 | [Documentation] Configure network settings. |
| 625 | [Arguments] ${id} ${ip_addr} ${prefix_len} ${gateway_ip}=${gateway} |
| 626 | ... ${expected_result}=valid ${interface}=eth0 |
| 627 | |
| 628 | # Description of argument(s): |
| 629 | # id The VLAN ID (e.g. '53'). |
| 630 | # ip_addr IP address of VLAN Interface. |
| 631 | # prefix_len Prefix length of VLAN Interface. |
| 632 | # gateway_ip Gateway IP address of VLAN Interface. |
| 633 | # expected_result Expected status of network setting configuration. |
| 634 | # interface Physical Interface on which the VLAN is defined. |
| 635 | |
| 636 | @{ip_parm_list}= Create List ${network_resource} |
| 637 | ... ${ip_addr} ${prefix_len} ${gateway_ip} |
| 638 | |
| 639 | ${data}= Create Dictionary data=@{ip_parm_list} |
| 640 | |
| 641 | Run Keyword And Ignore Error OpenBMC Post Request |
| 642 | ... ${NETWORK_MANAGER}${interface}_${id}/action/IP data=${data} |
| 643 | |
| 644 | # After any modification on network interface, BMC restarts network |
| 645 | # module, wait until it is reachable. Then wait 15 seconds for new |
| 646 | # configuration to be updated on BMC. |
| 647 | |
| 648 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 649 | ... ${NETWORK_RETRY_TIME} |
| 650 | Sleep ${NETWORK_TIMEOUT}s |
| 651 | |
| 652 | # Verify whether new IP address is populated on BMC system. |
| 653 | # It should not allow to configure invalid settings. |
| 654 | ${status}= Run Keyword And Return Status |
| 655 | ... Verify IP On BMC ${ip_addr} |
| 656 | |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 657 | IF '${expected_result}' == 'error' |
| 658 | Should Be Equal ${status} ${False} msg=Configuration of invalid IP Failed. |
| 659 | ELSE |
| 660 | Should Be Equal ${status} ${True} msg=Configuration of valid IP Failed. |
| 661 | END |
Prashanth Katti | 3dc8cc3 | 2020-03-04 11:11:01 -0600 | [diff] [blame] | 662 | |
Prashanth Katti | b478d90 | 2020-05-08 10:05:32 -0500 | [diff] [blame] | 663 | |
| 664 | Get BMC Default Gateway |
| 665 | [Documentation] Get system default gateway. |
| 666 | |
| 667 | ${route_info}= Get BMC Route Info |
| 668 | |
| 669 | ${lines}= Get Lines Containing String ${route_info} default via |
Prashanth Katti | b478d90 | 2020-05-08 10:05:32 -0500 | [diff] [blame] | 670 | |
Sweta Potthuri | 811021d | 2022-08-08 11:28:05 -0500 | [diff] [blame] | 671 | ${active_channel_config}= Get Active Channel Config |
| 672 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 673 | |
| 674 | # Extract the corresponding default gateway for eth0 and eth1 |
| 675 | ${default_gw_line}= Get Lines Containing String ${lines} ${ethernet_interface} |
| 676 | ${default_gw}= Split String ${default_gw_line} |
| 677 | |
| 678 | # Example of the output |
| 679 | # default_gw: |
| 680 | # [0]: default |
| 681 | # [1]: via |
| 682 | # [2]: xx.xx.xx.1 |
| 683 | # [3]: dev |
| 684 | # [4]: eth1 |
Prashanth Katti | b478d90 | 2020-05-08 10:05:32 -0500 | [diff] [blame] | 685 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 686 | RETURN ${default_gw[2]} |
Anves Kumar rayankula | 55d5192 | 2021-07-01 06:37:00 -0500 | [diff] [blame] | 687 | |
| 688 | |
| 689 | Validate Hostname On BMC |
| 690 | [Documentation] Verify that the hostname read via Redfish is the same as the |
| 691 | ... hostname configured on system. |
| 692 | [Arguments] ${hostname} |
| 693 | |
| 694 | # Description of argument(s): |
| 695 | # hostname A hostname value which is to be compared to the hostname |
| 696 | # configured on system. |
| 697 | |
| 698 | ${sys_hostname}= Get BMC Hostname |
| 699 | Should Be Equal ${sys_hostname} ${hostname} |
| 700 | ... ignore_case=True msg=Hostname does not exist. |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 701 | |
| 702 | Get Channel Number For All Interface |
| 703 | [Documentation] Gets the Interface name and returns the channel number for the given interface. |
| 704 | |
| 705 | ${valid_channel_number_interface_names}= Get Channel Config |
| 706 | |
| 707 | ${valid_channel_number_interface_names}= Convert To Dictionary ${valid_channel_number_interface_names} |
| 708 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 709 | RETURN ${valid_channel_number_interface_names} |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 710 | |
| 711 | Get Valid Channel Number |
| 712 | [Documentation] Get Valid Channel Number. |
| 713 | [Arguments] ${valid_channel_number_interface_names} |
| 714 | |
Sridevi Ramesh | 8924229 | 2025-07-20 02:36:56 -0500 | [diff] [blame] | 715 | # Description of argument(s): |
| 716 | # valid_channel_number_interface_names Contains channel names in dict. |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 717 | |
| 718 | &{valid_channel_number_interface_name}= Create Dictionary |
| 719 | |
| 720 | FOR ${key} ${values} IN &{valid_channel_number_interface_names} |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 721 | IF '${values['is_valid']}' == 'True' |
| 722 | Set To Dictionary ${valid_channel_number_interface_name} ${key} ${values} |
| 723 | END |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 724 | END |
| 725 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 726 | RETURN ${valid_channel_number_interface_name} |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 727 | |
nagarjunb22 | 7fabf79 | 2022-04-19 11:09:29 +0530 | [diff] [blame] | 728 | Get Invalid Channel Number List |
| 729 | [Documentation] Get Invalid Channel and return as list. |
| 730 | |
| 731 | ${available_channels}= Get Channel Number For All Interface |
| 732 | # Get the channel which medium_type as 'reserved' and append it to a list. |
| 733 | @{invalid_channel_number_list}= Create List |
| 734 | |
| 735 | FOR ${channel_number} ${values} IN &{available_channels} |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 736 | IF '${values['channel_info']['medium_type']}' == 'reserved' |
| 737 | Append To List ${invalid_channel_number_list} ${channel_number} |
| 738 | END |
nagarjunb22 | 7fabf79 | 2022-04-19 11:09:29 +0530 | [diff] [blame] | 739 | END |
| 740 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 741 | RETURN ${invalid_channel_number_list} |
nagarjunb22 | 7fabf79 | 2022-04-19 11:09:29 +0530 | [diff] [blame] | 742 | |
| 743 | |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 744 | Get Channel Number For Valid Ethernet Interface |
| 745 | [Documentation] Get channel number for all ethernet interface. |
| 746 | [Arguments] ${valid_channel_number_interface_name} |
| 747 | |
| 748 | # Description of argument(s): |
| 749 | # channel_number_list Contains channel names in list. |
| 750 | |
| 751 | @{channel_number_list}= Create List |
| 752 | |
| 753 | FOR ${channel_number} ${values} IN &{valid_channel_number_interface_name} |
ganesanb | d9a4787 | 2022-10-26 06:50:34 +0000 | [diff] [blame] | 754 | ${usb_interface_status}= Run Keyword And Return Status Should Not Contain ${values['name']} usb |
| 755 | Continue For Loop IF ${usb_interface_status} == False |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 756 | IF '${values['channel_info']['medium_type']}' == 'lan-802.3' |
| 757 | Append To List ${channel_number_list} ${channel_number} |
| 758 | END |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 759 | END |
| 760 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 761 | RETURN ${channel_number_list} |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 762 | |
nagarjunb22 | 7fabf79 | 2022-04-19 11:09:29 +0530 | [diff] [blame] | 763 | |
| 764 | Get Current Channel Name List |
| 765 | [Documentation] Get Current Channel name and append it to active channel list. |
| 766 | [Arguments] ${channel_list} ${channel_config_json} |
| 767 | |
| 768 | # Description of Arguments |
George Keishing | 05eb71c | 2022-05-25 05:02:51 -0500 | [diff] [blame] | 769 | # ${channel_list} - list Contains all available active channels. |
nagarjunb22 | 7fabf79 | 2022-04-19 11:09:29 +0530 | [diff] [blame] | 770 | # ${channel_config_json} - output of /usr/share/ipmi-providers/channel_config.json file. |
| 771 | |
| 772 | FOR ${channel_number} ${values} IN &{channel_config_json} |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 773 | IF '${values['name']}' == 'SELF' |
| 774 | Append To List ${channel_list} ${channel_number} |
| 775 | END |
nagarjunb22 | 7fabf79 | 2022-04-19 11:09:29 +0530 | [diff] [blame] | 776 | END |
| 777 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 778 | RETURN ${channel_list} |
nagarjunb22 | 7fabf79 | 2022-04-19 11:09:29 +0530 | [diff] [blame] | 779 | |
| 780 | |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 781 | Get Active Ethernet Channel List |
nagarjunb22 | 7fabf79 | 2022-04-19 11:09:29 +0530 | [diff] [blame] | 782 | [Documentation] Get Available channels from channel_config.json file and return as list. |
| 783 | [Arguments] ${current_channel}=${0} |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 784 | |
Sridevi Ramesh | 8924229 | 2025-07-20 02:36:56 -0500 | [diff] [blame] | 785 | # Description of Arguments |
| 786 | # ${current_channel} Current channel number. |
| 787 | |
ganesanb | 0ae3620 | 2022-02-17 12:14:37 +0000 | [diff] [blame] | 788 | ${valid_channel_number_interface_names}= Get Channel Number For All Interface |
| 789 | |
| 790 | ${valid_channel_number_interface_name}= Get Valid Channel Number ${valid_channel_number_interface_names} |
| 791 | |
| 792 | ${channel_number_list}= Get Channel Number For Valid Ethernet Interface |
| 793 | ... ${valid_channel_number_interface_name} |
| 794 | |
nagarjunb22 | 7fabf79 | 2022-04-19 11:09:29 +0530 | [diff] [blame] | 795 | Return From Keyword If ${current_channel} == 0 ${channel_number_list} |
| 796 | ${channel_number_list}= Get Current Channel Name List |
| 797 | ... ${channel_number_list} ${valid_channel_number_interface_names} |
| 798 | |
George Keishing | 409df05 | 2024-01-17 22:36:14 +0530 | [diff] [blame] | 799 | RETURN ${channel_number_list} |
Sweta Potthuri | 2667f2c | 2022-10-11 07:55:21 -0500 | [diff] [blame] | 800 | |
| 801 | Update IP Address |
| 802 | [Documentation] Update and verify IP address of BMC. |
| 803 | [Arguments] ${ip} ${new_ip} ${netmask} ${gw_ip} |
| 804 | ... ${valid_status_codes}=[${HTTP_OK}, ${HTTP_NO_CONTENT}] |
| 805 | |
| 806 | # Description of argument(s): |
| 807 | # ip IP address to be replaced (e.g. "10.7.7.7"). |
| 808 | # new_ip New IP address to be configured. |
| 809 | # netmask Netmask value. |
| 810 | # gw_ip Gateway IP address. |
| 811 | # valid_status_codes Expected return code from patch operation |
| 812 | # (e.g. "200"). See prolog of rest_request |
| 813 | # method in redfish_plus.py for details. |
| 814 | |
| 815 | ${empty_dict}= Create Dictionary |
| 816 | ${patch_list}= Create List |
| 817 | ${ip_data}= Create Dictionary |
| 818 | ... Address=${new_ip} SubnetMask=${netmask} Gateway=${gw_ip} |
| 819 | |
| 820 | # Find the position of IP address to be modified. |
| 821 | @{network_configurations}= Get Network Configuration |
| 822 | FOR ${network_configuration} IN @{network_configurations} |
Anvesh-Kumar_Rayankula | f8012ac | 2025-05-23 00:11:36 -0500 | [diff] [blame] | 823 | IF '${network_configuration['Address']}' == '${ip}' |
| 824 | Append To List ${patch_list} ${ip_data} |
| 825 | ELSE |
| 826 | Append To List ${patch_list} ${empty_dict} |
| 827 | END |
Sweta Potthuri | 2667f2c | 2022-10-11 07:55:21 -0500 | [diff] [blame] | 828 | END |
| 829 | |
| 830 | # Modify the IP address only if given IP is found |
| 831 | ${ip_found}= Run Keyword And Return Status List Should Contain Value |
| 832 | ... ${patch_list} ${ip_data} msg=${ip} does not exist on BMC |
| 833 | Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC |
| 834 | |
| 835 | ${data}= Create Dictionary IPv4StaticAddresses=${patch_list} |
| 836 | |
| 837 | ${active_channel_config}= Get Active Channel Config |
| 838 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 839 | |
| 840 | Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} |
| 841 | ... body=&{data} valid_status_codes=${valid_status_codes} |
| 842 | |
| 843 | # Note: Network restart takes around 15-18s after patch request processing. |
| 844 | Sleep ${NETWORK_TIMEOUT}s |
| 845 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT} |
| 846 | |
| 847 | Verify IP On BMC ${new_ip} |
| 848 | Validate Network Config On BMC |
| 849 | |
Sweta Potthuri | 49c86a0 | 2023-10-12 07:43:13 -0500 | [diff] [blame] | 850 | Get IPv4 DHCP Enabled Status |
| 851 | [Documentation] Return IPv4 DHCP enabled status from redfish URI. |
Sweta Potthuri | 0e3f3f8 | 2023-10-19 05:30:29 -0500 | [diff] [blame] | 852 | [Arguments] ${channel_number}=${1} |
Sweta Potthuri | 49c86a0 | 2023-10-12 07:43:13 -0500 | [diff] [blame] | 853 | |
Sweta Potthuri | 0e3f3f8 | 2023-10-19 05:30:29 -0500 | [diff] [blame] | 854 | # Description of argument(s): |
| 855 | # channel_number Ethernet channel number, 1 is for eth0 and 2 is for eth1 (e.g. "1"). |
George Keishing | ee0103d | 2024-01-30 12:35:37 +0530 | [diff] [blame] | 856 | |
Sweta Potthuri | 49c86a0 | 2023-10-12 07:43:13 -0500 | [diff] [blame] | 857 | ${active_channel_config}= Get Active Channel Config |
| 858 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 859 | ${resp}= Redfish.Get Attribute ${REDFISH_NW_ETH_IFACE}${ethernet_interface} DHCPv4 |
| 860 | Return From Keyword ${resp['DHCPEnabled']} |
| 861 | |
| 862 | Get DHCP IP Info |
| 863 | [Documentation] Return DHCP IP address, gateway and subnetmask from redfish URI. |
| 864 | |
| 865 | ${active_channel_config}= Get Active Channel Config |
| 866 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 867 | ${resp_list}= Redfish.Get Attribute ${REDFISH_NW_ETH_IFACE}${ethernet_interface} IPv4Addresses |
| 868 | FOR ${resp} IN @{resp_list} |
| 869 | Continue For Loop If '${resp['AddressOrigin']}' != 'DHCP' |
| 870 | ${ip_addr}= Set Variable ${resp['Address']} |
| 871 | ${gateway}= Set Variable ${resp['Gateway']} |
| 872 | ${subnetmask}= Set Variable ${resp['SubnetMask']} |
| 873 | Return From Keyword ${ip_addr} ${gateway} ${subnetmask} |
| 874 | END |
Megha G N | b9e3c71 | 2024-01-09 04:48:43 -0600 | [diff] [blame] | 875 | |
| 876 | |
| 877 | DNS Test Setup Execution |
| 878 | [Documentation] Do DNS test setup execution. |
| 879 | |
| 880 | Redfish.Login |
| 881 | |
| 882 | ${active_channel_config}= Get Active Channel Config |
| 883 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 884 | |
| 885 | ${original_nameservers}= Redfish.Get Attribute |
| 886 | ... ${REDFISH_NW_ETH_IFACE}${ethernet_interface} StaticNameServers |
| 887 | |
| 888 | Rprint Vars original_nameservers |
| 889 | # Set suite variables to trigger restoration during teardown. |
| 890 | Set Suite Variable ${original_nameservers} |
| 891 | |
| 892 | |
| 893 | Delete Static Name Servers |
| 894 | [Documentation] Delete static name servers. |
| 895 | |
| 896 | DNS Test Setup Execution |
| 897 | Configure Static Name Servers static_name_servers=@{EMPTY} |
| 898 | |
| 899 | # Check if all name servers deleted on BMC. |
| 900 | ${nameservers}= CLI Get Nameservers |
| 901 | Should Not Contain ${nameservers} ${original_nameservers} |
| 902 | |
| 903 | DNS Test Setup Execution |
| 904 | |
| 905 | Should Be Empty ${original_nameservers} |
| 906 | |
| 907 | |
| 908 | Configure Static Name Servers |
| 909 | [Documentation] Configure DNS server on BMC. |
| 910 | [Arguments] ${static_name_servers}=${original_nameservers} |
| 911 | ... ${valid_status_codes}=${HTTP_OK} |
| 912 | |
| 913 | # Description of the argument(s): |
| 914 | # static_name_servers A list of static name server IPs to be |
| 915 | # configured on the BMC. |
Sridevi Ramesh | 8924229 | 2025-07-20 02:36:56 -0500 | [diff] [blame] | 916 | # valid_status_codes Expected return code from patch operation |
| 917 | # (e.g. "200"). See prolog of rest_request |
| 918 | # method in redfish_plus.py for details. |
Megha G N | b9e3c71 | 2024-01-09 04:48:43 -0600 | [diff] [blame] | 919 | |
| 920 | ${active_channel_config}= Get Active Channel Config |
| 921 | ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']} |
| 922 | |
| 923 | ${type} = Evaluate type($static_name_servers).__name__ |
| 924 | ${static_name_servers}= Set Variable If '${type}'=='str' |
| 925 | ... '${static_name_servers}' ${static_name_servers} |
| 926 | |
| 927 | # Currently BMC is sending 500 response code instead of 400 for invalid scenarios. |
| 928 | Redfish.Patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} |
| 929 | ... body={'StaticNameServers': ${static_name_servers}} |
| 930 | ... valid_status_codes=[${valid_status_codes}, ${HTTP_INTERNAL_SERVER_ERROR}] |
| 931 | |
| 932 | # Patch operation takes 1 to 3 seconds to set new value. |
| 933 | Sleep 3s |
| 934 | |
| 935 | # Check if newly added DNS server is configured on BMC. |
Anvesh-Kumar_Rayankula | a4beb12 | 2024-02-26 03:35:46 -0600 | [diff] [blame] | 936 | CLI Get and Verify Name Servers ${static_name_servers} ${valid_status_codes} |