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    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
163    ...  /sbin/fw_printenv | grep ethaddr
164
165    # Split the line and return MAC address.
166    # Split list data:
167    # ethaddr | xx:xx:xx:xx:xx:xx:xx
168
169    @{words}=  Split String  ${cmd_output}  =
170
171    [Return]  ${words[1]}
172
173
174Get List Of IP Address Via REST
175    [Documentation]  Get list of IP address via REST.
176    [Arguments]  @{ip_uri_list}
177
178    # Description of argument(s):
179    # ip_uri_list  List of IP objects.
180    # Example:
181    #   "data": [
182    #     "/xyz/openbmc_project/network/eth0/ipv4/e9767624",
183    #     "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b"
184    #   ],
185
186    ${ip_list}=  Create List
187
188    FOR  ${ip_uri}  IN  @{ip_uri_list}
189      ${ip_addr}=  Read Attribute  ${ip_uri}  Address
190      Append To List  ${ip_list}  ${ip_addr}
191    END
192
193    [Return]  @{ip_list}
194
195Delete IP And Object
196    [Documentation]  Delete IP and object.
197    [Arguments]  ${ip_addr}  @{ip_uri_list}
198
199    # Description of argument(s):
200    # ip_addr      IP address to be deleted.
201    # ip_uri_list  List of IP object URIs.
202
203    # Find IP object having this IP address.
204
205     FOR  ${ip_uri}  IN  @{ip_uri_list}
206       ${ip_addr1}=  Read Attribute  ${ip_uri}  Address
207       Run Keyword If  '${ip_addr}' == '${ip_addr1}'  Exit For Loop
208     END
209
210    # If the given IP address is not configured, return.
211    # Otherwise, delete the IP and object.
212
213    Run Keyword And Return If  '${ip_addr}' != '${ip_addr1}'
214    ...  Pass Execution  IP address to be deleted is not configured.
215
216    Run Keyword And Ignore Error  OpenBMC Delete Request  ${ip_uri}
217
218    # After any modification on network interface, BMC restarts network
219    # module, wait until it is reachable. Then wait 15 seconds for new
220    # configuration to be updated on BMC.
221
222    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
223    ...  ${NETWORK_RETRY_TIME}
224    Sleep  15s
225
226    # Verify whether deleted IP address is removed from BMC system.
227
228    ${ip_data}=  Get BMC IP Info
229    Should Not Contain Match  ${ip_data}  ${ip_addr}*
230    ...  msg=IP address not deleted.
231
232Get First Non Pingable IP From Subnet
233    [Documentation]  Find first non-pingable IP from the subnet and return it.
234    [Arguments]  ${host}=${OPENBMC_HOST}
235
236    # Description of argument(s):
237    # host  Any valid host name or IP address
238    #       (e.g. "machine1" or "9.xx.xx.31").
239
240    # Non-pingable IP is unused IP address in the subnet.
241    ${host_name}  ${ip_addr}=  Get Host Name IP
242
243    # Split IP address into network part and host part.
244    # IP address will have 4 octets xx.xx.xx.xx.
245    # Sample output after split:
246    # split_ip  [xx.xx.xx, xx]
247
248    ${split_ip}=  Split String From Right  ${ip_addr}  .  1
249    # First element in list is Network part.
250    ${network_part}=  Get From List  ${split_ip}  0
251
252    FOR  ${octet4}  IN RANGE  1  255
253      ${new_ip}=  Catenate  ${network_part}.${octet4}
254      ${status}=  Run Keyword And Return Status  Ping Host  ${new_ip}
255      # If IP is non-pingable, return it.
256      Return From Keyword If  '${status}' == 'False'  ${new_ip}
257    END
258
259    Fail  msg=No non-pingable IP could be found in subnet ${network_part}.
260
261
262Validate MAC On BMC
263    [Documentation]  Validate MAC on BMC.
264    [Arguments]  ${mac_addr}
265
266    # Description of argument(s):
267    # mac_addr  MAC address of the BMC.
268
269    ${system_mac}=  Get BMC MAC Address
270    ${mac_new_addr}=  Truncate MAC Address  ${system_mac}  ${mac_addr}
271
272    ${status}=  Compare MAC Address  ${system_mac}  ${mac_new_addr}
273    Should Be True  ${status}
274    ...  msg=MAC address ${system_mac} does not match ${mac_new_addr}.
275
276Validate MAC On FW_Env
277    [Documentation]  Validate MAC on FW_Env.
278    [Arguments]  ${mac_addr}
279
280    # Description of argument(s):
281    # mac_addr  MAC address of the BMC.
282
283    ${fw_env_addr}=  Get FW_Env MAC Address
284    ${mac_new_addr}=  Truncate MAC Address  ${fw_env_addr}  ${mac_addr}
285
286    ${status}=  Compare MAC Address  ${fw_env_addr}  ${mac_new_addr}
287    Should Be True  ${status}
288    ...  msg=MAC address ${fw_env_addr} does not match ${mac_new_addr}.
289
290Truncate MAC Address
291    [Arguments]    ${sys_mac_addr}  ${user_mac_addr}
292    # Description of argument(s):
293    # sys_mac_addr  MAC address of the BMC.
294    # user_mac_addr user provided MAC address.
295
296    ${mac_byte}=  Set Variable  ${0}
297    @{user_mac_list}=  Split String  ${user_mac_addr}  :
298    @{sys_mac_list}=  Split String  ${sys_mac_addr}  :
299    ${user_new_mac_list}  Create List
300
301    # Truncate extra bytes and bits from MAC address
302    FOR  ${mac_item}  IN  @{sys_mac_list}
303        ${invalid_mac_byte} =  Get Regexp Matches  ${user_mac_list}[${mac_byte}]  [^A-Za-z0-9]+
304        Return From Keyword If  ${invalid_mac_byte}  ${user_mac_addr}
305        ${mac_int} =    Convert To Integer      ${user_mac_list}[${mac_byte}]   16
306        ${user_mac_len} =  Get Length  ${user_mac_list}
307        ${user_mac_byte}=  Run Keyword IF  ${mac_int} >= ${256}  Truncate MAC Bits  ${user_mac_list}[${mac_byte}]
308                                      ...  ELSE  Set Variable  ${user_mac_list}[${mac_byte}]
309
310        Append To List  ${user_new_mac_list}  ${user_mac_byte}
311        ${mac_byte} =    Set Variable    ${mac_byte + 1}
312        Exit For Loop If  '${mac_byte}' == '${user_mac_len}'
313
314    END
315    ${user_new_mac_string}=   Evaluate  ":".join(${user_new_mac_list})
316    [Return]  ${user_new_mac_string}
317
318Truncate MAC Bits
319    [Arguments]    ${user_mac_addr_byte}
320    # Description of argument(s):
321    # user_mac_addr_byte user provided MAC address byte to truncate bits
322
323    ${user_mac_addr_int}=   Convert To List  ${user_mac_addr_byte}
324    ${user_mac_addr_byte}=  Get Slice From List  ${user_mac_addr_int}  0  2
325    ${user_mac_addr_byte_string}=  Evaluate  "".join(${user_mac_addr_byte})
326    [Return]  ${user_mac_addr_byte_string}
327
328
329Run Build Net
330    [Documentation]  Run build_net to preconfigure the ethernet interfaces.
331
332    OS Execute Command  build_net help y y
333    # Run pingum to check if the "build_net" was run correctly done.
334    ${output}  ${stderr}  ${rc}=  OS Execute Command  pingum
335    Should Contain  ${output}  All networks ping Ok
336
337
338Configure Hostname
339    [Documentation]  Configure hostname on BMC via Redfish.
340    [Arguments]  ${hostname}
341
342    # Description of argument(s):
343    # hostname  A hostname value which is to be configured on BMC.
344
345    ${data}=  Create Dictionary  HostName=${hostname}
346    Redfish.patch  ${REDFISH_NW_PROTOCOL_URI}  body=&{data}
347    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
348
349
350Verify IP On BMC
351    [Documentation]  Verify IP on BMC.
352    [Arguments]  ${ip}
353
354    # Description of argument(s):
355    # ip  IP address to be verified (e.g. "10.7.7.7").
356
357    # Get IP address details on BMC using IP command.
358    @{ip_data}=  Get BMC IP Info
359    Should Contain Match  ${ip_data}  ${ip}/*
360    ...  msg=IP address does not exist.
361
362
363Verify Gateway On BMC
364    [Documentation]  Verify gateway on BMC.
365    [Arguments]  ${gateway_ip}=0.0.0.0
366
367    # Description of argument(s):
368    # gateway_ip  Gateway IP address.
369
370    ${route_info}=  Get BMC Route Info
371
372    # If gateway IP is empty or 0.0.0.0 it will not have route entry.
373
374    Run Keyword If  '${gateway_ip}' == '0.0.0.0'
375    ...      Pass Execution  Gateway IP is "0.0.0.0".
376    ...  ELSE
377    ...      Should Contain  ${route_info}  ${gateway_ip}
378    ...      msg=Gateway IP address not matching.
379
380
381Get BMC DNS Info
382    [Documentation]  Get system DNS info.
383
384
385    # Sample output of "resolv.conf":
386    # ### Generated manually via dbus settings ###
387    # nameserver 8.8.8.8
388
389    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
390    ...  cat /etc/resolv.conf
391
392    [Return]  ${cmd_output}
393
394
395CLI Get Nameservers
396    [Documentation]  Get the nameserver IPs from /etc/resolv.conf and return as a list.
397
398    # Example of /etc/resolv.conf data:
399    # nameserver x.x.x.x
400    # nameserver y.y.y.y
401
402    ${stdout}  ${stderr}  ${rc}=  BMC Execute Command  egrep nameserver /etc/resolv.conf | cut -f2- -d ' '
403    ${nameservers}=  Split String  ${stdout}
404
405    [Return]  ${nameservers}
406
407
408Get Network Configuration
409    [Documentation]  Get network configuration.
410    # Sample output:
411    #{
412    #  "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
413    #  "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0",
414    #  "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface",
415    #  "Description": "Management Network Interface",
416    #  "IPv4Addresses": [
417    #    {
418    #      "Address": "169.254.xx.xx",
419    #      "AddressOrigin": "IPv4LinkLocal",
420    #      "Gateway": "0.0.0.0",
421    #      "SubnetMask": "255.255.0.0"
422    #    },
423    #    {
424    #      "Address": "xx.xx.xx.xx",
425    #      "AddressOrigin": "Static",
426    #      "Gateway": "xx.xx.xx.1",
427    #      "SubnetMask": "xx.xx.xx.xx"
428    #    }
429    #  ],
430    #  "Id": "eth0",
431    #  "MACAddress": "xx:xx:xx:xx:xx:xx",
432    #  "Name": "Manager Ethernet Interface",
433    #  "SpeedMbps": 0,
434    #  "VLAN": {
435    #    "VLANEnable": false,
436    #    "VLANId": 0
437    #  }
438
439
440    ${active_channel_config}=  Get Active Channel Config
441    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${active_channel_config['${CHANNEL_NUMBER}']['name']}
442
443    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4StaticAddresses
444    [Return]  @{network_configurations}
445
446
447Add IP Address
448    [Documentation]  Add IP Address To BMC.
449    [Arguments]  ${ip}  ${subnet_mask}  ${gateway}
450    ...  ${valid_status_codes}=${HTTP_OK}
451
452    # Description of argument(s):
453    # ip                  IP address to be added (e.g. "10.7.7.7").
454    # subnet_mask         Subnet mask for the IP to be added
455    #                     (e.g. "255.255.0.0").
456    # gateway             Gateway for the IP to be added (e.g. "10.7.7.1").
457    # valid_status_codes  Expected return code from patch operation
458    #                     (e.g. "200").  See prolog of rest_request
459    #                     method in redfish_plus.py for details.
460
461    ${empty_dict}=  Create Dictionary
462    ${ip_data}=  Create Dictionary  Address=${ip}
463    ...  SubnetMask=${subnet_mask}  Gateway=${gateway}
464
465    ${patch_list}=  Create List
466    ${network_configurations}=  Get Network Configuration
467    ${num_entries}=  Get Length  ${network_configurations}
468
469    FOR  ${INDEX}  IN RANGE  0  ${num_entries}
470      Append To List  ${patch_list}  ${empty_dict}
471    END
472
473    # We need not check for existence of IP on BMC while adding.
474    Append To List  ${patch_list}  ${ip_data}
475    ${data}=  Create Dictionary  IPv4StaticAddresses=${patch_list}
476
477    ${active_channel_config}=  Get Active Channel Config
478    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
479
480    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{data}
481    ...  valid_status_codes=[${valid_status_codes}]
482
483    Return From Keyword If  '${valid_status_codes}' != '${HTTP_OK}'
484
485    # Note: Network restart takes around 15-18s after patch request processing.
486    Sleep  ${NETWORK_TIMEOUT}s
487    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
488
489    Verify IP On BMC  ${ip}
490    Validate Network Config On BMC
491
492
493Delete IP Address
494    [Documentation]  Delete IP Address Of BMC.
495    [Arguments]  ${ip}  ${valid_status_codes}=${HTTP_OK}
496
497    # Description of argument(s):
498    # ip                  IP address to be deleted (e.g. "10.7.7.7").
499    # valid_status_codes  Expected return code from patch operation
500    #                     (e.g. "200").  See prolog of rest_request
501    #                     method in redfish_plus.py for details.
502
503    ${empty_dict}=  Create Dictionary
504    ${patch_list}=  Create List
505
506    @{network_configurations}=  Get Network Configuration
507    FOR  ${network_configuration}  IN  @{network_configurations}
508      Run Keyword If  '${network_configuration['Address']}' == '${ip}'
509      ...  Append To List  ${patch_list}  ${null}
510      ...  ELSE  Append To List  ${patch_list}  ${empty_dict}
511    END
512
513    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
514    ...  ${patch_list}  ${null}  msg=${ip} does not exist on BMC
515    Pass Execution If  ${ip_found} == ${False}  ${ip} does not exist on BMC
516
517    # Run patch command only if given IP is found on BMC
518    ${data}=  Create Dictionary  IPv4StaticAddresses=${patch_list}
519
520    ${active_channel_config}=  Get Active Channel Config
521    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
522
523    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{data}
524    ...  valid_status_codes=[${valid_status_codes}]
525
526    # Note: Network restart takes around 15-18s after patch request processing
527    Sleep  ${NETWORK_TIMEOUT}s
528    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
529
530    ${delete_status}=  Run Keyword And Return Status  Verify IP On BMC  ${ip}
531    Run Keyword If  '${valid_status_codes}' == '${HTTP_OK}'
532    ...  Should Be True  '${delete_status}' == '${False}'
533    ...  ELSE  Should Be True  '${delete_status}' == '${True}'
534
535    Validate Network Config On BMC
536
537
538Validate Network Config On BMC
539    [Documentation]  Check that network info obtained via redfish matches info
540    ...              obtained via CLI.
541
542    @{network_configurations}=  Get Network Configuration
543    ${ip_data}=  Get BMC IP Info
544    FOR  ${network_configuration}  IN  @{network_configurations}
545      Should Contain Match  ${ip_data}  ${network_configuration['Address']}/*
546      ...  msg=IP address does not exist.
547    END
548
549
550Create VLAN
551    [Documentation]  Create a VLAN.
552    [Arguments]  ${id}  ${interface}=eth0  ${expected_result}=valid
553
554    # Description of argument(s):
555    # id  The VLAN ID (e.g. '53').
556    # interface  The physical interface for the VLAN(e.g. 'eth0').
557    # expected_result  Expected status of VLAN configuration.
558
559    @{data_vlan_id}=  Create List  ${interface}  ${id}
560    ${data}=  Create Dictionary   data=@{data_vlan_id}
561    ${resp}=  OpenBMC Post Request  ${vlan_resource}  data=${data}
562    ${resp.status_code}=  Convert To String  ${resp.status_code}
563    ${status}=  Run Keyword And Return Status
564    ...  Valid Value  resp.status_code  ["${HTTP_OK}"]
565
566    Run Keyword If  '${expected_result}' == 'error'
567    ...      Should Be Equal  ${status}  ${False}
568    ...      msg=Configuration of an invalid VLAN ID Failed.
569    ...  ELSE
570    ...      Should Be Equal  ${status}  ${True}
571    ...      msg=Configuration of a valid VLAN ID Failed.
572
573    Sleep  ${NETWORK_TIMEOUT}s
574
575
576Configure Network Settings On VLAN
577    [Documentation]  Configure network settings.
578    [Arguments]  ${id}  ${ip_addr}  ${prefix_len}  ${gateway_ip}=${gateway}
579    ...  ${expected_result}=valid  ${interface}=eth0
580
581    # Description of argument(s):
582    # id               The VLAN ID (e.g. '53').
583    # ip_addr          IP address of VLAN Interface.
584    # prefix_len       Prefix length of VLAN Interface.
585    # gateway_ip       Gateway IP address of VLAN Interface.
586    # expected_result  Expected status of network setting configuration.
587    # interface        Physical Interface on which the VLAN is defined.
588
589    @{ip_parm_list}=  Create List  ${network_resource}
590    ...  ${ip_addr}  ${prefix_len}  ${gateway_ip}
591
592    ${data}=  Create Dictionary  data=@{ip_parm_list}
593
594    Run Keyword And Ignore Error  OpenBMC Post Request
595    ...  ${NETWORK_MANAGER}${interface}_${id}/action/IP  data=${data}
596
597    # After any modification on network interface, BMC restarts network
598    # module, wait until it is reachable. Then wait 15 seconds for new
599    # configuration to be updated on BMC.
600
601    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
602    ...  ${NETWORK_RETRY_TIME}
603    Sleep  ${NETWORK_TIMEOUT}s
604
605    # Verify whether new IP address is populated on BMC system.
606    # It should not allow to configure invalid settings.
607    ${status}=  Run Keyword And Return Status
608    ...  Verify IP On BMC  ${ip_addr}
609
610    Run Keyword If  '${expected_result}' == 'error'
611    ...      Should Be Equal  ${status}  ${False}
612    ...      msg=Configuration of invalid IP Failed.
613    ...  ELSE
614    ...      Should Be Equal  ${status}  ${True}
615    ...      msg=Configuration of valid IP Failed.
616
617
618Get BMC Default Gateway
619    [Documentation]  Get system default gateway.
620
621    ${route_info}=  Get BMC Route Info
622
623    ${lines}=  Get Lines Containing String  ${route_info}  default via
624    @{gateway_list}=  Split To Lines  ${lines}
625
626    # Extract first default gateway and return.
627    @{default_gw}=  Split String  ${gateway_list[0]}
628
629    [Return]  ${default_gw[2]}
630