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