1*** Settings ***
2Resource                ../lib/utils.robot
3Resource                ../lib/connection_client.robot
4Resource                ../lib/boot_utils.robot
5Library                 ../lib/gen_misc.py
6Library                 ../lib/utils.py
7Library                 ../lib/bmc_network_utils.py
8
9*** Variables ***
10# MAC input from user.
11${MAC_ADDRESS}          ${EMPTY}
12
13
14*** Keywords ***
15
16Check 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
23    ${active_channel_config}=  Get Active Channel Config
24    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
25
26    Should Not Be Empty  ${mac_address}
27    Open Connection And Log In
28    ${bmc_mac_addr}  ${stderr}  ${rc}=  BMC Execute Command
29    ...  cat /sys/class/net/${ethernet_interface}/address
30    Run Keyword If  '${mac_address.lower()}' != '${bmc_mac_addr.lower()}'
31    ...  Set MAC Address
32
33
34Set 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
41    ${active_channel_config}=  Get Active Channel Config
42    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
43
44    Write  fw_setenv ethaddr ${mac_address}
45    OBMC Reboot (off)
46
47    # Take SSH session post BMC reboot.
48    Open Connection And Log In
49    ${bmc_mac_addr}  ${stderr}  ${rc}=  BMC Execute Command
50    ...  cat /sys/class/net/${ethernet_interface}/address
51    Should Be Equal  ${bmc_mac_addr}  ${mac_address}  ignore_case=True
52
53
54Get BMC IP Info
55    [Documentation]  Get system IP address and prefix length.
56
57
58    # Get system IP address and prefix length details using "ip addr"
59    # Sample Output of "ip addr":
60    # 1: eth0: <BROADCAST,MULTIAST> mtu 1500 qdisc mq state UP qlen 1000
61    #     link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
62    #     inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0
63
64    ${active_channel_config}=  Get Active Channel Config
65    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
66    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
67    ...  /sbin/ip addr | grep ${ethernet_interface}
68
69    # Get line having IP address details.
70    ${lines}=  Get Lines Containing String  ${cmd_output}  inet
71
72    # List IP address details.
73    @{ip_components}=  Split To Lines  ${lines}
74
75    @{ip_data}=  Create List
76
77    # Get all IP addresses and prefix lengths on system.
78    FOR  ${ip_component}  IN  @{ip_components}
79      @{if_info}=  Split String  ${ip_component}
80      ${ip_n_prefix}=  Get From List  ${if_info}  1
81      Append To List  ${ip_data}  ${ip_n_prefix}
82    END
83
84    [Return]  ${ip_data}
85
86Get BMC Route Info
87    [Documentation]  Get system route info.
88
89
90    # Sample output of "ip route":
91    # default via xx.xx.xx.x dev eth0
92    # xx.xx.xx.0/23 dev eth0  src xx.xx.xx.xx
93    # xx.xx.xx.0/24 dev eth0  src xx.xx.xx.xx
94
95    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
96    ...  /sbin/ip route
97
98    [Return]  ${cmd_output}
99
100# TODO: openbmc/openbmc-test-automation#1331
101Get BMC MAC Address
102    [Documentation]  Get system MAC address.
103
104
105    # Sample output of "ip addr | grep ether":
106    # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff
107
108    ${active_channel_config}=  Get Active Channel Config
109    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
110
111    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
112    ...  /sbin/ip addr | grep ${ethernet_interface} -A 1 | grep ether
113
114    # Split the line and return MAC address.
115    # Split list data:
116    # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
117
118    @{words}=  Split String  ${cmd_output}
119
120    [Return]  ${words[1]}
121
122
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
129    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
130    ...  /sbin/ip addr | grep ether
131
132    # Split the line and return MAC address.
133    # Split list data:
134    # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
135    # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
136
137    ${mac_list}=  Create List
138    @{lines}=  Split To Lines  ${cmd_output}
139    FOR  ${line}  IN  @{lines}
140      @{words}=  Split String  ${line}
141      Append To List  ${mac_list}  ${words[1]}
142    END
143
144    [Return]  ${mac_list}
145
146Get BMC Hostname
147    [Documentation]  Get BMC hostname.
148
149    # Sample output of  "hostname":
150    # test_hostname
151
152    ${output}  ${stderr}  ${rc}=  BMC Execute Command  hostname
153
154    [Return]  ${output}
155
156Get FW_Env MAC Address
157    [Documentation]  Get FW_Env MAC address.
158
159    # Sample output of "fw_printenv | grep ethaddr"
160    # ethaddr=xx:xx:xx:xx:xx:xx:xx
161
162    ${active_channel_config}=  Get Active Channel Config
163    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
164
165    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
166    ...  /sbin/fw_printenv | grep ${ethernet_interface}
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
174    [Return]  ${words[1]}
175
176
177Get 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
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
195
196    [Return]  @{ip_list}
197
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
208     FOR  ${ip_uri}  IN  @{ip_uri_list}
209       ${ip_addr1}=  Read Attribute  ${ip_uri}  Address
210       Run Keyword If  '${ip_addr}' == '${ip_addr1}'  Exit For Loop
211     END
212
213    # If the given IP address is not configured, return.
214    # Otherwise, delete the IP and object.
215
216    Run Keyword And Return If  '${ip_addr}' != '${ip_addr1}'
217    ...  Pass Execution  IP address to be deleted is not configured.
218
219    Run Keyword And Ignore Error  OpenBMC Delete Request  ${ip_uri}
220
221    # After any modification on network interface, BMC restarts network
222    # module, wait until it is reachable. Then wait 15 seconds for new
223    # configuration to be updated on BMC.
224
225    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
226    ...  ${NETWORK_RETRY_TIME}
227    Sleep  15s
228
229    # Verify whether deleted IP address is removed from BMC system.
230
231    ${ip_data}=  Get BMC IP Info
232    Should Not Contain Match  ${ip_data}  ${ip_addr}*
233    ...  msg=IP address not deleted.
234
235Get First Non Pingable IP From Subnet
236    [Documentation]  Find first non-pingable IP from the subnet and return it.
237    [Arguments]  ${host}=${OPENBMC_HOST}
238
239    # Description of argument(s):
240    # host  Any valid host name or IP address
241    #       (e.g. "machine1" or "9.xx.xx.31").
242
243    # Non-pingable IP is unused IP address in the subnet.
244    ${host_name}  ${ip_addr}=  Get Host Name IP  ${host}
245
246    # Split IP address into network part and host part.
247    # IP address will have 4 octets xx.xx.xx.xx.
248    # Sample output after split:
249    # split_ip  [xx.xx.xx, xx]
250
251    ${split_ip}=  Split String From Right  ${ip_addr}  .  1
252    # First element in list is Network part.
253    ${network_part}=  Get From List  ${split_ip}  0
254
255    FOR  ${octet4}  IN RANGE  1  255
256      ${new_ip}=  Catenate  ${network_part}.${octet4}
257      ${status}=  Run Keyword And Return Status  Ping Host  ${new_ip}
258      # If IP is non-pingable, return it.
259      Return From Keyword If  '${status}' == 'False'  ${new_ip}
260    END
261
262    Fail  msg=No non-pingable IP could be found in subnet ${network_part}.
263
264
265Validate MAC On BMC
266    [Documentation]  Validate MAC on BMC.
267    [Arguments]  ${mac_addr}
268
269    # Description of argument(s):
270    # mac_addr  MAC address of the BMC.
271
272    ${system_mac}=  Get BMC MAC Address
273    ${mac_new_addr}=  Truncate MAC Address  ${system_mac}  ${mac_addr}
274
275    ${status}=  Compare MAC Address  ${system_mac}  ${mac_new_addr}
276    Should Be True  ${status}
277    ...  msg=MAC address ${system_mac} does not match ${mac_new_addr}.
278
279Validate MAC On FW_Env
280    [Documentation]  Validate MAC on FW_Env.
281    [Arguments]  ${mac_addr}
282
283    # Description of argument(s):
284    # mac_addr  MAC address of the BMC.
285
286    ${fw_env_addr}=  Get FW_Env MAC Address
287    ${mac_new_addr}=  Truncate MAC Address  ${fw_env_addr}  ${mac_addr}
288
289    ${status}=  Compare MAC Address  ${fw_env_addr}  ${mac_new_addr}
290    Should Be True  ${status}
291    ...  msg=MAC address ${fw_env_addr} does not match ${mac_new_addr}.
292
293Truncate MAC Address
294    [Documentation]  Truncates and returns user provided MAC address.
295    [Arguments]    ${sys_mac_addr}  ${user_mac_addr}
296
297    # Description of argument(s):
298    # sys_mac_addr  MAC address of the BMC.
299    # user_mac_addr user provided MAC address.
300
301    ${mac_byte}=  Set Variable  ${0}
302    @{user_mac_list}=  Split String  ${user_mac_addr}  :
303    @{sys_mac_list}=  Split String  ${sys_mac_addr}  :
304    ${user_new_mac_list}  Create List
305
306    # Truncate extra bytes and bits from MAC address
307    FOR  ${mac_item}  IN  @{sys_mac_list}
308        ${invalid_mac_byte} =  Get Regexp Matches  ${user_mac_list}[${mac_byte}]  [^A-Za-z0-9]+
309        Return From Keyword If  ${invalid_mac_byte}  ${user_mac_addr}
310        ${mac_int} =    Convert To Integer      ${user_mac_list}[${mac_byte}]   16
311        ${user_mac_len} =  Get Length  ${user_mac_list}
312        ${user_mac_byte}=  Run Keyword IF
313        ...  ${mac_int} >= ${256}  Truncate MAC Bits  ${user_mac_list}[${mac_byte}]
314        ...  ELSE  Set Variable  ${user_mac_list}[${mac_byte}]
315
316        Append To List  ${user_new_mac_list}  ${user_mac_byte}
317        ${mac_byte} =    Set Variable    ${mac_byte + 1}
318        Exit For Loop If  '${mac_byte}' == '${user_mac_len}'
319
320    END
321    ${user_new_mac_string}=   Evaluate  ":".join(${user_new_mac_list})
322    [Return]  ${user_new_mac_string}
323
324Truncate MAC Bits
325    [Documentation]  Truncates user provided MAC address byte to bits.
326    [Arguments]    ${user_mac_addr_byte}
327
328    # Description of argument(s):
329    # user_mac_addr_byte user provided MAC address byte to truncate bits
330
331    ${user_mac_addr_int}=   Convert To List  ${user_mac_addr_byte}
332    ${user_mac_addr_byte}=  Get Slice From List  ${user_mac_addr_int}  0  2
333    ${user_mac_addr_byte_string}=  Evaluate  "".join(${user_mac_addr_byte})
334    [Return]  ${user_mac_addr_byte_string}
335
336
337Run Build Net
338    [Documentation]  Run build_net to preconfigure the ethernet interfaces.
339
340    OS Execute Command  build_net help y y
341    # Run pingum to check if the "build_net" was run correctly done.
342    ${output}  ${stderr}  ${rc}=  OS Execute Command  pingum
343    Should Contain  ${output}  All networks ping Ok
344
345
346Configure Hostname
347    [Documentation]  Configure hostname on BMC via Redfish.
348    [Arguments]  ${hostname}
349
350    # Description of argument(s):
351    # hostname  A hostname value which is to be configured on BMC.
352
353    ${active_channel_config}=  Get Active Channel Config
354    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
355
356    ${data}=  Create Dictionary  HostName=${hostname}
357    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{data}
358    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
359
360
361Verify IP On BMC
362    [Documentation]  Verify IP on BMC.
363    [Arguments]  ${ip}
364
365    # Description of argument(s):
366    # ip  IP address to be verified (e.g. "10.7.7.7").
367
368    # Get IP address details on BMC using IP command.
369    @{ip_data}=  Get BMC IP Info
370    Should Contain Match  ${ip_data}  ${ip}/*
371    ...  msg=IP address does not exist.
372
373
374Verify Gateway On BMC
375    [Documentation]  Verify gateway on BMC.
376    [Arguments]  ${gateway_ip}=0.0.0.0
377
378    # Description of argument(s):
379    # gateway_ip  Gateway IP address.
380
381    ${route_info}=  Get BMC Route Info
382
383    # If gateway IP is empty or 0.0.0.0 it will not have route entry.
384
385    Run Keyword If  '${gateway_ip}' == '0.0.0.0'
386    ...      Pass Execution  Gateway IP is "0.0.0.0".
387    ...  ELSE
388    ...      Should Contain  ${route_info}  ${gateway_ip}
389    ...      msg=Gateway IP address not matching.
390
391
392Get BMC DNS Info
393    [Documentation]  Get system DNS info.
394
395
396    # Sample output of "resolv.conf":
397    # ### Generated manually via dbus settings ###
398    # nameserver 8.8.8.8
399
400    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
401    ...  cat /etc/resolv.conf
402
403    [Return]  ${cmd_output}
404
405
406CLI Get Nameservers
407    [Documentation]  Get the nameserver IPs from /etc/resolv.conf and return as a list.
408
409    # Example of /etc/resolv.conf data:
410    # nameserver x.x.x.x
411    # nameserver y.y.y.y
412
413    ${stdout}  ${stderr}  ${rc}=  BMC Execute Command  egrep nameserver /etc/resolv.conf | cut -f2- -d ' '
414    ${nameservers}=  Split String  ${stdout}
415
416    [Return]  ${nameservers}
417
418
419Get Network Configuration
420    [Documentation]  Get network configuration.
421    # Sample output:
422    #{
423    #  "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
424    #  "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0",
425    #  "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface",
426    #  "Description": "Management Network Interface",
427    #  "IPv4Addresses": [
428    #    {
429    #      "Address": "169.254.xx.xx",
430    #      "AddressOrigin": "IPv4LinkLocal",
431    #      "Gateway": "0.0.0.0",
432    #      "SubnetMask": "255.255.0.0"
433    #    },
434    #    {
435    #      "Address": "xx.xx.xx.xx",
436    #      "AddressOrigin": "Static",
437    #      "Gateway": "xx.xx.xx.1",
438    #      "SubnetMask": "xx.xx.xx.xx"
439    #    }
440    #  ],
441    #  "Id": "eth0",
442    #  "MACAddress": "xx:xx:xx:xx:xx:xx",
443    #  "Name": "Manager Ethernet Interface",
444    #  "SpeedMbps": 0,
445    #  "VLAN": {
446    #    "VLANEnable": false,
447    #    "VLANId": 0
448    #  }
449    [Arguments]  ${network_active_channel}=${CHANNEL_NUMBER}
450
451    # Description of argument(s):
452    # network_active_channel   Ethernet channel number (eg. 1 or 2)
453
454    ${active_channel_config}=  Get Active Channel Config
455    ${resp}=  Redfish.Get
456    ...  ${REDFISH_NW_ETH_IFACE}${active_channel_config['${network_active_channel}']['name']}
457
458    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4StaticAddresses
459    [Return]  @{network_configurations}
460
461
462Add IP Address
463    [Documentation]  Add IP Address To BMC.
464    [Arguments]  ${ip}  ${subnet_mask}  ${gateway}
465    ...  ${valid_status_codes}=${HTTP_OK}
466
467    # Description of argument(s):
468    # ip                  IP address to be added (e.g. "10.7.7.7").
469    # subnet_mask         Subnet mask for the IP to be added
470    #                     (e.g. "255.255.0.0").
471    # gateway             Gateway for the IP to be added (e.g. "10.7.7.1").
472    # valid_status_codes  Expected return code from patch operation
473    #                     (e.g. "200").  See prolog of rest_request
474    #                     method in redfish_plus.py for details.
475
476    ${empty_dict}=  Create Dictionary
477    ${ip_data}=  Create Dictionary  Address=${ip}
478    ...  SubnetMask=${subnet_mask}  Gateway=${gateway}
479
480    ${patch_list}=  Create List
481    ${network_configurations}=  Get Network Configuration
482    ${num_entries}=  Get Length  ${network_configurations}
483
484    FOR  ${INDEX}  IN RANGE  0  ${num_entries}
485      Append To List  ${patch_list}  ${empty_dict}
486    END
487
488    ${valid_status_codes}=  Run Keyword If  '${valid_status_codes}' == '${HTTP_OK}'
489    ...  Set Variable   ${HTTP_OK},${HTTP_NO_CONTENT}
490    ...  ELSE  Set Variable  ${valid_status_codes}
491
492    # We need not check for existence of IP on BMC while adding.
493    Append To List  ${patch_list}  ${ip_data}
494    ${data}=  Create Dictionary  IPv4StaticAddresses=${patch_list}
495
496    ${active_channel_config}=  Get Active Channel Config
497    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
498
499    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{data}
500    ...  valid_status_codes=[${valid_status_codes}]
501
502    Return From Keyword If  '${valid_status_codes}' != '${HTTP_OK},${HTTP_NO_CONTENT}'
503
504    # Note: Network restart takes around 15-18s after patch request processing.
505    Sleep  ${NETWORK_TIMEOUT}s
506    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
507
508    Verify IP On BMC  ${ip}
509    Validate Network Config On BMC
510
511
512Delete IP Address
513    [Documentation]  Delete IP Address Of BMC.
514    [Arguments]  ${ip}  ${valid_status_codes}=${HTTP_OK}
515
516    # Description of argument(s):
517    # ip                  IP address to be deleted (e.g. "10.7.7.7").
518    # valid_status_codes  Expected return code from patch operation
519    #                     (e.g. "200").  See prolog of rest_request
520    #                     method in redfish_plus.py for details.
521
522    ${empty_dict}=  Create Dictionary
523    ${patch_list}=  Create List
524
525    @{network_configurations}=  Get Network Configuration
526    FOR  ${network_configuration}  IN  @{network_configurations}
527      Run Keyword If  '${network_configuration['Address']}' == '${ip}'
528      ...  Append To List  ${patch_list}  ${null}
529      ...  ELSE  Append To List  ${patch_list}  ${empty_dict}
530    END
531
532    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
533    ...  ${patch_list}  ${null}  msg=${ip} does not exist on BMC
534    Pass Execution If  ${ip_found} == ${False}  ${ip} does not exist on BMC
535
536    # Run patch command only if given IP is found on BMC
537    ${data}=  Create Dictionary  IPv4StaticAddresses=${patch_list}
538
539    ${active_channel_config}=  Get Active Channel Config
540    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
541
542    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{data}
543    ...  valid_status_codes=[${valid_status_codes}]
544
545    # Note: Network restart takes around 15-18s after patch request processing
546    Sleep  ${NETWORK_TIMEOUT}s
547    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
548
549    ${delete_status}=  Run Keyword And Return Status  Verify IP On BMC  ${ip}
550    Run Keyword If  '${valid_status_codes}' == '${HTTP_OK}'
551    ...  Should Be True  '${delete_status}' == '${False}'
552    ...  ELSE  Should Be True  '${delete_status}' == '${True}'
553
554    Validate Network Config On BMC
555
556
557Validate Network Config On BMC
558    [Documentation]  Check that network info obtained via redfish matches info
559    ...              obtained via CLI.
560
561    @{network_configurations}=  Get Network Configuration
562    ${ip_data}=  Get BMC IP Info
563    FOR  ${network_configuration}  IN  @{network_configurations}
564      Should Contain Match  ${ip_data}  ${network_configuration['Address']}/*
565      ...  msg=IP address does not exist.
566    END
567
568
569Create VLAN
570    [Documentation]  Create a VLAN.
571    [Arguments]  ${id}  ${interface}=eth0  ${expected_result}=valid
572
573    # Description of argument(s):
574    # id  The VLAN ID (e.g. '53').
575    # interface  The physical interface for the VLAN(e.g. 'eth0').
576    # expected_result  Expected status of VLAN configuration.
577
578    @{data_vlan_id}=  Create List  ${interface}  ${id}
579    ${data}=  Create Dictionary   data=@{data_vlan_id}
580    ${resp}=  OpenBMC Post Request  ${vlan_resource}  data=${data}
581    ${resp.status_code}=  Convert To String  ${resp.status_code}
582    ${status}=  Run Keyword And Return Status
583    ...  Valid Value  resp.status_code  ["${HTTP_OK}"]
584
585    Run Keyword If  '${expected_result}' == 'error'
586    ...      Should Be Equal  ${status}  ${False}
587    ...      msg=Configuration of an invalid VLAN ID Failed.
588    ...  ELSE
589    ...      Should Be Equal  ${status}  ${True}
590    ...      msg=Configuration of a valid VLAN ID Failed.
591
592    Sleep  ${NETWORK_TIMEOUT}s
593
594
595Configure Network Settings On VLAN
596    [Documentation]  Configure network settings.
597    [Arguments]  ${id}  ${ip_addr}  ${prefix_len}  ${gateway_ip}=${gateway}
598    ...  ${expected_result}=valid  ${interface}=eth0
599
600    # Description of argument(s):
601    # id               The VLAN ID (e.g. '53').
602    # ip_addr          IP address of VLAN Interface.
603    # prefix_len       Prefix length of VLAN Interface.
604    # gateway_ip       Gateway IP address of VLAN Interface.
605    # expected_result  Expected status of network setting configuration.
606    # interface        Physical Interface on which the VLAN is defined.
607
608    @{ip_parm_list}=  Create List  ${network_resource}
609    ...  ${ip_addr}  ${prefix_len}  ${gateway_ip}
610
611    ${data}=  Create Dictionary  data=@{ip_parm_list}
612
613    Run Keyword And Ignore Error  OpenBMC Post Request
614    ...  ${NETWORK_MANAGER}${interface}_${id}/action/IP  data=${data}
615
616    # After any modification on network interface, BMC restarts network
617    # module, wait until it is reachable. Then wait 15 seconds for new
618    # configuration to be updated on BMC.
619
620    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
621    ...  ${NETWORK_RETRY_TIME}
622    Sleep  ${NETWORK_TIMEOUT}s
623
624    # Verify whether new IP address is populated on BMC system.
625    # It should not allow to configure invalid settings.
626    ${status}=  Run Keyword And Return Status
627    ...  Verify IP On BMC  ${ip_addr}
628
629    Run Keyword If  '${expected_result}' == 'error'
630    ...      Should Be Equal  ${status}  ${False}
631    ...      msg=Configuration of invalid IP Failed.
632    ...  ELSE
633    ...      Should Be Equal  ${status}  ${True}
634    ...      msg=Configuration of valid IP Failed.
635
636
637Get BMC Default Gateway
638    [Documentation]  Get system default gateway.
639
640    ${route_info}=  Get BMC Route Info
641
642    ${lines}=  Get Lines Containing String  ${route_info}  default via
643    @{gateway_list}=  Split To Lines  ${lines}
644
645    # Extract first default gateway and return.
646    @{default_gw}=  Split String  ${gateway_list[0]}
647
648    [Return]  ${default_gw[2]}
649
650
651Validate Hostname On BMC
652    [Documentation]  Verify that the hostname read via Redfish is the same as the
653    ...  hostname configured on system.
654    [Arguments]  ${hostname}
655
656    # Description of argument(s):
657    # hostname  A hostname value which is to be compared to the hostname
658    #           configured on system.
659
660    ${sys_hostname}=  Get BMC Hostname
661    Should Be Equal  ${sys_hostname}  ${hostname}
662    ...  ignore_case=True  msg=Hostname does not exist.
663