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