blob: 3ecf2f66a5996876e9316dc78013c837ed77da70 [file] [log] [blame]
Michael Walsh1b0ceb22017-05-31 16:03:01 -05001*** Settings ***
2Resource ../lib/utils.robot
3Resource ../lib/connection_client.robot
4Resource ../lib/boot_utils.robot
George Keishing58e47232018-02-12 10:35:15 -06005Library ../lib/gen_misc.py
George Keishingbf724772018-02-21 08:57:16 -06006Library ../lib/utils.py
Tony Lee9f6b2042020-04-27 20:20:43 +08007Library ../lib/bmc_network_utils.py
Michael Walsh1b0ceb22017-05-31 16:03:01 -05008
9*** Variables ***
10# MAC input from user.
11${MAC_ADDRESS} ${EMPTY}
12
13
14*** Keywords ***
15
Michael Walsh1b0ceb22017-05-31 16:03:01 -050016Check 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 Lee8094d382020-04-02 13:14:47 +080023 ${active_channel_config}= Get Active Channel Config
24 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
25
Michael Walsh1b0ceb22017-05-31 16:03:01 -050026 Should Not Be Empty ${mac_address}
27 Open Connection And Log In
Joy Onyerikwu9b668972018-05-22 19:10:43 -050028 ${bmc_mac_addr} ${stderr} ${rc}= BMC Execute Command
Tony Lee8094d382020-04-02 13:14:47 +080029 ... cat /sys/class/net/${ethernet_interface}/address
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -050030 IF '${mac_address.lower()}' != '${bmc_mac_addr.lower()}'
31 Set MAC Address
32 END
Michael Walsh1b0ceb22017-05-31 16:03:01 -050033
Michael Walsh1b0ceb22017-05-31 16:03:01 -050034
Michael Walsh1b0ceb22017-05-31 16:03:01 -050035Set 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 Lee8094d382020-04-02 13:14:47 +080042 ${active_channel_config}= Get Active Channel Config
43 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
44
Michael Walsh1b0ceb22017-05-31 16:03:01 -050045 Write fw_setenv ethaddr ${mac_address}
46 OBMC Reboot (off)
Sunil Md1c4f272017-07-07 09:03:24 -050047
48 # Take SSH session post BMC reboot.
49 Open Connection And Log In
Joy Onyerikwu9b668972018-05-22 19:10:43 -050050 ${bmc_mac_addr} ${stderr} ${rc}= BMC Execute Command
Tony Lee8094d382020-04-02 13:14:47 +080051 ... cat /sys/class/net/${ethernet_interface}/address
Michael Walsh1b0ceb22017-05-31 16:03:01 -050052 Should Be Equal ${bmc_mac_addr} ${mac_address} ignore_case=True
53
Prashanth Kattie79c5402017-06-08 07:40:49 -050054
55Get BMC IP Info
56 [Documentation] Get system IP address and prefix length.
57
Prashanth Kattie79c5402017-06-08 07:40:49 -050058
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 Lee412c6682020-04-01 17:34:30 +080065 ${active_channel_config}= Get Active Channel Config
66 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
Joy Onyerikwu9b668972018-05-22 19:10:43 -050067 ${cmd_output} ${stderr} ${rc}= BMC Execute Command
Tony Lee412c6682020-04-01 17:34:30 +080068 ... /sbin/ip addr | grep ${ethernet_interface}
Prashanth Kattie79c5402017-06-08 07:40:49 -050069
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 Rayankulae354c1c2020-03-09 06:01:13 -050079 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 Kattie79c5402017-06-08 07:40:49 -050084
George Keishing409df052024-01-17 22:36:14 +053085 RETURN ${ip_data}
Prashanth Kattie79c5402017-06-08 07:40:49 -050086
87Get BMC Route Info
88 [Documentation] Get system route info.
89
Prashanth Kattie79c5402017-06-08 07:40:49 -050090 # 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 Onyerikwu9b668972018-05-22 19:10:43 -050095 ${cmd_output} ${stderr} ${rc}= BMC Execute Command
96 ... /sbin/ip route
Prashanth Kattie79c5402017-06-08 07:40:49 -050097
George Keishing409df052024-01-17 22:36:14 +053098 RETURN ${cmd_output}
Prashanth Kattie79c5402017-06-08 07:40:49 -050099
100Get BMC MAC Address
101 [Documentation] Get system MAC address.
102
Prashanth Kattie79c5402017-06-08 07:40:49 -0500103 # 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 Lee8094d382020-04-02 13:14:47 +0800106 ${active_channel_config}= Get Active Channel Config
107 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
108
Joy Onyerikwu9b668972018-05-22 19:10:43 -0500109 ${cmd_output} ${stderr} ${rc}= BMC Execute Command
Tony Lee8094d382020-04-02 13:14:47 +0800110 ... /sbin/ip addr | grep ${ethernet_interface} -A 1 | grep ether
Prashanth Kattie79c5402017-06-08 07:40:49 -0500111
Prashanth Katti9819b162017-12-12 05:38:59 -0600112 # 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 Keishing409df052024-01-17 22:36:14 +0530118 RETURN ${words[1]}
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500119
George Keishing02651f02018-04-11 02:07:16 -0500120
121Get 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 Onyerikwu9b668972018-05-22 19:10:43 -0500127 ${cmd_output} ${stderr} ${rc}= BMC Execute Command
128 ... /sbin/ip addr | grep ether
George Keishing02651f02018-04-11 02:07:16 -0500129
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 Onyerikwu9b668972018-05-22 19:10:43 -0500136 @{lines}= Split To Lines ${cmd_output}
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500137 FOR ${line} IN @{lines}
138 @{words}= Split String ${line}
139 Append To List ${mac_list} ${words[1]}
140 END
George Keishing02651f02018-04-11 02:07:16 -0500141
George Keishing409df052024-01-17 22:36:14 +0530142 RETURN ${mac_list}
George Keishing02651f02018-04-11 02:07:16 -0500143
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500144Get BMC Hostname
145 [Documentation] Get BMC hostname.
146
Prashanth Kattic068faa2019-04-16 00:57:22 -0500147 # Sample output of "hostname":
148 # test_hostname
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500149
Prashanth Kattic068faa2019-04-16 00:57:22 -0500150 ${output} ${stderr} ${rc}= BMC Execute Command hostname
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500151
George Keishing409df052024-01-17 22:36:14 +0530152 RETURN ${output}
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500153
shrsuman123fdc51d22020-08-18 06:51:09 -0500154Get 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 Potthuri9a77ac52021-10-04 00:30:43 -0500160 ${active_channel_config}= Get Active Channel Config
161 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
162
Sweta Potthurib461a982021-10-25 09:03:26 -0500163 ${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}
shrsuman123fdc51d22020-08-18 06:51:09 -0500167
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 Keishing409df052024-01-17 22:36:14 +0530174 RETURN ${words[1]}
shrsuman123fdc51d22020-08-18 06:51:09 -0500175
176
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500177Get 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 Rayankulae354c1c2020-03-09 06:01:13 -0500191 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 Katti90f9ff22017-08-11 06:17:12 -0500195
George Keishing409df052024-01-17 22:36:14 +0530196 RETURN @{ip_list}
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500197
198Delete 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 Rayankulae354c1c2020-03-09 06:01:13 -0500208 FOR ${ip_uri} IN @{ip_uri_list}
209 ${ip_addr1}= Read Attribute ${ip_uri} Address
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500210 IF '${ip_addr}' == '${ip_addr1}'
211 Exit For Loop
212 END
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500213 END
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500214
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 Katti549c63a2018-07-17 06:13:37 -0500224 # module, wait until it is reachable. Then wait 15 seconds for new
225 # configuration to be updated on BMC.
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500226
Prashanth Katti549c63a2018-07-17 06:13:37 -0500227 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
228 ... ${NETWORK_RETRY_TIME}
229 Sleep 15s
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500230
231 # Verify whether deleted IP address is removed from BMC system.
232
233 ${ip_data}= Get BMC IP Info
Prashanth Katti160faf62017-09-07 01:05:56 -0500234 Should Not Contain Match ${ip_data} ${ip_addr}*
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500235 ... msg=IP address not deleted.
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600236
George Keishing58e47232018-02-12 10:35:15 -0600237Get 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 Kattidf2e4fdf2018-02-07 07:04:13 -0600240
241 # Description of argument(s):
George Keishing58e47232018-02-12 10:35:15 -0600242 # host Any valid host name or IP address
243 # (e.g. "machine1" or "9.xx.xx.31").
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600244
George Keishing58e47232018-02-12 10:35:15 -0600245 # Non-pingable IP is unused IP address in the subnet.
shrsuman1237ba02f32021-08-26 04:50:56 -0500246 ${host_name} ${ip_addr}= Get Host Name IP ${host}
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600247
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 Rayankulae354c1c2020-03-09 06:01:13 -0500257 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 Kattidf2e4fdf2018-02-07 07:04:13 -0600263
George Keishing58e47232018-02-12 10:35:15 -0600264 Fail msg=No non-pingable IP could be found in subnet ${network_part}.
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600265
George Keishingbf724772018-02-21 08:57:16 -0600266
267Validate 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
shrsuman123fdc51d22020-08-18 06:51:09 -0500275 ${mac_new_addr}= Truncate MAC Address ${system_mac} ${mac_addr}
George Keishingbf724772018-02-21 08:57:16 -0600276
shrsuman123fdc51d22020-08-18 06:51:09 -0500277 ${status}= Compare MAC Address ${system_mac} ${mac_new_addr}
George Keishingbf724772018-02-21 08:57:16 -0600278 Should Be True ${status}
shrsuman123fdc51d22020-08-18 06:51:09 -0500279 ... msg=MAC address ${system_mac} does not match ${mac_new_addr}.
280
281Validate 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
295Truncate MAC Address
Anves Kumar rayankula0b9efea2021-05-28 08:52:28 -0500296 [Documentation] Truncates and returns user provided MAC address.
shrsuman123fdc51d22020-08-18 06:51:09 -0500297 [Arguments] ${sys_mac_addr} ${user_mac_addr}
Anves Kumar rayankula0b9efea2021-05-28 08:52:28 -0500298
shrsuman123fdc51d22020-08-18 06:51:09 -0500299 # 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_Rayankulaf8012ac2025-05-23 00:11:36 -0500314 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
shrsuman123fdc51d22020-08-18 06:51:09 -0500319 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 Keishing409df052024-01-17 22:36:14 +0530325 RETURN ${user_new_mac_string}
shrsuman123fdc51d22020-08-18 06:51:09 -0500326
327Truncate MAC Bits
Anves Kumar rayankula0b9efea2021-05-28 08:52:28 -0500328 [Documentation] Truncates user provided MAC address byte to bits.
shrsuman123fdc51d22020-08-18 06:51:09 -0500329 [Arguments] ${user_mac_addr_byte}
Anves Kumar rayankula0b9efea2021-05-28 08:52:28 -0500330
shrsuman123fdc51d22020-08-18 06:51:09 -0500331 # 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 Keishing409df052024-01-17 22:36:14 +0530337 RETURN ${user_mac_addr_byte_string}
George Keishingbf724772018-02-21 08:57:16 -0600338
Daniel Gonzalezbfd8aff2018-03-27 10:20:37 -0600339
340Run Build Net
341 [Documentation] Run build_net to preconfigure the ethernet interfaces.
342
343 OS Execute Command build_net help y y
Gunnar Mills7732c7e2018-08-14 11:54:24 -0500344 # Run pingum to check if the "build_net" was run correctly done.
Daniel Gonzalezbfd8aff2018-03-27 10:20:37 -0600345 ${output} ${stderr} ${rc}= OS Execute Command pingum
Prashanth Katti549c63a2018-07-17 06:13:37 -0500346 Should Contain ${output} All networks ping Ok
Sushil Singhf661a102019-06-04 00:52:48 -0500347
348
349Configure Hostname
350 [Documentation] Configure hostname on BMC via Redfish.
Sushil Singh44bfc202023-02-08 09:53:36 -0600351 [Arguments] ${hostname} ${status_code}=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sushil Singhf661a102019-06-04 00:52:48 -0500352
353 # Description of argument(s):
354 # hostname A hostname value which is to be configured on BMC.
355
Anves Kumar rayankula1cc996d2021-05-31 01:14:19 -0500356 ${active_channel_config}= Get Active Channel Config
357 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
358
Sushil Singhf661a102019-06-04 00:52:48 -0500359 ${data}= Create Dictionary HostName=${hostname}
Anves Kumar rayankula1cc996d2021-05-31 01:14:19 -0500360 Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data}
Sushil Singh44bfc202023-02-08 09:53:36 -0600361 ... valid_status_codes=${status_code}
Sushil Singhf661a102019-06-04 00:52:48 -0500362
Naman Navin Hegde53691452019-07-30 00:22:37 -0500363
364Verify IP On BMC
365 [Documentation] Verify IP on BMC.
366 [Arguments] ${ip}
367
368 # Description of argument(s):
369 # ip IP address to be verified (e.g. "10.7.7.7").
370
371 # Get IP address details on BMC using IP command.
372 @{ip_data}= Get BMC IP Info
373 Should Contain Match ${ip_data} ${ip}/*
374 ... msg=IP address does not exist.
375
376
377Verify Gateway On BMC
378 [Documentation] Verify gateway on BMC.
379 [Arguments] ${gateway_ip}=0.0.0.0
380
381 # Description of argument(s):
382 # gateway_ip Gateway IP address.
383
384 ${route_info}= Get BMC Route Info
385
386 # If gateway IP is empty or 0.0.0.0 it will not have route entry.
387
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500388 IF '${gateway_ip}' == '0.0.0.0'
389 Pass Execution Gateway IP is "0.0.0.0".
390 ELSE
391 Should Contain ${route_info} ${gateway_ip} msg=Gateway IP address not matching.
392 END
Naman Navin Hegde53691452019-07-30 00:22:37 -0500393
394
395Get BMC DNS Info
396 [Documentation] Get system DNS info.
397
398
399 # Sample output of "resolv.conf":
400 # ### Generated manually via dbus settings ###
401 # nameserver 8.8.8.8
402
403 ${cmd_output} ${stderr} ${rc}= BMC Execute Command
404 ... cat /etc/resolv.conf
405
George Keishing409df052024-01-17 22:36:14 +0530406 RETURN ${cmd_output}
Naman Navin Hegde53691452019-07-30 00:22:37 -0500407
408
409CLI Get Nameservers
410 [Documentation] Get the nameserver IPs from /etc/resolv.conf and return as a list.
411
412 # Example of /etc/resolv.conf data:
413 # nameserver x.x.x.x
414 # nameserver y.y.y.y
415
Sweta Potthuridc325932022-06-15 12:51:27 -0500416 ${stdout} ${stderr} ${rc}= BMC Execute Command
417 ... egrep nameserver /etc/resolv.conf | cut -f2- -d ' '
Naman Navin Hegde53691452019-07-30 00:22:37 -0500418 ${nameservers}= Split String ${stdout}
419
George Keishing409df052024-01-17 22:36:14 +0530420 RETURN ${nameservers}
Anvesh Kumar Rayankulaada25db2020-02-19 01:29:17 -0600421
kothais878f4f92023-11-02 11:43:37 +0000422CLI Get and Verify Name Servers
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500423 [Documentation] Get and Verify the nameserver IPs from /etc/resolv.conf
424 ... and compare with redfish nameserver.
kothais878f4f92023-11-02 11:43:37 +0000425 [Arguments] ${static_name_servers}
426 ... ${valid_status_codes}=${HTTP_OK}
427
428 # Description of Argument(s):
429 # static_name_servers: Address for static name server
430
431 ${cli_nameservers}= CLI Get Nameservers
432 ${cmd_status}= Run Keyword And Return Status
433 ... List Should Contain Sub List ${cli_nameservers} ${static_name_servers}
434
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500435 IF '${valid_status_codes}' == '${HTTP_OK}'
436 Should Be True ${cmd_status}
437 ELSE
438 Should Not Be True ${cmd_status}
439 END
Anvesh Kumar Rayankulaada25db2020-02-19 01:29:17 -0600440
441Get Network Configuration
442 [Documentation] Get network configuration.
443 # Sample output:
444 #{
445 # "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
ganesanb4d430282023-04-27 14:33:23 +0000446 # "@odata.id": "/redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/eth0",
Anvesh Kumar Rayankulaada25db2020-02-19 01:29:17 -0600447 # "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface",
448 # "Description": "Management Network Interface",
449 # "IPv4Addresses": [
450 # {
451 # "Address": "169.254.xx.xx",
452 # "AddressOrigin": "IPv4LinkLocal",
453 # "Gateway": "0.0.0.0",
454 # "SubnetMask": "255.255.0.0"
455 # },
456 # {
457 # "Address": "xx.xx.xx.xx",
458 # "AddressOrigin": "Static",
459 # "Gateway": "xx.xx.xx.1",
460 # "SubnetMask": "xx.xx.xx.xx"
461 # }
462 # ],
463 # "Id": "eth0",
464 # "MACAddress": "xx:xx:xx:xx:xx:xx",
465 # "Name": "Manager Ethernet Interface",
466 # "SpeedMbps": 0,
467 # "VLAN": {
468 # "VLANEnable": false,
469 # "VLANId": 0
470 # }
shrsuman1237ba02f32021-08-26 04:50:56 -0500471 [Arguments] ${network_active_channel}=${CHANNEL_NUMBER}
Tony Lee412c6682020-04-01 17:34:30 +0800472
shrsuman1237ba02f32021-08-26 04:50:56 -0500473 # Description of argument(s):
474 # network_active_channel Ethernet channel number (eg. 1 or 2)
George Keishing33be3592022-03-08 08:52:25 -0600475
Tony Lee9f6b2042020-04-27 20:20:43 +0800476 ${active_channel_config}= Get Active Channel Config
shrsuman1237ba02f32021-08-26 04:50:56 -0500477 ${resp}= Redfish.Get
478 ... ${REDFISH_NW_ETH_IFACE}${active_channel_config['${network_active_channel}']['name']}
Tony Lee412c6682020-04-01 17:34:30 +0800479
Anvesh Kumar Rayankulaada25db2020-02-19 01:29:17 -0600480 @{network_configurations}= Get From Dictionary ${resp.dict} IPv4StaticAddresses
George Keishing409df052024-01-17 22:36:14 +0530481 RETURN @{network_configurations}
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600482
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500483
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600484Add IP Address
485 [Documentation] Add IP Address To BMC.
486 [Arguments] ${ip} ${subnet_mask} ${gateway}
487 ... ${valid_status_codes}=${HTTP_OK}
488
489 # Description of argument(s):
490 # ip IP address to be added (e.g. "10.7.7.7").
491 # subnet_mask Subnet mask for the IP to be added
492 # (e.g. "255.255.0.0").
493 # gateway Gateway for the IP to be added (e.g. "10.7.7.1").
494 # valid_status_codes Expected return code from patch operation
495 # (e.g. "200"). See prolog of rest_request
496 # method in redfish_plus.py for details.
497
498 ${empty_dict}= Create Dictionary
499 ${ip_data}= Create Dictionary Address=${ip}
500 ... SubnetMask=${subnet_mask} Gateway=${gateway}
501
502 ${patch_list}= Create List
503 ${network_configurations}= Get Network Configuration
504 ${num_entries}= Get Length ${network_configurations}
505
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500506 FOR ${INDEX} IN RANGE 0 ${num_entries}
507 Append To List ${patch_list} ${empty_dict}
508 END
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600509
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500510 ${valid_status_codes}= Set Variable If '${valid_status_codes}' == '${HTTP_OK}'
511 ... ${HTTP_OK},${HTTP_NO_CONTENT} ${valid_status_codes}
Anves Kumar rayankula53b80302021-05-21 01:50:03 -0500512
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600513 # We need not check for existence of IP on BMC while adding.
514 Append To List ${patch_list} ${ip_data}
515 ${data}= Create Dictionary IPv4StaticAddresses=${patch_list}
516
Tony Lee412c6682020-04-01 17:34:30 +0800517 ${active_channel_config}= Get Active Channel Config
518 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
519
520 Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data}
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600521 ... valid_status_codes=[${valid_status_codes}]
522
Anves Kumar rayankula53b80302021-05-21 01:50:03 -0500523 Return From Keyword If '${valid_status_codes}' != '${HTTP_OK},${HTTP_NO_CONTENT}'
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600524
525 # Note: Network restart takes around 15-18s after patch request processing.
526 Sleep ${NETWORK_TIMEOUT}s
527 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
528
529 Verify IP On BMC ${ip}
530 Validate Network Config On BMC
531
532
533Delete IP Address
534 [Documentation] Delete IP Address Of BMC.
Sweta Potthuric9649ca2025-05-07 00:48:43 -0500535 [Arguments] ${ip} ${valid_status_codes}=[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}]
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600536
537 # Description of argument(s):
538 # ip IP address to be deleted (e.g. "10.7.7.7").
539 # valid_status_codes Expected return code from patch operation
540 # (e.g. "200"). See prolog of rest_request
541 # method in redfish_plus.py for details.
542
543 ${empty_dict}= Create Dictionary
544 ${patch_list}= Create List
545
546 @{network_configurations}= Get Network Configuration
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500547 FOR ${network_configuration} IN @{network_configurations}
548 Run Keyword If '${network_configuration['Address']}' == '${ip}'
549 ... Append To List ${patch_list} ${null}
550 ... ELSE Append To List ${patch_list} ${empty_dict}
551 END
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600552
553 ${ip_found}= Run Keyword And Return Status List Should Contain Value
554 ... ${patch_list} ${null} msg=${ip} does not exist on BMC
555 Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC
556
557 # Run patch command only if given IP is found on BMC
558 ${data}= Create Dictionary IPv4StaticAddresses=${patch_list}
559
Tony Lee412c6682020-04-01 17:34:30 +0800560 ${active_channel_config}= Get Active Channel Config
561 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
562
563 Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data}
Sweta Potthuric9649ca2025-05-07 00:48:43 -0500564 ... valid_status_codes=${valid_status_codes}
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600565
566 # Note: Network restart takes around 15-18s after patch request processing
567 Sleep ${NETWORK_TIMEOUT}s
568 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
569
570 ${delete_status}= Run Keyword And Return Status Verify IP On BMC ${ip}
Sweta Potthuric9649ca2025-05-07 00:48:43 -0500571 IF '${valid_status_codes}' == '[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}]'
572 Should Be True '${delete_status}' == '${False}'
573 ELSE
574 Should Be True '${delete_status}' == '${True}'
575 END
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600576
577 Validate Network Config On BMC
578
579
580Validate Network Config On BMC
581 [Documentation] Check that network info obtained via redfish matches info
582 ... obtained via CLI.
583
584 @{network_configurations}= Get Network Configuration
585 ${ip_data}= Get BMC IP Info
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500586 FOR ${network_configuration} IN @{network_configurations}
587 Should Contain Match ${ip_data} ${network_configuration['Address']}/*
588 ... msg=IP address does not exist.
589 END
590
591
592Create VLAN
593 [Documentation] Create a VLAN.
594 [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid
595
596 # Description of argument(s):
597 # id The VLAN ID (e.g. '53').
598 # interface The physical interface for the VLAN(e.g. 'eth0').
599 # expected_result Expected status of VLAN configuration.
600
601 @{data_vlan_id}= Create List ${interface} ${id}
602 ${data}= Create Dictionary data=@{data_vlan_id}
603 ${resp}= OpenBMC Post Request ${vlan_resource} data=${data}
604 ${resp.status_code}= Convert To String ${resp.status_code}
605 ${status}= Run Keyword And Return Status
606 ... Valid Value resp.status_code ["${HTTP_OK}"]
607
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500608 IF '${expected_result}' == 'error'
609 Should Be Equal ${status} ${False} msg=Configuration of an invalid VLAN ID Failed.
610 ELSE
611 Should Be Equal ${status} ${True} msg=Configuration of a valid VLAN ID Failed.
612 END
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500613
614 Sleep ${NETWORK_TIMEOUT}s
615
616
617Configure Network Settings On VLAN
618 [Documentation] Configure network settings.
619 [Arguments] ${id} ${ip_addr} ${prefix_len} ${gateway_ip}=${gateway}
620 ... ${expected_result}=valid ${interface}=eth0
621
622 # Description of argument(s):
623 # id The VLAN ID (e.g. '53').
624 # ip_addr IP address of VLAN Interface.
625 # prefix_len Prefix length of VLAN Interface.
626 # gateway_ip Gateway IP address of VLAN Interface.
627 # expected_result Expected status of network setting configuration.
628 # interface Physical Interface on which the VLAN is defined.
629
630 @{ip_parm_list}= Create List ${network_resource}
631 ... ${ip_addr} ${prefix_len} ${gateway_ip}
632
633 ${data}= Create Dictionary data=@{ip_parm_list}
634
635 Run Keyword And Ignore Error OpenBMC Post Request
636 ... ${NETWORK_MANAGER}${interface}_${id}/action/IP data=${data}
637
638 # After any modification on network interface, BMC restarts network
639 # module, wait until it is reachable. Then wait 15 seconds for new
640 # configuration to be updated on BMC.
641
642 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
643 ... ${NETWORK_RETRY_TIME}
644 Sleep ${NETWORK_TIMEOUT}s
645
646 # Verify whether new IP address is populated on BMC system.
647 # It should not allow to configure invalid settings.
648 ${status}= Run Keyword And Return Status
649 ... Verify IP On BMC ${ip_addr}
650
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500651 IF '${expected_result}' == 'error'
652 Should Be Equal ${status} ${False} msg=Configuration of invalid IP Failed.
653 ELSE
654 Should Be Equal ${status} ${True} msg=Configuration of valid IP Failed.
655 END
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600656
Prashanth Kattib478d902020-05-08 10:05:32 -0500657
658Get BMC Default Gateway
659 [Documentation] Get system default gateway.
660
661 ${route_info}= Get BMC Route Info
662
663 ${lines}= Get Lines Containing String ${route_info} default via
Prashanth Kattib478d902020-05-08 10:05:32 -0500664
Sweta Potthuri811021d2022-08-08 11:28:05 -0500665 ${active_channel_config}= Get Active Channel Config
666 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
667
668 # Extract the corresponding default gateway for eth0 and eth1
669 ${default_gw_line}= Get Lines Containing String ${lines} ${ethernet_interface}
670 ${default_gw}= Split String ${default_gw_line}
671
672 # Example of the output
673 # default_gw:
674 # [0]: default
675 # [1]: via
676 # [2]: xx.xx.xx.1
677 # [3]: dev
678 # [4]: eth1
Prashanth Kattib478d902020-05-08 10:05:32 -0500679
George Keishing409df052024-01-17 22:36:14 +0530680 RETURN ${default_gw[2]}
Anves Kumar rayankula55d51922021-07-01 06:37:00 -0500681
682
683Validate Hostname On BMC
684 [Documentation] Verify that the hostname read via Redfish is the same as the
685 ... hostname configured on system.
686 [Arguments] ${hostname}
687
688 # Description of argument(s):
689 # hostname A hostname value which is to be compared to the hostname
690 # configured on system.
691
692 ${sys_hostname}= Get BMC Hostname
693 Should Be Equal ${sys_hostname} ${hostname}
694 ... ignore_case=True msg=Hostname does not exist.
ganesanb0ae36202022-02-17 12:14:37 +0000695
696Get Channel Number For All Interface
697 [Documentation] Gets the Interface name and returns the channel number for the given interface.
698
699 ${valid_channel_number_interface_names}= Get Channel Config
700
701 ${valid_channel_number_interface_names}= Convert To Dictionary ${valid_channel_number_interface_names}
702
George Keishing409df052024-01-17 22:36:14 +0530703 RETURN ${valid_channel_number_interface_names}
ganesanb0ae36202022-02-17 12:14:37 +0000704
705Get Valid Channel Number
706 [Documentation] Get Valid Channel Number.
707 [Arguments] ${valid_channel_number_interface_names}
708
709 #Description of argument(s):
710 #valid_channel_number_interface_names Contains channel names in dict.
711
712 &{valid_channel_number_interface_name}= Create Dictionary
713
714 FOR ${key} ${values} IN &{valid_channel_number_interface_names}
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500715 IF '${values['is_valid']}' == 'True'
716 Set To Dictionary ${valid_channel_number_interface_name} ${key} ${values}
717 END
ganesanb0ae36202022-02-17 12:14:37 +0000718 END
719
George Keishing409df052024-01-17 22:36:14 +0530720 RETURN ${valid_channel_number_interface_name}
ganesanb0ae36202022-02-17 12:14:37 +0000721
nagarjunb227fabf792022-04-19 11:09:29 +0530722Get Invalid Channel Number List
723 [Documentation] Get Invalid Channel and return as list.
724
725 ${available_channels}= Get Channel Number For All Interface
726 # Get the channel which medium_type as 'reserved' and append it to a list.
727 @{invalid_channel_number_list}= Create List
728
729 FOR ${channel_number} ${values} IN &{available_channels}
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500730 IF '${values['channel_info']['medium_type']}' == 'reserved'
731 Append To List ${invalid_channel_number_list} ${channel_number}
732 END
nagarjunb227fabf792022-04-19 11:09:29 +0530733 END
734
George Keishing409df052024-01-17 22:36:14 +0530735 RETURN ${invalid_channel_number_list}
nagarjunb227fabf792022-04-19 11:09:29 +0530736
737
ganesanb0ae36202022-02-17 12:14:37 +0000738Get Channel Number For Valid Ethernet Interface
739 [Documentation] Get channel number for all ethernet interface.
740 [Arguments] ${valid_channel_number_interface_name}
741
742 # Description of argument(s):
743 # channel_number_list Contains channel names in list.
744
745 @{channel_number_list}= Create List
746
747 FOR ${channel_number} ${values} IN &{valid_channel_number_interface_name}
ganesanbd9a47872022-10-26 06:50:34 +0000748 ${usb_interface_status}= Run Keyword And Return Status Should Not Contain ${values['name']} usb
749 Continue For Loop IF ${usb_interface_status} == False
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500750 IF '${values['channel_info']['medium_type']}' == 'lan-802.3'
751 Append To List ${channel_number_list} ${channel_number}
752 END
ganesanb0ae36202022-02-17 12:14:37 +0000753 END
754
George Keishing409df052024-01-17 22:36:14 +0530755 RETURN ${channel_number_list}
ganesanb0ae36202022-02-17 12:14:37 +0000756
nagarjunb227fabf792022-04-19 11:09:29 +0530757
758Get Current Channel Name List
759 [Documentation] Get Current Channel name and append it to active channel list.
760 [Arguments] ${channel_list} ${channel_config_json}
761
762 # Description of Arguments
George Keishing05eb71c2022-05-25 05:02:51 -0500763 # ${channel_list} - list Contains all available active channels.
nagarjunb227fabf792022-04-19 11:09:29 +0530764 # ${channel_config_json} - output of /usr/share/ipmi-providers/channel_config.json file.
765
766 FOR ${channel_number} ${values} IN &{channel_config_json}
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500767 IF '${values['name']}' == 'SELF'
768 Append To List ${channel_list} ${channel_number}
769 END
nagarjunb227fabf792022-04-19 11:09:29 +0530770 END
771
George Keishing409df052024-01-17 22:36:14 +0530772 RETURN ${channel_list}
nagarjunb227fabf792022-04-19 11:09:29 +0530773
774
ganesanb0ae36202022-02-17 12:14:37 +0000775Get Active Ethernet Channel List
nagarjunb227fabf792022-04-19 11:09:29 +0530776 [Documentation] Get Available channels from channel_config.json file and return as list.
777 [Arguments] ${current_channel}=${0}
ganesanb0ae36202022-02-17 12:14:37 +0000778
779 ${valid_channel_number_interface_names}= Get Channel Number For All Interface
780
781 ${valid_channel_number_interface_name}= Get Valid Channel Number ${valid_channel_number_interface_names}
782
783 ${channel_number_list}= Get Channel Number For Valid Ethernet Interface
784 ... ${valid_channel_number_interface_name}
785
nagarjunb227fabf792022-04-19 11:09:29 +0530786 Return From Keyword If ${current_channel} == 0 ${channel_number_list}
787 ${channel_number_list}= Get Current Channel Name List
788 ... ${channel_number_list} ${valid_channel_number_interface_names}
789
George Keishing409df052024-01-17 22:36:14 +0530790 RETURN ${channel_number_list}
Sweta Potthuri2667f2c2022-10-11 07:55:21 -0500791
792Update IP Address
793 [Documentation] Update and verify IP address of BMC.
794 [Arguments] ${ip} ${new_ip} ${netmask} ${gw_ip}
795 ... ${valid_status_codes}=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
796
797 # Description of argument(s):
798 # ip IP address to be replaced (e.g. "10.7.7.7").
799 # new_ip New IP address to be configured.
800 # netmask Netmask value.
801 # gw_ip Gateway IP address.
802 # valid_status_codes Expected return code from patch operation
803 # (e.g. "200"). See prolog of rest_request
804 # method in redfish_plus.py for details.
805
806 ${empty_dict}= Create Dictionary
807 ${patch_list}= Create List
808 ${ip_data}= Create Dictionary
809 ... Address=${new_ip} SubnetMask=${netmask} Gateway=${gw_ip}
810
811 # Find the position of IP address to be modified.
812 @{network_configurations}= Get Network Configuration
813 FOR ${network_configuration} IN @{network_configurations}
Anvesh-Kumar_Rayankulaf8012ac2025-05-23 00:11:36 -0500814 IF '${network_configuration['Address']}' == '${ip}'
815 Append To List ${patch_list} ${ip_data}
816 ELSE
817 Append To List ${patch_list} ${empty_dict}
818 END
Sweta Potthuri2667f2c2022-10-11 07:55:21 -0500819 END
820
821 # Modify the IP address only if given IP is found
822 ${ip_found}= Run Keyword And Return Status List Should Contain Value
823 ... ${patch_list} ${ip_data} msg=${ip} does not exist on BMC
824 Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC
825
826 ${data}= Create Dictionary IPv4StaticAddresses=${patch_list}
827
828 ${active_channel_config}= Get Active Channel Config
829 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
830
831 Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
832 ... body=&{data} valid_status_codes=${valid_status_codes}
833
834 # Note: Network restart takes around 15-18s after patch request processing.
835 Sleep ${NETWORK_TIMEOUT}s
836 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
837
838 Verify IP On BMC ${new_ip}
839 Validate Network Config On BMC
840
Sweta Potthuri49c86a02023-10-12 07:43:13 -0500841Get IPv4 DHCP Enabled Status
842 [Documentation] Return IPv4 DHCP enabled status from redfish URI.
Sweta Potthuri0e3f3f82023-10-19 05:30:29 -0500843 [Arguments] ${channel_number}=${1}
Sweta Potthuri49c86a02023-10-12 07:43:13 -0500844
Sweta Potthuri0e3f3f82023-10-19 05:30:29 -0500845 # Description of argument(s):
846 # channel_number Ethernet channel number, 1 is for eth0 and 2 is for eth1 (e.g. "1").
George Keishingee0103d2024-01-30 12:35:37 +0530847
Sweta Potthuri49c86a02023-10-12 07:43:13 -0500848 ${active_channel_config}= Get Active Channel Config
849 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
850 ${resp}= Redfish.Get Attribute ${REDFISH_NW_ETH_IFACE}${ethernet_interface} DHCPv4
851 Return From Keyword ${resp['DHCPEnabled']}
852
853Get DHCP IP Info
854 [Documentation] Return DHCP IP address, gateway and subnetmask from redfish URI.
855
856 ${active_channel_config}= Get Active Channel Config
857 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
858 ${resp_list}= Redfish.Get Attribute ${REDFISH_NW_ETH_IFACE}${ethernet_interface} IPv4Addresses
859 FOR ${resp} IN @{resp_list}
860 Continue For Loop If '${resp['AddressOrigin']}' != 'DHCP'
861 ${ip_addr}= Set Variable ${resp['Address']}
862 ${gateway}= Set Variable ${resp['Gateway']}
863 ${subnetmask}= Set Variable ${resp['SubnetMask']}
864 Return From Keyword ${ip_addr} ${gateway} ${subnetmask}
865 END
Megha G Nb9e3c712024-01-09 04:48:43 -0600866
867
868DNS Test Setup Execution
869 [Documentation] Do DNS test setup execution.
870
871 Redfish.Login
872
873 ${active_channel_config}= Get Active Channel Config
874 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
875
876 ${original_nameservers}= Redfish.Get Attribute
877 ... ${REDFISH_NW_ETH_IFACE}${ethernet_interface} StaticNameServers
878
879 Rprint Vars original_nameservers
880 # Set suite variables to trigger restoration during teardown.
881 Set Suite Variable ${original_nameservers}
882
883
884Delete Static Name Servers
885 [Documentation] Delete static name servers.
886
887 DNS Test Setup Execution
888 Configure Static Name Servers static_name_servers=@{EMPTY}
889
890 # Check if all name servers deleted on BMC.
891 ${nameservers}= CLI Get Nameservers
892 Should Not Contain ${nameservers} ${original_nameservers}
893
894 DNS Test Setup Execution
895
896 Should Be Empty ${original_nameservers}
897
898
899Configure Static Name Servers
900 [Documentation] Configure DNS server on BMC.
901 [Arguments] ${static_name_servers}=${original_nameservers}
902 ... ${valid_status_codes}=${HTTP_OK}
903
904 # Description of the argument(s):
905 # static_name_servers A list of static name server IPs to be
906 # configured on the BMC.
907
908 ${active_channel_config}= Get Active Channel Config
909 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
910
911 ${type} = Evaluate type($static_name_servers).__name__
912 ${static_name_servers}= Set Variable If '${type}'=='str'
913 ... '${static_name_servers}' ${static_name_servers}
914
915 # Currently BMC is sending 500 response code instead of 400 for invalid scenarios.
916 Redfish.Patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
917 ... body={'StaticNameServers': ${static_name_servers}}
918 ... valid_status_codes=[${valid_status_codes}, ${HTTP_INTERNAL_SERVER_ERROR}]
919
920 # Patch operation takes 1 to 3 seconds to set new value.
921 Sleep 3s
922
923 # Check if newly added DNS server is configured on BMC.
Anvesh-Kumar_Rayankulaa4beb122024-02-26 03:35:46 -0600924 CLI Get and Verify Name Servers ${static_name_servers} ${valid_status_codes}