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
11Suite Setup     Suite Setup Execution
12Suite Teardown  Suite Teardown Execution
13Test Setup      Test Setup Execution
14Test Teardown   Test Teardown Execution
15
16Force Tags     Bmc_Network_Conf
17
18*** Variables ***
19${test_hostname}           openbmc
20${test_ipv4_addr}          10.7.7.7
21${test_ipv4_invalid_addr}  0.0.1.a
22${test_subnet_mask}        255.255.0.0
23${broadcast_ip}            10.7.7.255
24${loopback_ip}             127.0.0.2
25${multicast_ip}            224.6.6.6
26${out_of_range_ip}         10.7.7.256
27${test_ipv4_addr2}         10.7.7.8
28
29# Valid netmask is 4 bytes long and has continuous block of 1s.
30# Maximum valid value in each octet is 255 and least value is 0.
31# 253 is not valid, as binary value is 11111101.
32${invalid_netmask}         255.255.253.0
33${alpha_netmask}           ff.ff.ff.ff
34# Maximum value of octet in netmask is 255.
35${out_of_range_netmask}    255.256.255.0
36${more_byte_netmask}       255.255.255.0.0
37${less_byte_netmask}       255.255.255
38${threshold_netmask}       255.255.255.255
39${lowest_netmask}          128.0.0.0
40
41# There will be 4 octets in IP address (e.g. xx.xx.xx.xx)
42# but trying to configure xx.xx.xx
43${less_octet_ip}           10.3.36
44
45# For the address 10.6.6.6, the 10.6.6.0 portion describes the
46# network ID and the 6 describe the host.
47
48${network_id}              10.7.7.0
49${hex_ip}                  0xa.0xb.0xc.0xd
50${negative_ip}             10.-7.-7.7
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    [Teardown]  Run Keywords
114    ...  Configure Hostname  ${hostname}  AND  Validate Hostname On BMC  ${hostname}
115
116    ${hostname}=  Redfish_Utils.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  HostName
117
118    Configure Hostname  ${test_hostname}
119    Validate Hostname On BMC  ${test_hostname}
120
121    # Verify configured hostname via redfish.
122    ${new_hostname}=  Redfish_Utils.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  HostName
123    Should Be Equal  ${new_hostname}  ${test_hostname}
124
125Configure Invalid HostName And Verify
126    [Documentation]  Configure invalid hostname via Redfish and Verify.
127    [Tags]  Configure_Invalid_HostName_And_Verify
128    [Template]  Configure Hostname
129
130    # hostname          status_code
131    !#@                 [${HTTP_BAD_REQUEST}]
132    ${EMPTY}            [${HTTP_BAD_REQUEST}]
133
134Add Valid IPv4 Address And Verify
135    [Documentation]  Add IPv4 Address via Redfish and verify.
136    [Tags]  Add_Valid_IPv4_Address_And_Verify
137    [Teardown]   Run Keywords
138    ...  Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown Execution
139
140     Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
141
142Add Invalid IPv4 Address And Verify
143    [Documentation]  Add Invalid IPv4 Address via Redfish and verify.
144    [Tags]  Add_Invalid_IPv4_Address_And_Verify
145
146    Add IP Address  ${test_ipv4_invalid_addr}  ${test_subnet_mask}
147    ...  ${test_gateway}  valid_status_codes=${HTTP_BAD_REQUEST}
148
149Configure Out Of Range IP
150    [Documentation]  Configure out-of-range IP address.
151    [Tags]  Configure_Out_Of_Range_IP
152    [Template]  Add IP Address
153
154    # ip                subnet_mask          gateway          valid_status_codes
155    ${out_of_range_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
156
157Configure Broadcast IP
158    [Documentation]  Configure broadcast IP address.
159    [Tags]  Configure_Broadcast_IP
160    [Template]  Add IP Address
161    [Teardown]  Clear IP Settings On Fail  ${broadcast_ip}
162
163    # ip             subnet_mask          gateway          valid_status_codes
164    ${broadcast_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
165
166Configure Multicast IP
167    [Documentation]  Configure multicast IP address.
168    [Tags]  Configure_Multicast_IP
169    [Template]  Add IP Address
170    [Teardown]  Clear IP Settings On Fail  ${multicast_ip}
171
172    # ip             subnet_mask          gateway          valid_status_codes
173    ${multicast_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
174
175Configure Loopback IP
176    [Documentation]  Configure loopback IP address.
177    [Tags]  Configure_Loopback_IP
178    [Template]  Add IP Address
179    [Teardown]  Clear IP Settings On Fail  ${loopback_ip}
180
181    # ip            subnet_mask          gateway          valid_status_codes
182    ${loopback_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
183
184Add Valid IPv4 Address And Check Persistency
185    [Documentation]  Add IPv4 address and check persistency.
186    [Tags]  Add_Valid_IPv4_Address_And_Check_Persistency
187    [Teardown]  Run Keywords
188    ...  Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown Execution
189
190    Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
191
192    # Reboot BMC and verify persistency.
193    Redfish OBMC Reboot (off)  stack_mode=skip
194    Redfish.Login
195    Verify IP On BMC  ${test_ipv4_addr}
196    Verify IP On Redfish URI  ${test_ipv4_addr}
197
198
199Add Fourth Octet Threshold IP And Verify
200    [Documentation]  Add fourth octet threshold IP and verify.
201    [Tags]  Add_Fourth_Octet_Threshold_IP_And_Verify
202    [Teardown]  Run Keywords
203    ...  Delete IP Address  10.7.7.254  AND  Test Teardown Execution
204
205     Add IP Address  10.7.7.254  ${test_subnet_mask}  ${test_gateway}
206
207Add Fourth Octet Lowest IP And Verify
208    [Documentation]  Add fourth octet lowest IP and verify.
209    [Tags]  Add_Fourth_Octet_Lowest_IP_And_Verify
210    [Teardown]  Run Keywords
211    ...  Delete IP Address  10.7.7.1  AND  Test Teardown Execution
212
213     Add IP Address  10.7.7.1  ${test_subnet_mask}  ${test_gateway}
214
215Add Third Octet Threshold IP And Verify
216    [Documentation]  Add third octet threshold IP and verify.
217    [Tags]  Add_Third_Octet_Threshold_IP_And_Verify
218    [Teardown]  Run Keywords
219    ...  Delete IP Address  10.7.255.7  AND  Test Teardown Execution
220
221     Add IP Address  10.7.255.7  ${test_subnet_mask}  ${test_gateway}
222
223Add Third Octet Lowest IP And Verify
224    [Documentation]  Add third octet lowest IP and verify.
225    [Tags]  Add_Third_Octet_Lowest_IP_And_Verify
226    [Teardown]  Run Keywords
227    ...  Delete IP Address  10.7.0.7  AND  Test Teardown Execution
228
229     Add IP Address  10.7.0.7  ${test_subnet_mask}  ${test_gateway}
230
231Add Second Octet Threshold IP And Verify
232    [Documentation]  Add second octet threshold IP and verify.
233    [Tags]  Add_Second_Octet_Threshold_IP_And_Verify
234    [Teardown]  Run Keywords
235    ...  Delete IP Address  10.255.7.7  AND  Test Teardown Execution
236
237     Add IP Address  10.255.7.7  ${test_subnet_mask}  ${test_gateway}
238
239Add Second Octet Lowest IP And Verify
240    [Documentation]  Add second octet lowest IP and verify.
241    [Tags]  Add_Second_Octet_Lowest_IP_And_Verify
242    [Teardown]  Run Keywords
243    ...  Delete IP Address  10.0.7.7  AND  Test Teardown Execution
244
245     Add IP Address  10.0.7.7  ${test_subnet_mask}  ${test_gateway}
246
247Add First Octet Threshold IP And Verify
248    [Documentation]  Add first octet threshold IP and verify.
249    [Tags]  Add_First_Octet_Threshold_IP_And_Verify
250    [Teardown]  Run Keywords
251    ...  Delete IP Address  223.7.7.7  AND  Test Teardown Execution
252
253     Add IP Address  223.7.7.7  ${test_subnet_mask}  ${test_gateway}
254
255Add First Octet Lowest IP And Verify
256    [Documentation]  Add first octet lowest IP and verify.
257    [Tags]  Add_First_Octet_Lowest_IP_And_Verify
258    [Teardown]  Run Keywords
259    ...  Delete IP Address  1.7.7.7  AND  Test Teardown Execution
260
261     Add IP Address  1.7.7.7  ${test_subnet_mask}  ${test_gateway}
262
263Configure Invalid Netmask
264    [Documentation]  Verify error while setting invalid netmask.
265    [Tags]  Configure_Invalid_Netmask
266    [Template]  Add IP Address
267
268    # ip               subnet_mask         gateway          valid_status_codes
269    ${test_ipv4_addr}  ${invalid_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
270
271Configure Out Of Range Netmask
272    [Documentation]  Verify error while setting out of range netmask.
273    [Tags]  Configure_Out_Of_Range_Netmask
274    [Template]  Add IP Address
275
276    # ip               subnet_mask              gateway          valid_status_codes
277    ${test_ipv4_addr}  ${out_of_range_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
278
279Configure Alpha Netmask
280    [Documentation]  Verify error while setting alpha netmask.
281    [Tags]  Configure_Alpha_Netmask
282    [Template]  Add IP Address
283
284    # ip               subnet_mask       gateway          valid_status_codes
285    ${test_ipv4_addr}  ${alpha_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
286
287Configure More Byte Netmask
288    [Documentation]  Verify error while setting more byte netmask.
289    [Tags]  Configure_More_Byte_Netmask
290    [Template]  Add IP Address
291
292    # ip               subnet_mask           gateway          valid_status_codes
293    ${test_ipv4_addr}  ${more_byte_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
294
295Configure Less Byte Netmask
296    [Documentation]  Verify error while setting less byte netmask.
297    [Tags]  Configure_Less_Byte_Netmask
298    [Template]  Add IP Address
299
300    # ip               subnet_mask           gateway          valid_status_codes
301    ${test_ipv4_addr}  ${less_byte_netmask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
302
303Configure Threshold Netmask And Verify
304    [Documentation]  Configure threshold netmask and verify.
305    [Tags]  Configure_Threshold_Netmask_And_Verify
306    [Teardown]  Run Keywords
307    ...   Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown Execution
308
309     Add IP Address  ${test_ipv4_addr}  ${threshold_netmask}  ${test_gateway}
310
311Configure Lowest Netmask And Verify
312    [Documentation]  Configure lowest netmask and verify.
313    [Tags]  Configure_Lowest_Netmask_And_Verify
314    [Teardown]  Run Keywords
315    ...   Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown Execution
316
317     Add IP Address  ${test_ipv4_addr}  ${lowest_netmask}  ${test_gateway}
318
319Configure Network ID
320    [Documentation]  Verify error while configuring network ID.
321    [Tags]  Configure_Network_ID
322    [Template]  Add IP Address
323    [Teardown]  Clear IP Settings On Fail  ${network_id}
324
325    # ip           subnet_mask          gateway          valid_status_codes
326    ${network_id}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
327
328Configure Less Octet IP
329    [Documentation]  Verify error while Configuring less octet IP address.
330    [Tags]  Configure_Less_Octet_IP
331    [Template]  Add IP Address
332
333    # ip              subnet_mask          gateway          valid_status_codes
334    ${less_octet_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
335
336Configure Empty IP
337    [Documentation]  Verify error while Configuring empty IP address.
338    [Tags]  Configure_Empty_IP
339    [Template]  Add IP Address
340
341    # ip      subnet_mask          gateway          valid_status_codes
342    ${EMPTY}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
343
344Configure Special Char IP
345    [Documentation]  Configure invalid IP address containing special chars.
346    [Tags]  Configure_Special_Char_IP
347    [Template]  Add IP Address
348
349    # ip          subnet_mask          gateway          valid_status_codes
350    @@@.%%.44.11  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
351
352Configure Hexadecimal IP
353    [Documentation]  Configure invalid IP address containing hex value.
354    [Tags]  Configure_Hexadecimal_IP
355    [Template]  Add IP Address
356
357    # ip       subnet_mask          gateway          valid_status_codes
358    ${hex_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
359
360Configure Negative Octet IP
361    [Documentation]  Configure invalid IP address containing negative octet.
362    [Tags]  Configure_Negative_Octet_IP
363    [Template]  Add IP Address
364
365    # ip            subnet_mask          gateway          valid_status_codes
366    ${negative_ip}  ${test_subnet_mask}  ${test_gateway}  ${HTTP_BAD_REQUEST}
367
368Configure Incomplete IP For Gateway
369    [Documentation]  Configure incomplete IP for gateway and expect an error.
370    [Tags]  Configure_Incomplete_IP_For_Gateway
371    [Template]  Add IP Address
372
373    # ip               subnet_mask          gateway           valid_status_codes
374    ${test_ipv4_addr}  ${test_subnet_mask}  ${less_octet_ip}  ${HTTP_BAD_REQUEST}
375
376Configure Special Char IP For Gateway
377    [Documentation]  Configure special char IP for gateway and expect an error.
378    [Tags]  Configure_Special_Char_IP_For_Gateway
379    [Template]  Add IP Address
380
381    # ip               subnet_mask          gateway       valid_status_codes
382    ${test_ipv4_addr}  ${test_subnet_mask}  @@@.%%.44.11  ${HTTP_BAD_REQUEST}
383
384Configure Hexadecimal IP For Gateway
385    [Documentation]  Configure hexadecimal IP for gateway and expect an error.
386    [Tags]  Configure_Hexadecimal_IP_For_Gateway
387    [Template]  Add IP Address
388
389    # ip               subnet_mask          gateway    valid_status_codes
390    ${test_ipv4_addr}  ${test_subnet_mask}  ${hex_ip}  ${HTTP_BAD_REQUEST}
391
392Get DNS Server And Verify
393    [Documentation]  Get DNS server via Redfish and verify.
394    [Tags]  Get_DNS_Server_And_Verify
395
396    Verify CLI and Redfish Nameservers
397
398Configure DNS Server And Verify
399    [Documentation]  Configure DNS server and verify.
400    [Tags]  Configure_DNS_Server_And_Verify
401    [Setup]  DNS Test Setup Execution
402    [Teardown]  Run Keywords
403    ...  Configure Static Name Servers  AND  Test Teardown Execution
404
405    Configure Static Name Servers  ${static_name_servers}
406    Verify CLI and Redfish Nameservers
407
408Delete DNS Server And Verify
409    [Documentation]  Delete DNS server and verify.
410    [Tags]  Delete_DNS_Server_And_Verify
411    [Setup]  DNS Test Setup Execution
412    [Teardown]  Run Keywords
413    ...  Configure Static Name Servers  AND  Test Teardown Execution
414
415    Delete Static Name Servers
416    Verify CLI and Redfish Nameservers
417
418Configure DNS Server And Check Persistency
419    [Documentation]  Configure DNS server and check persistency on reboot.
420    [Tags]  Configure_DNS_Server_And_Check_Persistency
421    [Setup]  DNS Test Setup Execution
422    [Teardown]  Run Keywords
423    ...  Configure Static Name Servers  AND  Test Teardown Execution
424
425    Configure Static Name Servers  ${static_name_servers}
426    # Reboot BMC and verify persistency.
427    Redfish OBMC Reboot (off)  stack_mode=skip
428    Redfish.Login
429    Verify CLI and Redfish Nameservers
430
431Configure Loopback IP For Gateway
432    [Documentation]  Configure loopback IP for gateway and expect an error.
433    [Tags]  Configure_Loopback_IP_For_Gateway
434    [Template]  Add IP Address
435    [Teardown]  Clear IP Settings On Fail  ${test_ipv4_addr}
436
437    # ip               subnet_mask          gateway         valid_status_codes
438    ${test_ipv4_addr}  ${test_subnet_mask}  ${loopback_ip}  ${HTTP_BAD_REQUEST}
439
440Configure Network ID For Gateway
441    [Documentation]  Configure network ID for gateway and expect an error.
442    [Tags]  Configure_Network_ID_For_Gateway
443    [Template]  Add IP Address
444    [Teardown]  Clear IP Settings On Fail  ${test_ipv4_addr}
445
446    # ip               subnet_mask          gateway        valid_status_codes
447    ${test_ipv4_addr}  ${test_subnet_mask}  ${network_id}  ${HTTP_BAD_REQUEST}
448
449Configure Multicast IP For Gateway
450    [Documentation]  Configure multicast IP for gateway and expect an error.
451    [Tags]  Configure_Multicast_IP_For_Gateway
452    [Template]  Add IP Address
453    [Teardown]  Clear IP Settings On Fail  ${test_ipv4_addr}
454
455    # ip               subnet_mask          gateway           valid_status_codes
456    ${test_ipv4_addr}  ${test_subnet_mask}  ${multicast_ip}  ${HTTP_BAD_REQUEST}
457
458Configure Broadcast IP For Gateway
459    [Documentation]  Configure broadcast IP for gateway and expect an error.
460    [Tags]  Configure_Broadcast_IP_For_Gateway
461    [Template]  Add IP Address
462    [Teardown]  Clear IP Settings On Fail  ${test_ipv4_addr}
463
464    # ip               subnet_mask          gateway          valid_status_codes
465    ${test_ipv4_addr}  ${test_subnet_mask}  ${broadcast_ip}  ${HTTP_BAD_REQUEST}
466
467Configure Null Value For DNS Server
468    [Documentation]  Configure null value for DNS server and expect an error.
469    [Tags]  Configure_Null_Value_For_DNS_Server
470    [Setup]  DNS Test Setup Execution
471    [Teardown]  Run Keywords
472    ...  Configure Static Name Servers  AND  Test Teardown Execution
473
474    Configure Static Name Servers  ${null_value}  ${HTTP_BAD_REQUEST}
475
476Configure Empty Value For DNS Server
477    [Documentation]  Configure empty value for DNS server and expect an error.
478    [Tags]  Configure_Empty_Value_For_DNS_Server
479    [Setup]  DNS Test Setup Execution
480    [Teardown]  Run Keywords
481    ...  Configure Static Name Servers  AND  Test Teardown Execution
482
483    Configure Static Name Servers  ${empty_dictionary}  ${HTTP_BAD_REQUEST}
484
485Configure String Value For DNS Server
486    [Documentation]  Configure string value for DNS server and expect an error.
487    [Tags]  Configure_String_Value_For_DNS_Server
488    [Setup]  DNS Test Setup Execution
489    [Teardown]  Run Keywords
490    ...  Configure Static Name Servers  AND  Test Teardown Execution
491
492    Configure Static Name Servers  ${string_value}  ${HTTP_BAD_REQUEST}
493
494Modify IPv4 Address And Verify
495    [Documentation]  Modify IP address via Redfish and verify.
496    [Tags]  Modify_IPv4_Address_And_Verify
497    [Teardown]  Run Keywords
498    ...  Delete IP Address  ${test_ipv4_addr2}  AND  Test Teardown Execution
499
500     Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
501
502     Update IP Address  ${test_ipv4_addr}  ${test_ipv4_addr2}  ${test_subnet_mask}  ${test_gateway}
503
504Verify Modifying IP Address Multiple Times
505    [Documentation]  Verify modifying IP address multiple times.
506    [Tags]  Verify_Modifying_IP_Address_Multiple_Times
507    [Teardown]  Run Keywords
508    ...  Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown Execution
509
510    Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
511    Update IP Address  ${test_ipv4_addr}  ${test_ipv4_addr2}  ${test_subnet_mask}  ${test_gateway}
512    Update IP Address  ${test_ipv4_addr2}  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
513
514Configure Invalid Values For DNS Server
515    [Documentation]  Configure invalid values for DNS server and expect an error.
516    [Tags]  Configure_Invalid_Values_For_DNS_Server
517    [Setup]  DNS Test Setup Execution
518    [Template]  Configure Static Name Servers
519    [Teardown]  Run Keywords
520    ...  Configure Static Name Servers  AND  Test Teardown Execution
521
522     # static_name_servers        valid_status_codes
523      0xa.0xb.0xc.0xd             ${HTTP_BAD_REQUEST}
524      10.-7.-7.-7                 ${HTTP_BAD_REQUEST}
525      10.3.36                     ${HTTP_BAD_REQUEST}
526      @@@.%%.44.11                ${HTTP_BAD_REQUEST}
527
528
529Config Multiple DNS Servers And Verify
530    [Documentation]  Config multiple DNS servers and verify.
531    [Tags]  Config_Multiple_DNS_Servers_And_Verify
532    [Setup]  DNS Test Setup Execution
533    [Teardown]  Run Keywords
534    ...  Configure Static Name Servers  AND  Test Teardown Execution
535
536     @{list_name_servers}=  Create List  10.5.5.10  10.20.5.10  10.5.6.7
537     Configure Static Name Servers  ${list_name_servers}
538     Verify CLI and Redfish Nameservers
539
540
541Configure And Verify Multiple Static IPv4 Addresses
542    [Documentation]  Configure multiple static ipv4 address via Redfish and verify.
543    [Tags]  Configure_And_Verify_Multiple_Static_IPv4_Addresses
544    [Teardown]  Run Keywords  Delete Multiple Static IPv4 Addresses  ${test_ipv4_addresses}
545    ...  AND  Test Teardown Execution
546
547    ${test_ipv4_addresses}=  Create List  ${test_ipv4_addr}  ${test_ipv4_addr2}
548    Configure Multiple Static IPv4 Addresses   ${test_ipv4_addresses}  ${test_subnet_mask}  ${test_gateway}
549
550
551Configure Multiple Static IPv4 Addresses And Check Persistency
552    [Documentation]  Configure multiple static ipv4 address via Redfish and check persistency.
553    [Tags]  Configure_Multiple_Static_IPv4_Addresses_And_Check_Persistency
554    [Teardown]  Run Keywords  Delete Multiple Static IPv4 Addresses  ${test_ipv4_addresses}
555    ...  AND  Test Teardown Execution
556
557    ${test_ipv4_addresses}=  Create List  ${test_ipv4_addr}  ${test_ipv4_addr2}
558    Configure Multiple Static IPv4 Addresses  ${test_ipv4_addresses}  ${test_subnet_mask}  ${test_gateway}
559
560    # Reboot BMC and verify persistency.
561    Redfish OBMC Reboot (off)  stack_mode=skip
562    Redfish.Login
563    FOR  ${ip}  IN  @{test_ipv4_addresses}
564      Verify IP And Netmask On BMC  ${ip}  ${test_subnet_mask}
565      Verify IP On Redfish URI  ${ip}
566    END
567
568
569Configure And Verify Multiple IPv4 Addresses
570    [Documentation]  Configure multiple IPv4 addresses and verify.
571    [Tags]  Configure_And_Verify_Multiple_IPv4_Addresses
572    [Teardown]  Run Keywords
573    ...  Delete IP Address  ${test_ipv4_addr}  AND  Delete IP Address  ${test_ipv4_addr2}
574    ...  AND  Test Teardown Execution
575
576    ${ip1}=  Create dictionary  Address=${test_ipv4_addr}
577    ...  SubnetMask=255.255.0.0  Gateway=${test_gateway}
578    ${ip2}=  Create dictionary  Address=${test_ipv4_addr2}
579    ...  SubnetMask=255.255.252.0  Gateway=${test_gateway}
580
581    ${empty_dict}=  Create Dictionary
582    ${patch_list}=  Create List
583    ${network_configurations}=  Get Network Configuration
584    ${num_entries}=  Get Length  ${network_configurations}
585
586    FOR  ${INDEX}  IN RANGE  0  ${num_entries}
587      Append To List  ${patch_list}  ${empty_dict}
588    END
589
590    # We need not check for existence of IP on BMC while adding.
591    Append To List  ${patch_list}  ${ip1}  ${ip2}
592    ${payload}=  Create Dictionary  IPv4StaticAddresses=${patch_list}
593    ${active_channel_config}=  Get Active Channel Config
594    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
595    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{payload}
596    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
597
598    # Note: Network restart takes around 15-18s after patch request processing.
599    Sleep  ${NETWORK_TIMEOUT}s
600    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
601    Verify IP On BMC  ${test_ipv4_addr}
602    Verify IP On BMC  ${test_ipv4_addr2}
603
604
605Config Multiple DNS Servers And Check Persistency
606    [Documentation]  Config multiple DNS and check persistency.
607    [Tags]  Config_Multiple_DNS_Servers_And_Check_Persistency
608    [Setup]  DNS Test Setup Execution
609    [Teardown]  Run Keywords
610    ...  Configure Static Name Servers  AND  Test Teardown Execution
611
612    @{list_name_servers}=  Create List  10.5.5.10  10.20.5.10  10.5.6.7
613    Configure Static Name Servers  ${list_name_servers}
614
615    # Reboot BMC and verify persistency.
616    Redfish OBMC Reboot (off)  stack_mode=skip
617    Redfish.Login
618    Verify CLI and Redfish Nameservers
619
620
621Configure Static IP Without Using Gateway And Verify
622    [Documentation]  Configure static IP without using gateway and verify error.
623    [Tags]  Configure_Static_IP_Without_Using_Gateway_And_Verify
624
625    ${ip}=  Create dictionary  Address=${test_ipv4_addr}
626    ...  SubnetMask=${test_subnet_mask}
627    ${empty_dict}=  Create Dictionary
628    ${patch_list}=  Create List
629    ${network_configurations}=  Get Network Configuration
630
631    ${num_entries}=  Get Length  ${network_configurations}
632    FOR  ${INDEX}  IN RANGE  0  ${num_entries}
633      Append To List  ${patch_list}  ${empty_dict}
634    END
635
636    # We need not check for existence of IP on BMC while adding.
637    Append To List  ${patch_list}  ${ip}
638    ${payload}=  Create Dictionary  IPv4StaticAddresses=${patch_list}
639    ${active_channel_config}=  Get Active Channel Config
640    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
641    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
642    ...  body=&{payload}  valid_status_codes=[${HTTP_BAD_REQUEST}]
643
644
645Test Network Response On Specified Host State
646    [Documentation]  Verifying the BMC network response when host is on and off.
647    [Tags]  Test_Network_Response_On_Specified_Host_State
648    [Template]  Verify Network Response On Specified Host State
649
650    # host_state
651    on
652    off
653
654
655*** Keywords ***
656
657Test Setup Execution
658    [Documentation]  Test setup execution.
659
660    Redfish.Login
661
662    @{network_configurations}=  Get Network Configuration
663    Set Test Variable  @{network_configurations}
664
665    # Get BMC IP address and prefix length.
666    ${ip_data}=  Get BMC IP Info
667    Set Test Variable  ${ip_data}
668
669
670Verify Netmask On BMC
671    [Documentation]  Verify netmask on BMC.
672    [Arguments]  ${netmask}
673
674    # Description of the argument(s):
675    # netmask  netmask value to be verified.
676
677    ${prefix_length}=  Netmask Prefix Length  ${netmask}
678
679    Should Contain Match  ${ip_data}  */${prefix_length}
680    ...  msg=Prefix length does not exist.
681
682Verify IP And Netmask On BMC
683    [Documentation]  Verify IP and netmask on BMC.
684    [Arguments]  ${ip}  ${netmask}
685
686    # Description of the argument(s):
687    # ip       IP address to be verified.
688    # netmask  netmask value to be verified.
689
690    ${prefix_length}=  Netmask Prefix Length  ${netmask}
691    @{ip_data}=  Get BMC IP Info
692
693    ${ip_with_netmask}=  Catenate  ${ip}/${prefix_length}
694    Should Contain  ${ip_data}  ${ip_with_netmask}
695    ...  msg=IP and netmask pair does not exist.
696
697Test Teardown Execution
698    [Documentation]  Test teardown execution.
699
700    FFDC On Test Case Fail
701    Redfish.Logout
702
703Clear IP Settings On Fail
704    [Documentation]  Clear IP settings on fail.
705    [Arguments]  ${ip}
706
707    # Description of argument(s):
708    # ip  IP address to be deleted.
709
710    Run Keyword If  '${TEST STATUS}' == 'FAIL'
711    ...  Delete IP Address  ${ip}
712
713    Test Teardown Execution
714
715Verify CLI and Redfish Nameservers
716    [Documentation]  Verify that nameservers obtained via Redfish do not
717    ...  match those found in /etc/resolv.conf.
718
719    ${active_channel_config}=  Get Active Channel Config
720    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
721
722    ${redfish_nameservers}=  Redfish.Get Attribute
723    ...  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  StaticNameServers
724    ${resolve_conf_nameservers}=  CLI Get Nameservers
725    Rqprint Vars  redfish_nameservers  resolve_conf_nameservers
726
727    List Should Contain Sub List  ${resolve_conf_nameservers}  ${redfish_nameservers}
728    ...  msg=The nameservers obtained via Redfish do not match those found in /etc/resolv.conf.
729
730Suite Setup Execution
731    [Documentation]  Do suite setup execution.
732
733    # - Get DHCP IPv4 enabled/disabled status from redfish managers URI
734    # - If DHCP IPv4 is enabled ,
735    #   - Get DHCP IPv4 settings - ip address, gateway, subnetmask
736    #   - And set the same as static IP address
737
738    Redfish.Login
739    ${DHCPEnabled}=  Get IPv4 DHCP Enabled Status   ${CHANNEL_NUMBER}
740    Set Suite Variable  ${DHCPEnabled}
741
742    ${ip_addr}  ${gateway}  ${subnetmask}=  Run Keyword If  ${DHCPEnabled}==True
743    ...   Get DHCP IP Info
744
745    Run Keyword If  ${DHCPEnabled}==True
746    ...  Add IP Address  ${ip_addr}  ${subnetmask}  ${gateway}
747
748    ${test_gateway}=  Get BMC Default Gateway
749    Set Suite Variable  ${test_gateway}
750
751
752Suite Teardown Execution
753    [Documentation]  Do suite teardown execution.
754
755    # - If the DHCP IPv4 is enabled before suite setup execution
756    #   - Restore the DHCP IPv4 to enabled state
757
758    Redfish.Login
759    Run Keyword If  ${DHCPEnabled}==True
760    ...  Enable IPv4 DHCP Settings
761
762
763Configure Multiple Static IPv4 Addresses
764    [Documentation]  Configure multiple static ipv4 address via Redfish and verify.
765    [Arguments]  ${ip_addreses}  ${subnet_mask}  ${gateway}
766
767    # Description of argument(s):
768    # ip_addreses         A list of IP addresses to be added (e.g.["10.7.7.7"]).
769    # subnet_mask         Subnet mask for the IP to be added (e.g. "255.255.0.0").
770    # gateway             Gateway for the IP to be added (e.g. "10.7.7.1").
771
772    FOR  ${ip}  IN   @{ip_addreses}
773       Add IP Address  ${ip}  ${subnet_mask}  ${gateway}
774    END
775    Validate Network Config On BMC
776
777
778Delete Multiple Static IPv4 Addresses
779    [Documentation]  Delete multiple static ipv4 address via Redfish.
780    [Arguments]  ${ip_addreses}
781
782    # Description of argument(s):
783    # ip_addreses         A list of IP addresses to be deleted (e.g.["10.7.7.7"]).
784
785    FOR  ${ip}  IN   @{ip_addreses}
786       Delete IP Address  ${ip}
787    END
788    Validate Network Config On BMC
789
790Verify Network Response On Specified Host State
791    [Documentation]  Verifying the BMC network response when host is on and off.
792    [Arguments]  ${host_state}
793
794    # Description of argument(s):
795    # host_state   if host_state is on then host is booted to operating system.
796    #              if host_state is off then host is power off.
797    #              (eg. on, off).
798
799    ${active_channel_config}=  Get Active Channel Config
800    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
801
802    Run Keyword If  '${host_state}' == 'on'
803    ...    Redfish Power On  stack_mode=skip
804    ...  ELSE
805    ...    Redfish Power off  stack_mode=skip
806
807    Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
808    Ping Host  ${OPENBMC_HOST}
809
810
811Verify IP On Redfish URI
812    [Documentation]  Verify given IP on redfish URI.
813    [Arguments]  ${ip_address}
814
815    # Description of argument(s):
816    # ip_address   Configured IP address which need to verified.
817
818    ${network_configurations}=  Get Network Configuration
819
820    FOR  ${network_configuration}  IN  @{network_configurations}
821        ${ip_found}=  Set Variable If  '${network_configuration['Address']}' == '${ip_address}'  ${True}
822        ...  ${False}
823        Exit For Loop If  ${ip_found}
824    END
825    Run Keyword If  '${ip_found}' == '${False}'
826    ...  Fail  msg=Configured IP address not found on EthernetInterface URI.
827
828
829Enable IPv4 DHCP Settings
830    [Documentation]  Set IPv4 DHCP enabled status true/false in redfish URI.
831    [Arguments]  ${status}=${True}
832
833    # Description of argument(s):
834    # status   IPv4 DHCPEnabled status which needs to be set.
835    #          (e.g. True or False)
836
837    ${active_channel_config}=  Get Active Channel Config
838    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
839    ${DHCPv4}=  Create Dictionary  DHCPEnabled=${status}
840
841    ${payload}=  Create Dictionary  DHCPv4=${DHCPv4}
842    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
843    ...  body=&{payload}  valid_status_codes=[${HTTP_NO_CONTENT}, ${HTTP_OK}]
844
845    Sleep  ${NETWORK_TIMEOUT}s
846    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
847