blob: 7a42a229fe68e66923208aa59f92edd8fed6c977 [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
Michael Walsh1b0ceb22017-05-31 16:03:01 -050030 Run Keyword If '${mac_address.lower()}' != '${bmc_mac_addr.lower()}'
31 ... Set MAC Address
32
Michael Walsh1b0ceb22017-05-31 16:03:01 -050033
Michael Walsh1b0ceb22017-05-31 16:03:01 -050034Set MAC Address
35 [Documentation] Update eth0 with input MAC address.
36 [Arguments] ${mac_address}=${MAC_ADDRESS}
37
38 # Description of argument(s):
39 # mac_address The mac address (e.g. 00:01:6c:80:02:28).
40
Tony Lee8094d382020-04-02 13:14:47 +080041 ${active_channel_config}= Get Active Channel Config
42 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
43
Michael Walsh1b0ceb22017-05-31 16:03:01 -050044 Write fw_setenv ethaddr ${mac_address}
45 OBMC Reboot (off)
Sunil Md1c4f272017-07-07 09:03:24 -050046
47 # Take SSH session post BMC reboot.
48 Open Connection And Log In
Joy Onyerikwu9b668972018-05-22 19:10:43 -050049 ${bmc_mac_addr} ${stderr} ${rc}= BMC Execute Command
Tony Lee8094d382020-04-02 13:14:47 +080050 ... cat /sys/class/net/${ethernet_interface}/address
Michael Walsh1b0ceb22017-05-31 16:03:01 -050051 Should Be Equal ${bmc_mac_addr} ${mac_address} ignore_case=True
52
Prashanth Kattie79c5402017-06-08 07:40:49 -050053
54Get BMC IP Info
55 [Documentation] Get system IP address and prefix length.
56
Prashanth Kattie79c5402017-06-08 07:40:49 -050057
58 # Get system IP address and prefix length details using "ip addr"
59 # Sample Output of "ip addr":
60 # 1: eth0: <BROADCAST,MULTIAST> mtu 1500 qdisc mq state UP qlen 1000
61 # link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
62 # inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0
63
Tony Lee412c6682020-04-01 17:34:30 +080064 ${active_channel_config}= Get Active Channel Config
65 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
Joy Onyerikwu9b668972018-05-22 19:10:43 -050066 ${cmd_output} ${stderr} ${rc}= BMC Execute Command
Tony Lee412c6682020-04-01 17:34:30 +080067 ... /sbin/ip addr | grep ${ethernet_interface}
Prashanth Kattie79c5402017-06-08 07:40:49 -050068
69 # Get line having IP address details.
70 ${lines}= Get Lines Containing String ${cmd_output} inet
71
72 # List IP address details.
73 @{ip_components}= Split To Lines ${lines}
74
75 @{ip_data}= Create List
76
77 # Get all IP addresses and prefix lengths on system.
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -050078 FOR ${ip_component} IN @{ip_components}
79 @{if_info}= Split String ${ip_component}
80 ${ip_n_prefix}= Get From List ${if_info} 1
81 Append To List ${ip_data} ${ip_n_prefix}
82 END
Prashanth Kattie79c5402017-06-08 07:40:49 -050083
84 [Return] ${ip_data}
85
86Get BMC Route Info
87 [Documentation] Get system route info.
88
Prashanth Kattie79c5402017-06-08 07:40:49 -050089
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 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
98 [Return] ${cmd_output}
99
George Keishing02651f02018-04-11 02:07:16 -0500100# TODO: openbmc/openbmc-test-automation#1331
Prashanth Kattie79c5402017-06-08 07:40:49 -0500101Get BMC MAC Address
102 [Documentation] Get system MAC address.
103
Prashanth Kattie79c5402017-06-08 07:40:49 -0500104
105 # Sample output of "ip addr | grep ether":
106 # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff
107
Tony Lee8094d382020-04-02 13:14:47 +0800108 ${active_channel_config}= Get Active Channel Config
109 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
110
Joy Onyerikwu9b668972018-05-22 19:10:43 -0500111 ${cmd_output} ${stderr} ${rc}= BMC Execute Command
Tony Lee8094d382020-04-02 13:14:47 +0800112 ... /sbin/ip addr | grep ${ethernet_interface} -A 1 | grep ether
Prashanth Kattie79c5402017-06-08 07:40:49 -0500113
Prashanth Katti9819b162017-12-12 05:38:59 -0600114 # Split the line and return MAC address.
115 # Split list data:
116 # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
117
118 @{words}= Split String ${cmd_output}
119
120 [Return] ${words[1]}
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500121
George Keishing02651f02018-04-11 02:07:16 -0500122
123Get BMC MAC Address List
124 [Documentation] Get system MAC address
125
126 # Sample output of "ip addr | grep ether":
127 # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff
128
Joy Onyerikwu9b668972018-05-22 19:10:43 -0500129 ${cmd_output} ${stderr} ${rc}= BMC Execute Command
130 ... /sbin/ip addr | grep ether
George Keishing02651f02018-04-11 02:07:16 -0500131
132 # Split the line and return MAC address.
133 # Split list data:
134 # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
135 # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
136
137 ${mac_list}= Create List
Joy Onyerikwu9b668972018-05-22 19:10:43 -0500138 @{lines}= Split To Lines ${cmd_output}
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500139 FOR ${line} IN @{lines}
140 @{words}= Split String ${line}
141 Append To List ${mac_list} ${words[1]}
142 END
George Keishing02651f02018-04-11 02:07:16 -0500143
144 [Return] ${mac_list}
145
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500146Get BMC Hostname
147 [Documentation] Get BMC hostname.
148
Prashanth Kattic068faa2019-04-16 00:57:22 -0500149 # Sample output of "hostname":
150 # test_hostname
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500151
Prashanth Kattic068faa2019-04-16 00:57:22 -0500152 ${output} ${stderr} ${rc}= BMC Execute Command hostname
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500153
154 [Return] ${output}
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500155
shrsuman123fdc51d22020-08-18 06:51:09 -0500156Get FW_Env MAC Address
157 [Documentation] Get FW_Env MAC address.
158
159 # Sample output of "fw_printenv | grep ethaddr"
160 # ethaddr=xx:xx:xx:xx:xx:xx:xx
161
Sweta Potthuri9a77ac52021-10-04 00:30:43 -0500162 ${active_channel_config}= Get Active Channel Config
163 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
164
Sweta Potthurib461a982021-10-25 09:03:26 -0500165 ${ethernet_interface}= Set Variable If
166 ... "${ethernet_interface}"=="eth0" ethaddr eth1addr
167
168 ${cmd_output} ${stderr} ${rc}= BMC Execute Command /sbin/fw_printenv | grep ${ethernet_interface}
shrsuman123fdc51d22020-08-18 06:51:09 -0500169
170 # Split the line and return MAC address.
171 # Split list data:
172 # ethaddr | xx:xx:xx:xx:xx:xx:xx
173
174 @{words}= Split String ${cmd_output} =
175
176 [Return] ${words[1]}
177
178
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500179Get List Of IP Address Via REST
180 [Documentation] Get list of IP address via REST.
181 [Arguments] @{ip_uri_list}
182
183 # Description of argument(s):
184 # ip_uri_list List of IP objects.
185 # Example:
186 # "data": [
187 # "/xyz/openbmc_project/network/eth0/ipv4/e9767624",
188 # "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b"
189 # ],
190
191 ${ip_list}= Create List
192
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500193 FOR ${ip_uri} IN @{ip_uri_list}
194 ${ip_addr}= Read Attribute ${ip_uri} Address
195 Append To List ${ip_list} ${ip_addr}
196 END
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500197
198 [Return] @{ip_list}
199
200Delete IP And Object
201 [Documentation] Delete IP and object.
202 [Arguments] ${ip_addr} @{ip_uri_list}
203
204 # Description of argument(s):
205 # ip_addr IP address to be deleted.
206 # ip_uri_list List of IP object URIs.
207
208 # Find IP object having this IP address.
209
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500210 FOR ${ip_uri} IN @{ip_uri_list}
211 ${ip_addr1}= Read Attribute ${ip_uri} Address
212 Run Keyword If '${ip_addr}' == '${ip_addr1}' Exit For Loop
213 END
Prashanth 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}
Anves Kumar rayankula0b9efea2021-05-28 08:52:28 -0500314 ${user_mac_byte}= Run Keyword IF
315 ... ${mac_int} >= ${256} Truncate MAC Bits ${user_mac_list}[${mac_byte}]
316 ... ELSE Set Variable ${user_mac_list}[${mac_byte}]
shrsuman123fdc51d22020-08-18 06:51:09 -0500317
318 Append To List ${user_new_mac_list} ${user_mac_byte}
319 ${mac_byte} = Set Variable ${mac_byte + 1}
320 Exit For Loop If '${mac_byte}' == '${user_mac_len}'
321
322 END
323 ${user_new_mac_string}= Evaluate ":".join(${user_new_mac_list})
324 [Return] ${user_new_mac_string}
325
326Truncate MAC Bits
Anves Kumar rayankula0b9efea2021-05-28 08:52:28 -0500327 [Documentation] Truncates user provided MAC address byte to bits.
shrsuman123fdc51d22020-08-18 06:51:09 -0500328 [Arguments] ${user_mac_addr_byte}
Anves Kumar rayankula0b9efea2021-05-28 08:52:28 -0500329
shrsuman123fdc51d22020-08-18 06:51:09 -0500330 # Description of argument(s):
331 # user_mac_addr_byte user provided MAC address byte to truncate bits
332
333 ${user_mac_addr_int}= Convert To List ${user_mac_addr_byte}
334 ${user_mac_addr_byte}= Get Slice From List ${user_mac_addr_int} 0 2
335 ${user_mac_addr_byte_string}= Evaluate "".join(${user_mac_addr_byte})
336 [Return] ${user_mac_addr_byte_string}
George Keishingbf724772018-02-21 08:57:16 -0600337
Daniel Gonzalezbfd8aff2018-03-27 10:20:37 -0600338
339Run Build Net
340 [Documentation] Run build_net to preconfigure the ethernet interfaces.
341
342 OS Execute Command build_net help y y
Gunnar Mills7732c7e2018-08-14 11:54:24 -0500343 # Run pingum to check if the "build_net" was run correctly done.
Daniel Gonzalezbfd8aff2018-03-27 10:20:37 -0600344 ${output} ${stderr} ${rc}= OS Execute Command pingum
Prashanth Katti549c63a2018-07-17 06:13:37 -0500345 Should Contain ${output} All networks ping Ok
Sushil Singhf661a102019-06-04 00:52:48 -0500346
347
348Configure Hostname
349 [Documentation] Configure hostname on BMC via Redfish.
350 [Arguments] ${hostname}
351
352 # Description of argument(s):
353 # hostname A hostname value which is to be configured on BMC.
354
Anves Kumar rayankula1cc996d2021-05-31 01:14:19 -0500355 ${active_channel_config}= Get Active Channel Config
356 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
357
Sushil Singhf661a102019-06-04 00:52:48 -0500358 ${data}= Create Dictionary HostName=${hostname}
Anves Kumar rayankula1cc996d2021-05-31 01:14:19 -0500359 Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data}
George Keishing5041d6d2020-01-14 12:19:06 -0600360 ... valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
Sushil Singhf661a102019-06-04 00:52:48 -0500361
Naman Navin Hegde53691452019-07-30 00:22:37 -0500362
363Verify IP On BMC
364 [Documentation] Verify IP on BMC.
365 [Arguments] ${ip}
366
367 # Description of argument(s):
368 # ip IP address to be verified (e.g. "10.7.7.7").
369
370 # Get IP address details on BMC using IP command.
371 @{ip_data}= Get BMC IP Info
372 Should Contain Match ${ip_data} ${ip}/*
373 ... msg=IP address does not exist.
374
375
376Verify Gateway On BMC
377 [Documentation] Verify gateway on BMC.
378 [Arguments] ${gateway_ip}=0.0.0.0
379
380 # Description of argument(s):
381 # gateway_ip Gateway IP address.
382
383 ${route_info}= Get BMC Route Info
384
385 # If gateway IP is empty or 0.0.0.0 it will not have route entry.
386
387 Run Keyword If '${gateway_ip}' == '0.0.0.0'
388 ... Pass Execution Gateway IP is "0.0.0.0".
389 ... ELSE
390 ... Should Contain ${route_info} ${gateway_ip}
391 ... msg=Gateway IP address not matching.
392
393
394Get BMC DNS Info
395 [Documentation] Get system DNS info.
396
397
398 # Sample output of "resolv.conf":
399 # ### Generated manually via dbus settings ###
400 # nameserver 8.8.8.8
401
402 ${cmd_output} ${stderr} ${rc}= BMC Execute Command
403 ... cat /etc/resolv.conf
404
405 [Return] ${cmd_output}
406
407
408CLI Get Nameservers
409 [Documentation] Get the nameserver IPs from /etc/resolv.conf and return as a list.
410
411 # Example of /etc/resolv.conf data:
412 # nameserver x.x.x.x
413 # nameserver y.y.y.y
414
415 ${stdout} ${stderr} ${rc}= BMC Execute Command egrep nameserver /etc/resolv.conf | cut -f2- -d ' '
416 ${nameservers}= Split String ${stdout}
417
418 [Return] ${nameservers}
Anvesh Kumar Rayankulaada25db2020-02-19 01:29:17 -0600419
420
421Get Network Configuration
422 [Documentation] Get network configuration.
423 # Sample output:
424 #{
425 # "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
426 # "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0",
427 # "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface",
428 # "Description": "Management Network Interface",
429 # "IPv4Addresses": [
430 # {
431 # "Address": "169.254.xx.xx",
432 # "AddressOrigin": "IPv4LinkLocal",
433 # "Gateway": "0.0.0.0",
434 # "SubnetMask": "255.255.0.0"
435 # },
436 # {
437 # "Address": "xx.xx.xx.xx",
438 # "AddressOrigin": "Static",
439 # "Gateway": "xx.xx.xx.1",
440 # "SubnetMask": "xx.xx.xx.xx"
441 # }
442 # ],
443 # "Id": "eth0",
444 # "MACAddress": "xx:xx:xx:xx:xx:xx",
445 # "Name": "Manager Ethernet Interface",
446 # "SpeedMbps": 0,
447 # "VLAN": {
448 # "VLANEnable": false,
449 # "VLANId": 0
450 # }
shrsuman1237ba02f32021-08-26 04:50:56 -0500451 [Arguments] ${network_active_channel}=${CHANNEL_NUMBER}
Tony Lee412c6682020-04-01 17:34:30 +0800452
shrsuman1237ba02f32021-08-26 04:50:56 -0500453 # Description of argument(s):
454 # network_active_channel Ethernet channel number (eg. 1 or 2)
455
Tony Lee9f6b2042020-04-27 20:20:43 +0800456 ${active_channel_config}= Get Active Channel Config
shrsuman1237ba02f32021-08-26 04:50:56 -0500457 ${resp}= Redfish.Get
458 ... ${REDFISH_NW_ETH_IFACE}${active_channel_config['${network_active_channel}']['name']}
Tony Lee412c6682020-04-01 17:34:30 +0800459
Anvesh Kumar Rayankulaada25db2020-02-19 01:29:17 -0600460 @{network_configurations}= Get From Dictionary ${resp.dict} IPv4StaticAddresses
461 [Return] @{network_configurations}
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600462
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500463
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600464Add IP Address
465 [Documentation] Add IP Address To BMC.
466 [Arguments] ${ip} ${subnet_mask} ${gateway}
467 ... ${valid_status_codes}=${HTTP_OK}
468
469 # Description of argument(s):
470 # ip IP address to be added (e.g. "10.7.7.7").
471 # subnet_mask Subnet mask for the IP to be added
472 # (e.g. "255.255.0.0").
473 # gateway Gateway for the IP to be added (e.g. "10.7.7.1").
474 # valid_status_codes Expected return code from patch operation
475 # (e.g. "200"). See prolog of rest_request
476 # method in redfish_plus.py for details.
477
478 ${empty_dict}= Create Dictionary
479 ${ip_data}= Create Dictionary Address=${ip}
480 ... SubnetMask=${subnet_mask} Gateway=${gateway}
481
482 ${patch_list}= Create List
483 ${network_configurations}= Get Network Configuration
484 ${num_entries}= Get Length ${network_configurations}
485
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500486 FOR ${INDEX} IN RANGE 0 ${num_entries}
487 Append To List ${patch_list} ${empty_dict}
488 END
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600489
Anves Kumar rayankula53b80302021-05-21 01:50:03 -0500490 ${valid_status_codes}= Run Keyword If '${valid_status_codes}' == '${HTTP_OK}'
491 ... Set Variable ${HTTP_OK},${HTTP_NO_CONTENT}
492 ... ELSE Set Variable ${valid_status_codes}
493
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600494 # We need not check for existence of IP on BMC while adding.
495 Append To List ${patch_list} ${ip_data}
496 ${data}= Create Dictionary IPv4StaticAddresses=${patch_list}
497
Tony Lee412c6682020-04-01 17:34:30 +0800498 ${active_channel_config}= Get Active Channel Config
499 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
500
501 Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data}
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600502 ... valid_status_codes=[${valid_status_codes}]
503
Anves Kumar rayankula53b80302021-05-21 01:50:03 -0500504 Return From Keyword If '${valid_status_codes}' != '${HTTP_OK},${HTTP_NO_CONTENT}'
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600505
506 # Note: Network restart takes around 15-18s after patch request processing.
507 Sleep ${NETWORK_TIMEOUT}s
508 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
509
510 Verify IP On BMC ${ip}
511 Validate Network Config On BMC
512
513
514Delete IP Address
515 [Documentation] Delete IP Address Of BMC.
516 [Arguments] ${ip} ${valid_status_codes}=${HTTP_OK}
517
518 # Description of argument(s):
519 # ip IP address to be deleted (e.g. "10.7.7.7").
520 # valid_status_codes Expected return code from patch operation
521 # (e.g. "200"). See prolog of rest_request
522 # method in redfish_plus.py for details.
523
524 ${empty_dict}= Create Dictionary
525 ${patch_list}= Create List
526
527 @{network_configurations}= Get Network Configuration
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500528 FOR ${network_configuration} IN @{network_configurations}
529 Run Keyword If '${network_configuration['Address']}' == '${ip}'
530 ... Append To List ${patch_list} ${null}
531 ... ELSE Append To List ${patch_list} ${empty_dict}
532 END
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600533
534 ${ip_found}= Run Keyword And Return Status List Should Contain Value
535 ... ${patch_list} ${null} msg=${ip} does not exist on BMC
536 Pass Execution If ${ip_found} == ${False} ${ip} does not exist on BMC
537
538 # Run patch command only if given IP is found on BMC
539 ${data}= Create Dictionary IPv4StaticAddresses=${patch_list}
540
Tony Lee412c6682020-04-01 17:34:30 +0800541 ${active_channel_config}= Get Active Channel Config
542 ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
543
544 Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface} body=&{data}
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600545 ... valid_status_codes=[${valid_status_codes}]
546
547 # Note: Network restart takes around 15-18s after patch request processing
548 Sleep ${NETWORK_TIMEOUT}s
549 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
550
551 ${delete_status}= Run Keyword And Return Status Verify IP On BMC ${ip}
552 Run Keyword If '${valid_status_codes}' == '${HTTP_OK}'
553 ... Should Be True '${delete_status}' == '${False}'
554 ... ELSE Should Be True '${delete_status}' == '${True}'
555
556 Validate Network Config On BMC
557
558
559Validate Network Config On BMC
560 [Documentation] Check that network info obtained via redfish matches info
561 ... obtained via CLI.
562
563 @{network_configurations}= Get Network Configuration
564 ${ip_data}= Get BMC IP Info
Anvesh Kumar Rayankulae354c1c2020-03-09 06:01:13 -0500565 FOR ${network_configuration} IN @{network_configurations}
566 Should Contain Match ${ip_data} ${network_configuration['Address']}/*
567 ... msg=IP address does not exist.
568 END
569
570
571Create VLAN
572 [Documentation] Create a VLAN.
573 [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid
574
575 # Description of argument(s):
576 # id The VLAN ID (e.g. '53').
577 # interface The physical interface for the VLAN(e.g. 'eth0').
578 # expected_result Expected status of VLAN configuration.
579
580 @{data_vlan_id}= Create List ${interface} ${id}
581 ${data}= Create Dictionary data=@{data_vlan_id}
582 ${resp}= OpenBMC Post Request ${vlan_resource} data=${data}
583 ${resp.status_code}= Convert To String ${resp.status_code}
584 ${status}= Run Keyword And Return Status
585 ... Valid Value resp.status_code ["${HTTP_OK}"]
586
587 Run Keyword If '${expected_result}' == 'error'
588 ... Should Be Equal ${status} ${False}
589 ... msg=Configuration of an invalid VLAN ID Failed.
590 ... ELSE
591 ... Should Be Equal ${status} ${True}
592 ... msg=Configuration of a valid VLAN ID Failed.
593
594 Sleep ${NETWORK_TIMEOUT}s
595
596
597Configure Network Settings On VLAN
598 [Documentation] Configure network settings.
599 [Arguments] ${id} ${ip_addr} ${prefix_len} ${gateway_ip}=${gateway}
600 ... ${expected_result}=valid ${interface}=eth0
601
602 # Description of argument(s):
603 # id The VLAN ID (e.g. '53').
604 # ip_addr IP address of VLAN Interface.
605 # prefix_len Prefix length of VLAN Interface.
606 # gateway_ip Gateway IP address of VLAN Interface.
607 # expected_result Expected status of network setting configuration.
608 # interface Physical Interface on which the VLAN is defined.
609
610 @{ip_parm_list}= Create List ${network_resource}
611 ... ${ip_addr} ${prefix_len} ${gateway_ip}
612
613 ${data}= Create Dictionary data=@{ip_parm_list}
614
615 Run Keyword And Ignore Error OpenBMC Post Request
616 ... ${NETWORK_MANAGER}${interface}_${id}/action/IP data=${data}
617
618 # After any modification on network interface, BMC restarts network
619 # module, wait until it is reachable. Then wait 15 seconds for new
620 # configuration to be updated on BMC.
621
622 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
623 ... ${NETWORK_RETRY_TIME}
624 Sleep ${NETWORK_TIMEOUT}s
625
626 # Verify whether new IP address is populated on BMC system.
627 # It should not allow to configure invalid settings.
628 ${status}= Run Keyword And Return Status
629 ... Verify IP On BMC ${ip_addr}
630
631 Run Keyword If '${expected_result}' == 'error'
632 ... Should Be Equal ${status} ${False}
633 ... msg=Configuration of invalid IP Failed.
634 ... ELSE
635 ... Should Be Equal ${status} ${True}
636 ... msg=Configuration of valid IP Failed.
Prashanth Katti3dc8cc32020-03-04 11:11:01 -0600637
Prashanth Kattib478d902020-05-08 10:05:32 -0500638
639Get BMC Default Gateway
640 [Documentation] Get system default gateway.
641
642 ${route_info}= Get BMC Route Info
643
644 ${lines}= Get Lines Containing String ${route_info} default via
645 @{gateway_list}= Split To Lines ${lines}
646
647 # Extract first default gateway and return.
648 @{default_gw}= Split String ${gateway_list[0]}
649
650 [Return] ${default_gw[2]}
Anves Kumar rayankula55d51922021-07-01 06:37:00 -0500651
652
653Validate Hostname On BMC
654 [Documentation] Verify that the hostname read via Redfish is the same as the
655 ... hostname configured on system.
656 [Arguments] ${hostname}
657
658 # Description of argument(s):
659 # hostname A hostname value which is to be compared to the hostname
660 # configured on system.
661
662 ${sys_hostname}= Get BMC Hostname
663 Should Be Equal ${sys_hostname} ${hostname}
664 ... ignore_case=True msg=Hostname does not exist.