1*** Settings ***
2Documentation  Network interface configuration and verification
3               ...  tests.
4
5Resource       ../../lib/bmc_redfish_resource.robot
6Resource       ../../lib/bmc_network_utils.robot
7Resource       ../../lib/openbmc_ffdc.robot
8Library        ../../lib/bmc_network_utils.py
9Library        Collections
10
11Test Setup     Test Setup Execution
12Test Teardown  Test Teardown Execution
13Suite Setup    Suite Setup Execution
14
15Force Tags     Network_Conf_Test
16
17*** Variables ***
18${test_hostname}           openbmc
19${test_ipv4_addr}          10.7.7.7
20${test_ipv4_invalid_addr}  0.0.1.a
21${test_subnet_mask}        255.255.0.0
22${broadcast_ip}            10.7.7.255
23${loopback_ip}             127.0.0.2
24${multicast_ip}            224.6.6.6
25${out_of_range_ip}         10.7.7.256
26${test_ipv4_addr2}         10.7.7.8
27
28# Valid netmask is 4 bytes long and has continuos block of 1s.
29# Maximum valid value in each octet is 255 and least value is 0.
30# 253 is not valid, as binary value is 11111101.
31${invalid_netmask}         255.255.253.0
32${alpha_netmask}           ff.ff.ff.ff
33# Maximum value of octet in netmask is 255.
34${out_of_range_netmask}    255.256.255.0
35${more_byte_netmask}       255.255.255.0.0
36${less_byte_netmask}       255.255.255
37${threshold_netmask}       255.255.255.255
38${lowest_netmask}          128.0.0.0
39
40# There will be 4 octets in IP address (e.g. xx.xx.xx.xx)
41# but trying to configure xx.xx.xx
42${less_octet_ip}           10.3.36
43
44# For the address 10.6.6.6, the 10.6.6.0 portion describes the
45# network ID and the 6 describe the host.
46
47${network_id}              10.7.7.0
48${hex_ip}                  0xa.0xb.0xc.0xd
49${negative_ip}             10.-7.-7.7
50${hex_ip}                  0xa.0xb.0xc.0xd
51@{static_name_servers}     10.5.5.5
52@{null_value}              null
53@{empty_dictionary}        {}
54@{string_value}            aa.bb.cc.dd
55
56*** Test Cases ***
57
58Get IP Address And Verify
59    [Documentation]  Get IP Address And Verify.
60    [Tags]  Get_IP_Address_And_Verify
61
62    FOR  ${network_configuration}  IN  @{network_configurations}
63      Verify IP On BMC  ${network_configuration['Address']}
64    END
65
66Get Netmask And Verify
67    [Documentation]  Get Netmask And Verify.
68    [Tags]  Get_Netmask_And_Verify
69
70    FOR  ${network_configuration}  IN  @{network_configurations}
71      Verify Netmask On BMC  ${network_configuration['SubnetMask']}
72    END
73
74Get Gateway And Verify
75    [Documentation]  Get gateway and verify it's existence on the BMC.
76    [Tags]  Get_Gateway_And_Verify
77
78    FOR  ${network_configuration}  IN  @{network_configurations}
79      Verify Gateway On BMC  ${network_configuration['Gateway']}
80    END
81
82Get MAC Address And Verify
83    [Documentation]  Get MAC address and verify it's existence on the BMC.
84    [Tags]  Get_MAC_Address_And_Verify
85
86    ${active_channel_config}=  Get Active Channel Config
87    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
88
89    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
90    ${macaddr}=  Get From Dictionary  ${resp.dict}  MACAddress
91    Validate MAC On BMC  ${macaddr}
92
93Verify All Configured IP And Netmask
94    [Documentation]  Verify all configured IP and netmask on BMC.
95    [Tags]  Verify_All_Configured_IP_And_Netmask
96
97    FOR  ${network_configuration}  IN  @{network_configurations}
98      Verify IP And Netmask On BMC  ${network_configuration['Address']}
99      ...  ${network_configuration['SubnetMask']}
100    END
101
102Get Hostname And Verify
103    [Documentation]  Get hostname via Redfish and verify.
104    [Tags]  Get_Hostname_And_Verify
105
106    ${hostname}=  Redfish_Utils.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  HostName
107
108    Validate Hostname On BMC  ${hostname}
109
110Configure Hostname And Verify
111    [Documentation]  Configure hostname via Redfish and verify.
112    [Tags]  Configure_Hostname_And_Verify
113
114    ${hostname}=  Redfish_Utils.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  HostName
115
116    Configure Hostname  ${test_hostname}
117    Validate Hostname On BMC  ${test_hostname}
118
119    # Revert back to initial hostname.
120    Configure Hostname  ${hostname}
121    Validate Hostname On BMC  ${hostname}
122
123Add Valid IPv4 Address And Verify
124    [Documentation]  Add IPv4 Address via Redfish and verify.
125    [Tags]  Add_Valid_IPv4_Addres_And_Verify
126    [Teardown]   Run Keywords
127    ...  Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown Execution
128
129     Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
130
131Add Invalid IPv4 Address And Verify
132    [Documentation]  Add Invalid IPv4 Address via Redfish and verify.
133    [Tags]  Add_Invalid_IPv4_Addres_And_Verify
134
135    Add IP Address  ${test_ipv4_invalid_addr}  ${test_subnet_mask}
136    ...  ${test_gateway}  valid_status_codes=${HTTP_BAD_REQUEST}
137
138Configure Out Of Range IP
139    [Documentation]  Configure out-of-range IP address.
140    [Tags]  Configure_Out_Of_Range_IP
141    [Template]  Add IP Address
142
143    # ip                subnet_mask          gateway          valid_status_codes
144    ${out_of_range_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
145
146Configure Broadcast IP
147    [Documentation]  Configure broadcast IP address.
148    [Tags]  Configure_Broadcast_IP
149    [Template]  Add IP Address
150    [Teardown]  Clear IP Settings On Fail  ${broadcast_ip}
151
152    # ip             subnet_mask          gateway          valid_status_codes
153    ${broadcast_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
154
155Configure Multicast IP
156    [Documentation]  Configure multicast IP address.
157    [Tags]  Configure_Multicast_IP
158    [Template]  Add IP Address
159    [Teardown]  Clear IP Settings On Fail  ${multicast_ip}
160
161    # ip             subnet_mask          gateway          valid_status_codes
162    ${multicast_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
163
164Configure Loopback IP
165    [Documentation]  Configure loopback IP address.
166    [Tags]  Configure_Loopback_IP
167    [Template]  Add IP Address
168    [Teardown]  Clear IP Settings On Fail  ${loopback_ip}
169
170    # ip            subnet_mask          gateway          valid_status_codes
171    ${loopback_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
172
173Add Valid IPv4 Address And Check Persistency
174    [Documentation]  Add IPv4 address and check peristency.
175    [Tags]  Add_Valid_IPv4_Addres_And_Check_Persistency
176    [Teardown]  Run Keywords
177    ...  Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown Execution
178
179    Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
180
181    # Reboot BMC and verify persistency.
182    OBMC Reboot (off)
183    Redfish.Login
184    Verify IP On BMC  ${test_ipv4_addr}
185
186Add Fourth Octet Threshold IP And Verify
187    [Documentation]  Add fourth octet threshold IP and verify.
188    [Tags]  Add_Fourth_Octet_Threshold_IP_And_Verify
189    [Teardown]  Run Keywords
190    ...  Delete IP Address  10.7.7.254  AND  Test Teardown Execution
191
192     Add IP Address  10.7.7.254  ${test_subnet_mask}  ${test_gateway}
193
194Add Fourth Octet Lowest IP And Verify
195    [Documentation]  Add fourth octet lowest IP and verify.
196    [Tags]  Add_Fourth_Octet_Lowest_IP_And_Verify
197    [Teardown]  Run Keywords
198    ...  Delete IP Address  10.7.7.1  AND  Test Teardown Execution
199
200     Add IP Address  10.7.7.1  ${test_subnet_mask}  ${test_gateway}
201
202Add Third Octet Threshold IP And Verify
203    [Documentation]  Add third octet threshold IP and verify.
204    [Tags]  Add_Third_Octet_Threshold_IP_And_Verify
205    [Teardown]  Run Keywords
206    ...  Delete IP Address  10.7.255.7  AND  Test Teardown Execution
207
208     Add IP Address  10.7.255.7  ${test_subnet_mask}  ${test_gateway}
209
210Add Third Octet Lowest IP And Verify
211    [Documentation]  Add third octet lowest IP and verify.
212    [Tags]  Add_Third_Octet_Lowest_IP_And_Verify
213    [Teardown]  Run Keywords
214    ...  Delete IP Address  10.7.0.7  AND  Test Teardown Execution
215
216     Add IP Address  10.7.0.7  ${test_subnet_mask}  ${test_gateway}
217
218Add Second Octet Threshold IP And Verify
219    [Documentation]  Add second octet threshold IP and verify.
220    [Tags]  Add_Second_Octet_Threshold_IP_And_Verify
221    [Teardown]  Run Keywords
222    ...  Delete IP Address  10.255.7.7  AND  Test Teardown Execution
223
224     Add IP Address  10.255.7.7  ${test_subnet_mask}  ${test_gateway}
225
226Add Second Octet Lowest IP And Verify
227    [Documentation]  Add second octet lowest IP and verify.
228    [Tags]  Add_Second_Octet_Lowest_IP_And_Verify
229    [Teardown]  Run Keywords
230    ...  Delete IP Address  10.0.7.7  AND  Test Teardown Execution
231
232     Add IP Address  10.0.7.7  ${test_subnet_mask}  ${test_gateway}
233
234Add First Octet Threshold IP And Verify
235    [Documentation]  Add first octet threshold IP and verify.
236    [Tags]  Add_First_Octet_Threshold_IP_And_Verify
237    [Teardown]  Run Keywords
238    ...  Delete IP Address  223.7.7.7  AND  Test Teardown Execution
239
240     Add IP Address  223.7.7.7  ${test_subnet_mask}  ${test_gateway}
241
242Add First Octet Lowest IP And Verify
243    [Documentation]  Add first octet lowest IP and verify.
244    [Tags]  Add_First_Octet_Lowest_IP_And_Verify
245    [Teardown]  Run Keywords
246    ...  Delete IP Address  1.7.7.7  AND  Test Teardown Execution
247
248     Add IP Address  1.7.7.7  ${test_subnet_mask}  ${test_gateway}
249
250Configure Invalid Netmask
251    [Documentation]  Verify error while setting invalid netmask.
252    [Tags]  Configure_Invalid_Netmask
253    [Template]  Add IP Address
254
255    # ip               subnet_mask         gateway          valid_status_codes
256    ${test_ipv4_addr}  ${invalid_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
257
258Configure Out Of Range Netmask
259    [Documentation]  Verify error while setting out of range netmask.
260    [Tags]  Configure_Out_Of_Range_Netmask
261    [Template]  Add IP Address
262
263    # ip               subnet_mask              gateway          valid_status_codes
264    ${test_ipv4_addr}  ${out_of_range_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
265
266Configure Alpha Netmask
267    [Documentation]  Verify error while setting alpha netmask.
268    [Tags]  Configure_Alpha_Netmask
269    [Template]  Add IP Address
270
271    # ip               subnet_mask       gateway          valid_status_codes
272    ${test_ipv4_addr}  ${alpha_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
273
274Configure More Byte Netmask
275    [Documentation]  Verify error while setting more byte netmask.
276    [Tags]  Configure_More_Byte_Netmask
277    [Template]  Add IP Address
278
279    # ip               subnet_mask           gateway          valid_status_codes
280    ${test_ipv4_addr}  ${more_byte_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
281
282Configure Less Byte Netmask
283    [Documentation]  Verify error while setting less byte netmask.
284    [Tags]  Configure_Less_Byte_Netmask
285    [Template]  Add IP Address
286
287    # ip               subnet_mask           gateway          valid_status_codes
288    ${test_ipv4_addr}  ${less_byte_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
289
290Configure Threshold Netmask And Verify
291    [Documentation]  Configure threshold netmask and verify.
292    [Tags]  Configure_Threshold_Netmask_And_verify
293    [Teardown]  Run Keywords
294    ...   Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown Execution
295
296     Add IP Address  ${test_ipv4_addr}  ${threshold_netmask}  ${test_gateway}
297
298Configure Lowest Netmask And Verify
299    [Documentation]  Configure lowest netmask and verify.
300    [Tags]  Configure_Lowest_Netmask_And_verify
301    [Teardown]  Run Keywords
302    ...   Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown Execution
303
304     Add IP Address  ${test_ipv4_addr}  ${lowest_netmask}  ${test_gateway}
305
306Configure Network ID
307    [Documentation]  Verify error while configuring network ID.
308    [Tags]  Configure_Network_ID
309    [Template]  Add IP Address
310    [Teardown]  Clear IP Settings On Fail  ${network_id}
311
312    # ip           subnet_mask          gateway          valid_status_codes
313    ${network_id}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
314
315Configure Less Octet IP
316    [Documentation]  Verify error while Configuring less octet IP address.
317    [Tags]  Configure_Less_Octet_IP
318    [Template]  Add IP Address
319
320    # ip              subnet_mask          gateway          valid_status_codes
321    ${less_octet_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
322
323Configure Empty IP
324    [Documentation]  Verify error while Configuring empty IP address.
325    [Tags]  Configure_Empty_IP
326    [Template]  Add IP Address
327
328    # ip      subnet_mask          gateway          valid_status_codes
329    ${EMPTY}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
330
331Configure Special Char IP
332    [Documentation]  Configure invalid IP address containing special chars.
333    [Tags]  Configure_Special_Char_IP
334    [Template]  Add IP Address
335
336    # ip          subnet_mask          gateway          valid_status_codes
337    @@@.%%.44.11  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
338
339Configure Hexadecimal IP
340    [Documentation]  Configure invalid IP address containing hex value.
341    [Tags]  Configure_Hexadecimal_IP
342    [Template]  Add IP Address
343
344    # ip       subnet_mask          gateway          valid_status_codes
345    ${hex_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
346
347Configure Negative Octet IP
348    [Documentation]  Configure invalid IP address containing negative octet.
349    [Tags]  Configure_Negative_Octet_IP
350    [Template]  Add IP Address
351
352    # ip            subnet_mask          gateway          valid_status_codes
353    ${negative_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
354
355Configure Incomplete IP For Gateway
356    [Documentation]  Configure incomplete IP for gateway and expect an error.
357    [Tags]  Configure_Incomplete_IP_For_Gateway
358    [Template]  Add IP Address
359
360    # ip               subnet_mask          gateway           valid_status_codes
361    ${test_ipv4_addr}  ${test_subnet_mask}  ${less_octet_ip}  ${HTTP_BAD_REQUEST}
362
363Configure Special Char IP For Gateway
364    [Documentation]  Configure special char IP for gateway and expect an error.
365    [Tags]  Configure_Special_Char_IP_For_Gateway
366    [Template]  Add IP Address
367
368    # ip               subnet_mask          gateway       valid_status_codes
369    ${test_ipv4_addr}  ${test_subnet_mask}  @@@.%%.44.11  ${HTTP_BAD_REQUEST}
370
371Configure Hexadecimal IP For Gateway
372    [Documentation]  Configure hexadecimal IP for gateway and expect an error.
373    [Tags]  Configure_Hexadecimal_IP_For_Gateway
374    [Template]  Add IP Address
375
376    # ip               subnet_mask          gateway    valid_status_codes
377    ${test_ipv4_addr}  ${test_subnet_mask}  ${hex_ip}  ${HTTP_BAD_REQUEST}
378
379Get DNS Server And Verify
380    [Documentation]  Get DNS server via Redfish and verify.
381    [Tags]  Get_DNS_Server_And_Verify
382
383    Verify CLI and Redfish Nameservers
384
385Configure DNS Server And Verify
386    [Documentation]  Configure DNS server and verify.
387    [Tags]  Configure_DNS_Server_And_Verify
388    [Setup]  DNS Test Setup Execution
389    [Teardown]  Run Keywords
390    ...  Configure Static Name Servers  AND  Test Teardown Execution
391
392    Configure Static Name Servers  ${static_name_servers}
393    Verify CLI and Redfish Nameservers
394
395Delete DNS Server And Verify
396    [Documentation]  Delete DNS server and verify.
397    [Tags]  Delete_DNS_Server_And_Verify
398    [Setup]  DNS Test Setup Execution
399    [Teardown]  Run Keywords
400    ...  Configure Static Name Servers  AND  Test Teardown Execution
401
402    Delete Static Name Servers
403    Verify CLI and Redfish Nameservers
404
405Configure DNS Server And Check Persistency
406    [Documentation]  Configure DNS server and check persistency on reboot.
407    [Tags]  Configure_DNS_Server_And_Check_Persistency
408    [Setup]  DNS Test Setup Execution
409    [Teardown]  Run Keywords
410    ...  Configure Static Name Servers  AND  Test Teardown Execution
411
412    Configure Static Name Servers  ${static_name_servers}
413    # Reboot BMC and verify persistency.
414    OBMC Reboot (off)
415    Verify CLI and Redfish Nameservers
416
417Configure Loopback IP For Gateway
418    [Documentation]  Configure loopback IP for gateway and expect an error.
419    [Tags]  Configure_Loopback_IP_For_Gateway
420    [Template]  Add IP Address
421    [Teardown]  Clear IP Settings On Fail  ${test_ipv4_addr}
422
423    # ip               subnet_mask          gateway         valid_status_codes
424    ${test_ipv4_addr}  ${test_subnet_mask}  ${loopback_ip}  ${HTTP_BAD_REQUEST}
425
426Configure Network ID For Gateway
427    [Documentation]  Configure network ID for gateway and expect an error.
428    [Tags]  Configure_Network_ID_For_Gateway
429    [Template]  Add IP Address
430    [Teardown]  Clear IP Settings On Fail  ${test_ipv4_addr}
431
432    # ip               subnet_mask          gateway        valid_status_codes
433    ${test_ipv4_addr}  ${test_subnet_mask}  ${network_id}  ${HTTP_BAD_REQUEST}
434
435Configure Multicast IP For Gateway
436    [Documentation]  Configure multicast IP for gateway and expect an error.
437    [Tags]  Configure_Multicast_IP_For_Gateway
438    [Template]  Add IP Address
439    [Teardown]  Clear IP Settings On Fail  ${test_ipv4_addr}
440
441    # ip               subnet_mask          gateway           valid_status_codes
442    ${test_ipv4_addr}  ${test_subnet_mask}  ${multicast_ip}  ${HTTP_BAD_REQUEST}
443
444Configure Broadcast IP For Gateway
445    [Documentation]  Configure broadcast IP for gateway and expect an error.
446    [Tags]  Configure_Broadcast_IP_For_Gateway
447    [Template]  Add IP Address
448    [Teardown]  Clear IP Settings On Fail  ${test_ipv4_addr}
449
450    # ip               subnet_mask          gateway          valid_status_codes
451    ${test_ipv4_addr}  ${test_subnet_mask}  ${broadcast_ip}  ${HTTP_BAD_REQUEST}
452
453Configure Null Value For DNS Server
454    [Documentation]  Configure null value for DNS server and expect an error.
455    [Tags]  Configure_Null_Value_For_DNS_Server
456    [Setup]  DNS Test Setup Execution
457    [Teardown]  Run Keywords
458    ...  Configure Static Name Servers  AND  Test Teardown Execution
459
460    Configure Static Name Servers  ${null_value}  ${HTTP_BAD_REQUEST}
461
462Configure Empty Value For DNS Server
463    [Documentation]  Configure empty value for DNS server and expect an error.
464    [Tags]  Configure_Empty_Value_For_DNS_Server
465    [Setup]  DNS Test Setup Execution
466    [Teardown]  Run Keywords
467    ...  Configure Static Name Servers  AND  Test Teardown Execution
468
469    Configure Static Name Servers  ${empty_dictionary}  ${HTTP_BAD_REQUEST}
470
471Configure String Value For DNS Server
472    [Documentation]  Configure string value for DNS server and expect an error.
473    [Tags]  Configure_String_Value_For_DNS_Server
474    [Setup]  DNS Test Setup Execution
475    [Teardown]  Run Keywords
476    ...  Configure Static Name Servers  AND  Test Teardown Execution
477
478    Configure Static Name Servers  ${string_value}  ${HTTP_BAD_REQUEST}
479
480Modify IPv4 Address And Verify
481    [Documentation]  Modify IP address via Redfish and verify.
482    [Tags]  Modify_IPv4_Addres_And_Verify
483    [Teardown]  Run Keywords
484    ...  Delete IP Address  ${test_ipv4_addr2}  AND  Delete IP Address  ${test_ipv4_addr}
485    ...  AND  Test Teardown Execution
486
487     Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
488
489     Update IP Address  ${test_ipv4_addr}  ${test_ipv4_addr2}  ${test_subnet_mask}  ${test_gateway}
490
491
492*** Keywords ***
493
494Test Setup Execution
495    [Documentation]  Test setup execution.
496
497    Redfish.Login
498
499    @{network_configurations}=  Get Network Configuration
500    Set Test Variable  @{network_configurations}
501
502    # Get BMC IP address and prefix length.
503    ${ip_data}=  Get BMC IP Info
504    Set Test Variable  ${ip_data}
505
506
507Verify Netmask On BMC
508    [Documentation]  Verify netmask on BMC.
509    [Arguments]  ${netmask}
510
511    # Description of the argument(s):
512    # netmask  netmask value to be verified.
513
514    ${prefix_length}=  Netmask Prefix Length  ${netmask}
515
516    Should Contain Match  ${ip_data}  */${prefix_length}
517    ...  msg=Prefix length does not exist.
518
519Verify IP And Netmask On BMC
520    [Documentation]  Verify IP and netmask on BMC.
521    [Arguments]  ${ip}  ${netmask}
522
523    # Description of the argument(s):
524    # ip       IP address to be verified.
525    # netmask  netmask value to be verified.
526
527    ${prefix_length}=  Netmask Prefix Length  ${netmask}
528    @{ip_data}=  Get BMC IP Info
529
530    ${ip_with_netmask}=  Catenate  ${ip}/${prefix_length}
531    Should Contain  ${ip_data}  ${ip_with_netmask}
532    ...  msg=IP and netmask pair does not exist.
533
534Validate Hostname On BMC
535    [Documentation]  Verify that the hostname read via Redfish is the same as the
536    ...  hostname configured on system.
537    [Arguments]  ${hostname}
538
539    # Description of argument(s):
540    # hostname  A hostname value which is to be compared to the hostname
541    #           configured on system.
542
543    ${sys_hostname}=  Get BMC Hostname
544    Should Be Equal  ${sys_hostname}  ${hostname}
545    ...  ignore_case=True  msg=Hostname does not exist.
546
547Test Teardown Execution
548    [Documentation]  Test teardown execution.
549
550    FFDC On Test Case Fail
551    Redfish.Logout
552
553Clear IP Settings On Fail
554    [Documentation]  Clear IP settings on fail.
555    [Arguments]  ${ip}
556
557    # Description of argument(s):
558    # ip  IP address to be deleted.
559
560    Run Keyword If  '${TEST STATUS}' == 'FAIL'
561    ...  Delete IP Address  ${ip}
562
563    Test Teardown Execution
564
565Verify CLI and Redfish Nameservers
566    [Documentation]  Verify that nameservers obtained via Redfish do not
567    ...  match those found in /etc/resolv.conf.
568
569    ${active_channel_config}=  Get Active Channel Config
570    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
571
572    ${redfish_nameservers}=  Redfish.Get Attribute
573    ...  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  StaticNameServers
574    ${resolve_conf_nameservers}=  CLI Get Nameservers
575    Rqprint Vars  redfish_nameservers  resolve_conf_nameservers
576
577    # Check that the 2 lists are equivalent.
578    ${match}=  Evaluate  set($redfish_nameservers) == set($resolve_conf_nameservers)
579    Should Be True  ${match}
580    ...  The nameservers obtained via Redfish do not match those found in /etc/resolv.conf.
581
582
583Configure Static Name Servers
584    [Documentation]  Configure DNS server on BMC.
585    [Arguments]  ${static_name_servers}=${original_nameservers}
586     ...  ${valid_status_codes}=${HTTP_OK}
587
588    # Description of the argument(s):
589    # static_name_servers  A list of static name server IPs to be
590    #                      configured on the BMC.
591
592    ${active_channel_config}=  Get Active Channel Config
593    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
594
595    # Currently BMC is sending 500 response code instead of 400 for invalid scenarios.
596    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
597    ...  body={'StaticNameServers': ${static_name_servers}}
598    ...  valid_status_codes=[${valid_status_codes}, ${HTTP_INTERNAL_SERVER_ERROR}]
599
600    # Patch operation takes 1 to 3 seconds to set new value.
601    Sleep  3s
602
603    # Check if newly added DNS server is configured on BMC.
604    ${cli_nameservers}=  CLI Get Nameservers
605    ${cmd_status}=  Run Keyword And Return Status
606    ...  List Should Contain Sub List  ${cli_nameservers}  ${static_name_servers}
607
608    Run Keyword If  '${valid_status_codes}' == '${HTTP_OK}'
609    ...  Should Be True  ${cmd_status} == ${True}
610    ...  ELSE  Should Be True  ${cmd_status} == ${False}
611
612Delete Static Name Servers
613    [Documentation]  Delete static name servers.
614
615    Configure Static Name Servers  @{EMPTY}
616
617    # Check if all name servers deleted on BMC.
618    ${nameservers}=  CLI Get Nameservers
619    Should Be Empty  ${nameservers}
620
621DNS Test Setup Execution
622    [Documentation]  Do DNS test setup execution.
623
624    Redfish.Login
625
626    ${active_channel_config}=  Get Active Channel Config
627    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
628
629    ${original_nameservers}=  Redfish.Get Attribute
630    ...  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  StaticNameServers
631
632    Rprint Vars  original_nameservers
633    # Set suite variables to trigger restoration during teardown.
634    Set Suite Variable  ${original_nameservers}
635
636Suite Setup Execution
637    [Documentation]  Do suite setup execution.
638
639    ${test_gateway}=  Get BMC Default Gateway
640    Set Suite Variable  ${test_gateway}
641
642Update IP Address
643    [Documentation]  Update IP address of BMC.
644    [Arguments]  ${ip}  ${new_ip}  ${netmask}  ${gw_ip}  ${valid_status_codes}=${HTTP_OK}
645
646    # Description of argument(s):
647    # ip                  IP address to be replaced (e.g. "10.7.7.7").
648    # new_ip              New IP address to be configured.
649    # netmask             Netmask value.
650    # gw_ip               Gateway IP address.
651    # valid_status_codes  Expected return code from patch operation
652    #                     (e.g. "200").  See prolog of rest_request
653    #                     method in redfish_plus.py for details.
654
655    ${empty_dict}=  Create Dictionary
656    ${patch_list}=  Create List
657    ${ip_data}=  Create Dictionary  Address=${new_ip}  SubnetMask=${netmask}  Gateway=${gw_ip}
658
659    # Find the position of IP address to be modified.
660    @{network_configurations}=  Get Network Configuration
661    FOR  ${network_configuration}  IN  @{network_configurations}
662      Run Keyword If  '${network_configuration['Address']}' == '${ip}'
663      ...  Append To List  ${patch_list}  ${ip_data}
664      ...  ELSE  Append To List  ${patch_list}  ${empty_dict}
665    END
666
667    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
668    ...  ${patch_list}  ${ip_data}  msg=${ip} does not exist on BMC
669    Pass Execution If  ${ip_found} == ${False}  ${ip} does not exist on BMC
670
671    # Run patch command only if given IP is found on BMC
672    ${data}=  Create Dictionary  IPv4StaticAddresses=${patch_list}
673
674    Redfish.patch  ${REDFISH_NW_ETH0_URI}  body=&{data}  valid_status_codes=[${valid_status_codes}]
675
676    # Note: Network restart takes around 15-18s after patch request processing.
677    Sleep  ${NETWORK_TIMEOUT}s
678    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
679
680    Verify IP On BMC  ${new_ip}
681    Validate Network Config On BMC
682