xref: /openbmc/openbmc-test-automation/redfish/managers/test_bmc_ipv6.robot (revision 57c1a669d8b6805c30f4eb55400e65f203bf5b72)
1*** Settings ***
2Documentation  Network interface IPv6 configuration and verification
3               ...  tests.
4
5Resource       ../../lib/bmc_redfish_resource.robot
6Resource       ../../lib/openbmc_ffdc.robot
7Resource       ../../lib/bmc_ipv6_utils.robot
8Resource       ../../lib/external_intf/vmi_utils.robot
9Library        ../../lib/bmc_network_utils.py
10Library        Collections
11
12Test Setup     Test Setup Execution
13Test Teardown  Test Teardown Execution
14Suite Setup    Suite Setup Execution
15
16Test Tags     BMC_IPv6
17
18*** Variables ***
19${test_ipv6_addr}            2001:db8:3333:4444:5555:6666:7777:8888
20${test_ipv6_invalid_addr}    2001:db8:3333:4444:5555:6666:7777:JJKK
21${test_ipv6_addr1}           2001:db8:3333:4444:5555:6666:7777:9999
22
23# Valid prefix length is a integer ranges from 1 to 128.
24${test_prefix_length}        64
25${ipv6_gw_addr}              2002:903:15F:32:9:3:32:1
26${prefix_length_def}         None
27${invalid_staticv6_gateway}  9.41.164.1
28
29*** Test Cases ***
30
31Get IPv6 Address And Verify
32    [Documentation]  Get IPv6 Address And Verify.
33    [Tags]  Get_IPv6_Address_And_Verify
34
35    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
36      Verify IPv6 On BMC  ${ipv6_network_configuration['Address']}
37    END
38
39
40Get PrefixLength And Verify
41    [Documentation]  Get IPv6 prefix length and verify.
42    [Tags]  Get_PrefixLength_And_Verify
43
44    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
45      Verify IPv6 On BMC  ${ipv6_network_configuration['PrefixLength']}
46    END
47
48
49Get IPv6 Default Gateway And Verify
50    [Documentation]  Get IPv6 default gateway and verify.
51    [Tags]  Get_IPv6_Default_Gateway_And_Verify
52
53    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
54    ${ipv6_gateway}=  Get From Dictionary  ${resp.dict}  IPv6DefaultGateway
55    Verify IPv6 Default Gateway On BMC  ${ipv6_gateway}
56
57
58Verify All Configured IPv6 And PrefixLength On BMC
59    [Documentation]  Verify IPv6 address and its prefix length on BMC.
60    [Tags]  Verify_All_Configured_IPv6_And_PrefixLength_On_BMC
61
62    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
63      Verify IPv6 And PrefixLength  ${ipv6_network_configuration['Address']}
64      ...  ${ipv6_network_configuration['PrefixLength']}
65    END
66
67
68Configure IPv6 Address And Verify
69    [Documentation]  Configure IPv6 address and verify.
70    [Tags]  Configure_IPv6_Address_And_Verify
71    [Teardown]  Run Keywords
72    ...  Delete IPv6 Address  ${test_ipv6_addr}  AND  Test Teardown Execution
73    [Template]  Configure IPv6 Address On BMC
74
75
76    # IPv6 address     Prefix length
77    ${test_ipv6_addr}  ${test_prefix_length}
78
79
80Delete IPv6 Address And Verify
81    [Documentation]  Delete IPv6 address and verify.
82    [Tags]  Delete_IPv6_Address_And_Verify
83
84    Configure IPv6 Address On BMC  ${test_ipv6_addr}  ${test_prefix_length}
85
86    Delete IPv6 Address  ${test_ipv6_addr}
87
88
89
90Modify IPv6 Address And Verify
91    [Documentation]  Modify IPv6 address and verify.
92    [Tags]  Modify_IPv6_Address_And_Verify
93    [Teardown]  Run Keywords
94    ...  Delete IPv6 Address  ${test_ipv6_addr1}  AND  Test Teardown Execution
95
96    Configure IPv6 Address On BMC  ${test_ipv6_addr}  ${test_prefix_length}
97
98    Modify IPv6 Address  ${test_ipv6_addr}  ${test_ipv6_addr1}  ${test_prefix_length}
99
100
101Verify Persistency Of IPv6 After BMC Reboot
102    [Documentation]  Verify persistency of IPv6 after BMC reboot.
103    [Tags]  Verify_Persistency_Of_IPv6_After_BMC_Reboot
104    [Teardown]  Run Keywords
105    ...  Delete IPv6 Address  ${test_ipv6_addr}  AND  Test Teardown Execution
106
107    Configure IPv6 Address On BMC  ${test_ipv6_addr}  ${test_prefix_length}
108
109    Redfish OBMC Reboot (off)  stack_mode=skip
110
111    # Verifying persistency of IPv6.
112    Verify IPv6 On BMC  ${test_ipv6_addr}
113
114
115Enable SLAACv6 On BMC And Verify
116    [Documentation]  Enable SLAACv6 on BMC and verify.
117    [Tags]  Enable_SLAACv6_On_BMC_And_Verify
118
119    Set SLAACv6 Configuration State And Verify  ${True}
120
121
122Enable DHCPv6 Property On BMC And Verify
123    [Documentation]  Enable DHCPv6 property on BMC and verify.
124    [Tags]  Enable_DHCPv6_Property_On_BMC_And_Verify
125
126    Set And Verify DHCPv6 Property  Enabled
127
128
129Disable DHCPv6 Property On BMC And Verify
130    [Documentation]  Disable DHCPv6 property on BMC and verify.
131    [Tags]  Disable_DHCPv6_Property_On_BMC_And_Verify
132
133    Set And Verify DHCPv6 Property  Disabled
134
135
136Configure Invalid Static IPv6 And Verify
137    [Documentation]  Configure invalid static IPv6 and verify.
138    [Tags]  Configure_Invalid_Static_IPv6_And_Verify
139    [Template]  Configure IPv6 Address On BMC
140
141    #invalid_ipv6         prefix length           valid_status_code
142    ${ipv4_hexword_addr}  ${test_prefix_length}   ${HTTP_BAD_REQUEST}
143
144
145Configure IPv6 Static Default Gateway And Verify
146    [Documentation]  Configure IPv6 static default gateway and verify.
147    [Tags]  Configure_IPv6_Static_Default_Gateway_And_Verify
148    [Template]  Configure IPv6 Static Default Gateway On BMC
149
150    # static_def_gw              prefix length           valid_status_code
151    ${ipv6_gw_addr}              ${prefix_length_def}    ${HTTP_OK}
152    ${invalid_staticv6_gateway}  ${test_prefix_length}   ${HTTP_BAD_REQUEST}
153
154
155Modify Static Default Gateway And Verify
156    [Documentation]  Modify static default gateway and verify.
157    [Tags]  Modify_Static_Default_Gateway_And_Verify
158    [Setup]  Configure IPv6 Static Default Gateway On BMC  ${ipv6_gw_addr}  ${prefix_length_def}
159
160    Modify IPv6 Static Default Gateway On BMC  ${test_ipv6_addr1}  ${prefix_length_def}  ${HTTP_OK}  ${ipv6_gw_addr}
161
162
163*** Keywords ***
164
165Suite Setup Execution
166    [Documentation]  Do suite setup execution.
167
168    ${active_channel_config}=  Get Active Channel Config
169    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
170
171    Set Suite variable  ${ethernet_interface}
172
173
174Test Setup Execution
175    [Documentation]  Test setup execution.
176
177    Redfish.Login
178
179    @{ipv6_network_configurations}=  Get IPv6 Network Configuration
180    Set Test Variable  @{ipv6_network_configurations}
181
182    # Get BMC IPv6 address and prefix length.
183    ${ipv6_data}=  Get BMC IPv6 Info
184    Set Test Variable  ${ipv6_data}
185
186
187Test Teardown Execution
188    [Documentation]  Test teardown execution.
189
190    FFDC On Test Case Fail
191    Redfish.Logout
192
193
194Get IPv6 Network Configuration
195    [Documentation]  Get Ipv6 network configuration.
196    # Sample output:
197    # {
198    #  "@odata.id": "/redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/eth0",
199    #  "@odata.type": "#EthernetInterface.v1_4_1.EthernetInterface",
200    #   "DHCPv4": {
201    #    "DHCPEnabled": false,
202    #    "UseDNSServers": false,
203    #    "UseDomainName": true,
204    #    "UseNTPServers": false
205    #  },
206    #  "DHCPv6": {
207    #    "OperatingMode": "Disabled",
208    #    "UseDNSServers": false,
209    #    "UseDomainName": true,
210    #    "UseNTPServers": false
211    #  },
212    #  "Description": "Management Network Interface",
213    #  "FQDN": "localhost",
214    #  "HostName": "localhost",
215    #  "IPv4Addresses": [
216    #    {
217    #      "Address": "xx.xx.xx.xx",
218    #      "AddressOrigin": "Static",
219    #      "Gateway": "xx.xx.xx.1",
220    #      "SubnetMask": "xx.xx.xx.0"
221    #    },
222    #    {
223    #      "Address": "169.254.xx.xx",
224    #      "AddressOrigin": "IPv4LinkLocal",
225    #      "Gateway": "0.0.0.0",
226    #      "SubnetMask": "xx.xx.0.0"
227    #    },
228    #  ],
229    #  "IPv4StaticAddresses": [
230    #    {
231    #      "Address": "xx.xx.xx.xx",
232    #      "AddressOrigin": "Static",
233    #      "Gateway": "xx.xx.xx.1",
234    #      "SubnetMask": "xx.xx.0.0"
235    #    }
236    # }
237    #  ],
238    #  "IPv6AddressPolicyTable": [],
239    #  "IPv6Addresses": [
240    #    {
241    #      "Address": "fe80::xxxx:xxxx:xxxx:xxxx",
242    #      "AddressOrigin": "LinkLocal",
243    #      "AddressState": null,
244    #      "PrefixLength": xx
245    #    }
246    #  ],
247    #  "IPv6DefaultGateway": "",
248    #  "IPv6StaticAddresses": [
249    #    { "Address": "xxxx:xxxx:xxxx:xxxx::xxxx",
250    #      "AddressOrigin": "Static",
251    #      "AddressState": null,
252    #      "PrefixLength": xxx
253    #    }
254    #  ],
255    #  "Id": "eth0",
256    #  "InterfaceEnabled": true,
257    #  "LinkStatus": "LinkUp",
258    #  "MACAddress": "xx:xx:xx:xx:xx:xx",
259    #  "Name": "Manager Ethernet Interface",
260    #  "NameServers": [],
261    #  "SpeedMbps": 0,
262    #  "StaticNameServers": [],
263    #  "Status": {
264    #    "Health": "OK",
265    #    "HealthRollup": "OK",
266    #    "State": "Enabled"
267    #  },
268    #  "VLANs": {
269    #    "@odata.id": "/redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/eth0/VLANs"
270
271
272    ${active_channel_config}=  Get Active Channel Config
273    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${active_channel_config['${CHANNEL_NUMBER}']['name']}
274
275    @{ipv6_network_configurations}=  Get From Dictionary  ${resp.dict}  IPv6StaticAddresses
276    RETURN  @{ipv6_network_configurations}
277
278
279Verify IPv6 And PrefixLength
280    [Documentation]  Verify IPv6 address and prefix length on BMC.
281    [Arguments]  ${ipv6_addr}  ${prefix_len}
282
283    # Description of the argument(s):
284    # ipv6_addr   IPv6 address to be verified.
285    # prefix_len  PrefixLength value to be verified.
286
287    # Catenate IPv6 address and its prefix length.
288    ${ipv6_with_prefix}=  Catenate  ${ipv6_addr}/${prefix_len}
289
290    # Get IPv6 address details on BMC using IP command.
291    @{ip_data}=  Get BMC IPv6 Info
292
293    # Verify if IPv6 and prefix length is configured on BMC.
294
295    Should Contain  ${ip_data}  ${ipv6_with_prefix}
296    ...  msg=IPv6 and prefix length pair does not exist.
297
298
299Configure IPv6 Address On BMC
300    [Documentation]  Add IPv6 Address on BMC.
301    [Arguments]  ${ipv6_addr}  ${prefix_len}  ${valid_status_codes}=${HTTP_OK}
302
303    # Description of argument(s):
304    # ipv6_addr           IPv6 address to be added (e.g. "2001:EEEE:2222::2022").
305    # prefix_len          Prefix length for the IPv6 to be added
306    #                     (e.g. "64").
307    # valid_status_codes  Expected return code from patch operation
308    #                     (e.g. "200").
309
310    ${prefix_length}=  Convert To Integer  ${prefix_len}
311    ${empty_dict}=  Create Dictionary
312    ${ipv6_data}=  Create Dictionary  Address=${ipv6_addr}
313    ...  PrefixLength=${prefix_length}
314
315    ${patch_list}=  Create List
316
317    # Get existing static IPv6 configurations on BMC.
318    ${ipv6_network_configurations}=  Get IPv6 Network Configuration
319    ${num_entries}=  Get Length  ${ipv6_network_configurations}
320
321    FOR  ${INDEX}  IN RANGE  0  ${num_entries}
322      Append To List  ${patch_list}  ${empty_dict}
323    END
324
325    ${valid_status_codes}=  Set Variable If  '${valid_status_codes}' == '${HTTP_OK}'
326    ...  ${HTTP_OK},${HTTP_NO_CONTENT}
327    ...  ${valid_status_codes}
328
329    # We need not check for existence of IPv6 on BMC while adding.
330    Append To List  ${patch_list}  ${ipv6_data}
331    ${data}=  Create Dictionary  IPv6StaticAddresses=${patch_list}
332
333    ${active_channel_config}=  Get Active Channel Config
334    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
335
336    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{data}
337    ...  valid_status_codes=[${valid_status_codes}]
338
339    Return From Keyword If  '${valid_status_codes}' != '${HTTP_OK},${HTTP_NO_CONTENT}'
340
341    # Note: Network restart takes around 15-18s after patch request processing.
342    Sleep  ${NETWORK_TIMEOUT}s
343    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
344
345    Verify IPv6 And PrefixLength  ${ipv6_addr}  ${prefix_len}
346
347    # Verify if existing static IPv6 addresses still exist.
348    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
349      Verify IPv6 On BMC  ${ipv6_network_configuration['Address']}
350    END
351
352    Validate IPv6 Network Config On BMC
353
354
355Validate IPv6 Network Config On BMC
356    [Documentation]  Check that IPv6 network info obtained via redfish matches info
357    ...              obtained via CLI.
358    @{ipv6_network_configurations}=  Get IPv6 Network Configuration
359    ${ipv6_data}=  Get BMC IPv6 Info
360    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
361      Should Contain Match  ${ipv6_data}  ${ipv6_network_configuration['Address']}/*
362      ...  msg=IPv6 address does not exist.
363    END
364
365
366Delete IPv6 Address
367    [Documentation]  Delete IPv6 address of BMC.
368    [Arguments]  ${ipv6_addr}
369    ...          ${valid_status_codes}=[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}]
370
371    # Description of argument(s):
372    # ipv6_addr           IPv6 address to be deleted (e.g. "2001:1234:1234:1234::1234").
373    # valid_status_codes  Expected return code from patch operation
374    #                     (e.g. "200").  See prolog of rest_request
375    #                     method in redfish_plus.py for details.
376
377    ${empty_dict}=  Create Dictionary
378    ${patch_list}=  Create List
379
380    @{ipv6_network_configurations}=  Get IPv6 Network Configuration
381    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
382        IF  '${ipv6_network_configuration['Address']}' == '${ipv6_addr}'
383            Append To List  ${patch_list}  ${null}
384        ELSE
385            Append To List  ${patch_list}  ${empty_dict}
386        END
387    END
388
389    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
390    ...  ${patch_list}  ${null}  msg=${ipv6_addr} does not exist on BMC
391    Pass Execution If  ${ip_found} == ${False}  ${ipv6_addr} does not exist on BMC
392
393    # Run patch command only if given IP is found on BMC
394    ${data}=  Create Dictionary  IPv6StaticAddresses=${patch_list}
395
396    ${active_channel_config}=  Get Active Channel Config
397    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
398
399    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{data}
400    ...  valid_status_codes=${valid_status_codes}
401
402    # Note: Network restart takes around 15-18s after patch request processing
403    Sleep  ${NETWORK_TIMEOUT}s
404    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
405
406    # IPv6 address that is deleted should not be there on BMC.
407    ${delete_status}=  Run Keyword And Return Status  Verify IPv6 On BMC  ${ipv6_addr}
408    IF  '${valid_status_codes}' == '[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}]'
409        Should Be True  '${delete_status}' == '${False}'
410    ELSE
411        Should Be True  '${delete_status}' == '${True}'
412    END
413
414    Validate IPv6 Network Config On BMC
415
416
417Modify IPv6 Address
418    [Documentation]  Modify and verify IPv6 address of BMC.
419    [Arguments]  ${ipv6}  ${new_ipv6}  ${prefix_len}
420    ...  ${valid_status_codes}=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
421
422    # Description of argument(s):
423    # ipv6                  IPv6 address to be replaced (e.g. "2001:AABB:CCDD::AAFF").
424    # new_ipv6              New IPv6 address to be configured.
425    # prefix_len            Prefix length value (Range 1 to 128).
426    # valid_status_codes    Expected return code from patch operation
427    #                       (e.g. "200", "201").
428
429    ${empty_dict}=  Create Dictionary
430    ${patch_list}=  Create List
431    ${prefix_length}=  Convert To Integer  ${prefix_len}
432    ${ipv6_data}=  Create Dictionary
433    ...  Address=${new_ipv6}  PrefixLength=${prefix_length}
434
435    # Sample IPv6 network configurations:
436    #  "IPv6AddressPolicyTable": [],
437    #  "IPv6Addresses": [
438    #    {
439    #      "Address": "X002:db8:0:2::XX0",
440    #      "AddressOrigin": "DHCPv6",
441    #      "PrefixLength": 128
442    #    },
443    #    {
444    #      "Address": “X002:db8:0:2:a94:XXff:fe82:XXXX",
445    #      "AddressOrigin": "SLAAC",
446    #      "PrefixLength": 64
447    #    },
448    #    {
449    #      "Address": “Y002:db8:0:2:a94:efff:fe82:5000",
450    #      "AddressOrigin": "Static",
451    #      "PrefixLength": 56
452    #    },
453    #    {
454    #      "Address": “Z002:db8:0:2:a94:efff:fe82:5000",
455    #      "AddressOrigin": "Static",
456    #      "PrefixLength": 56
457    #    },
458    #    {
459    #      "Address": “Xe80::a94:efff:YYYY:XXXX",
460    #      "AddressOrigin": "LinkLocal",
461    #      "PrefixLength": 64
462    #    },
463    #    {
464    #     "Address": “X002:db8:1:2:eff:233:fee:546",
465    #      "AddressOrigin": "Static",
466    #      "PrefixLength": 56
467    #    }
468    #  ],
469    #  "IPv6DefaultGateway": “XXXX::ab2e:80fe:87df:XXXX”,
470    #  "IPv6StaticAddresses": [
471    #    {
472    #      "Address": “X002:db8:0:2:a94:efff:fe82:5000",
473    #      "PrefixLength": 56
474    #    },
475    #    {
476    #      "Address": “Y002:db8:0:2:a94:efff:fe82:5000",
477    #      "PrefixLength": 56
478    #    },
479    #    {
480    #      "Address": “Z002:db8:1:2:eff:233:fee:546",
481    #      "PrefixLength": 56
482    #    }
483    #  ],
484    #  "IPv6StaticDefaultGateways": [],
485
486    # Find the position of IPv6 address to be modified.
487    @{ipv6_network_configurations}=  Get IPv6 Network Configuration
488    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
489      IF  '${ipv6_network_configuration['Address']}' == '${ipv6}'
490          Append To List  ${patch_list}  ${ipv6_data}
491      ELSE
492          Append To List  ${patch_list}  ${empty_dict}
493      END
494    END
495
496    # Modify the IPv6 address only if given IPv6 is found
497    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
498    ...  ${patch_list}  ${ipv6_data}  msg=${ipv6} does not exist on BMC
499    Pass Execution If  ${ip_found} == ${False}  ${ipv6} does not exist on BMC
500
501    ${data}=  Create Dictionary  IPv6StaticAddresses=${patch_list}
502
503    ${active_channel_config}=  Get Active Channel Config
504    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
505
506    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
507    ...  body=&{data}  valid_status_codes=${valid_status_codes}
508
509    # Note: Network restart takes around 15-18s after patch request processing.
510    Sleep  ${NETWORK_TIMEOUT}s
511    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
512
513    # Verify if new IPv6 address is configured on BMC.
514    Verify IPv6 On BMC  ${new_ipv6}
515
516    # Verify if old IPv6 address is erased.
517    ${cmd_status}=  Run Keyword And Return Status
518    ...  Verify IPv6 On BMC  ${ipv6}
519    Should Be Equal  ${cmd_status}  ${False}  msg=Old IPv6 address is not deleted.
520
521    Validate IPv6 Network Config On BMC
522
523
524Set SLAACv6 Configuration State And Verify
525    [Documentation]  Set SLAACv6 configuration state and verify.
526    [Arguments]  ${slaac_state}  ${valid_status_codes}=[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}]
527
528    # Description of argument(s):
529    # slaac_state         SLAACv6 state('True' or 'False').
530    # valid_status_code   Expected valid status codes.
531
532    ${active_channel_config}=  Get Active Channel Config
533    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
534
535    ${data}=  Set Variable If  ${slaac_state} == ${False}  ${DISABLE_SLAAC}  ${ENABLE_SLAAC}
536    ${resp}=  Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
537    ...  body=${data}  valid_status_codes=${valid_status_codes}
538
539    # Verify SLAACv6 is set correctly.
540    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
541    ${slaac_verify}=  Get From Dictionary  ${resp.dict}  StatelessAddressAutoConfig
542
543    IF  '${slaac_verify['IPv6AutoConfigEnabled']}' != '${slaac_state}'
544        Fail  msg=SLAACv6 not set properly.
545    END
546
547
548Set And Verify DHCPv6 Property
549    [Documentation]  Set DHCPv6 attribute and verify.
550    [Arguments]  ${dhcpv6_operating_mode}=${Disabled}
551
552    # Description of argument(s):
553    # dhcpv6_operating_mode    Enabled if user wants to enable DHCPv6('Enabled' or 'Disabled').
554
555    ${data}=  Set Variable If  '${dhcpv6_operating_mode}' == 'Disabled'  ${DISABLE_DHCPv6}  ${ENABLE_DHCPv6}
556    ${active_channel_config}=  Get Active Channel Config
557    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
558
559    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
560    ...  body=${data}  valid_status_codes=[${HTTP_OK},${HTTP_NO_CONTENT}]
561
562    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
563    ${dhcpv6_verify}=  Get From Dictionary  ${resp.dict}  DHCPv6
564
565    Should Be Equal  '${dhcpv6_verify['OperatingMode']}'  '${dhcpv6_operating_mode}'
566
567
568Get IPv6 Static Default Gateway
569    [Documentation]  Get IPv6 static default gateway.
570
571    ${active_channel_config}=  Get Active Channel Config
572    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${active_channel_config['${CHANNEL_NUMBER}']['name']}
573
574    @{ipv6_static_defgw_configurations}=  Get From Dictionary  ${resp.dict}  IPv6StaticDefaultGateways
575    RETURN  @{ipv6_static_defgw_configurations}
576
577Configure IPv6 Static Default Gateway On BMC
578    [Documentation]  Configure IPv6 static default gateway on BMC.
579    [Arguments]  ${ipv6_gw_addr}  ${prefix_length_def}
580    ...  ${valid_status_codes}=${HTTP_OK}
581    # Description of argument(s):
582    # ipv6_gw_addr          IPv6 Static Default Gateway address to be configured.
583    # prefix_len_def        Prefix length value (Range 1 to 128).
584    # valid_status_codes    Expected return code from patch operation
585    #                       (e.g. "200", "204".)
586
587    # Prefix Length is passed as None.
588    IF   '${prefix_length_def}' == '${None}'
589        ${ipv6_gw}=  Create Dictionary  Address=${ipv6_gw_addr}
590    ELSE
591        ${ipv6_gw}=  Create Dictionary  Address=${ipv6_gw_addr}  Prefix Length=${prefix_length_def}
592    END
593
594    ${ipv6_static_def_gw}=  Get IPv6 Static Default Gateway
595
596    ${num_entries}=  Get Length  ${ipv6_static_def_gw}
597
598    ${patch_list}=  Create List
599    ${empty_dict}=  Create Dictionary
600
601    FOR  ${INDEX}  IN RANGE  0  ${num_entries}
602      Append To List  ${patch_list}  ${empty_dict}
603    END
604
605    ${valid_status_codes}=  Set Variable If  '${valid_status_codes}' == '${HTTP_OK}'
606    ...  ${HTTP_OK},${HTTP_NO_CONTENT}
607    ...  ${valid_status_codes}
608
609    Append To List  ${patch_list}  ${ipv6_gw}
610    ${data}=  Create Dictionary  IPv6StaticDefaultGateways=${patch_list}
611
612    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
613    ...  body=${data}  valid_status_codes=[${valid_status_codes}]
614
615    # Verify the added static default gateway is present in Redfish Get Output.
616    ${ipv6_staticdef_gateway}=  Get IPv6 Static Default Gateway
617
618    ${ipv6_static_def_gw_list}=  Create List
619    FOR  ${ipv6_staticdef_gateway}  IN  @{ipv6_staticdef_gateway}
620        ${value}=    Get From Dictionary    ${ipv6_staticdef_gateway}    Address
621        Append To List  ${ipv6_static_def_gw_list}  ${value}
622    END
623
624    IF  '${valid_status_codes}' != '${HTTP_OK},${HTTP_NO_CONTENT}'
625        Should Not Contain  ${ipv6_static_def_gw_list}  ${ipv6_gw_addr}
626    ELSE
627        Should Contain  ${ipv6_static_def_gw_list}  ${ipv6_gw_addr}
628    END
629
630Modify Static Default Gateway
631    [Documentation]  Modify and verify IPv6 address of BMC.
632    [Arguments]  ${ipv6_gw_addr}  ${new_static_def_gw}  ${prefix_length}
633    ...  ${valid_status_codes}=[${HTTP_OK},${HTTP_ACCEPTED}]
634
635    # Description of argument(s):
636    # ipv6_gw_addr          IPv6 static default gateway address to be replaced (e.g. "2001:AABB:CCDD::AAFF").
637    # new_static_def_gw     New static default gateway address to be configured.
638    # prefix length         Prefix length value (Range 1 to 128).
639    # valid_status_codes    Expected return code from patch operation
640    #                       (e.g. "200", "204").
641
642    ${empty_dict}=  Create Dictionary
643    ${patch_list}=  Create List
644    # Prefix Length is passed as None.
645    IF   '${prefix_length_def}' == '${None}'
646        ${modified_ipv6_gw_addripv6_data}=  Create Dictionary  Address=${new_static_def_gw}
647    ELSE
648        ${modified_ipv6_gw_addripv6_data}=  Create Dictionary  Address=${new_static_def_gw}  Prefix Length=${prefix_length_def}
649    END
650
651    @{ipv6_static_def_gw_list}=  Get IPv6 Static Default Gateway
652
653    FOR  ${ipv6_static_def_gw}  IN  @{ipv6_static_def_gw_list}
654      IF  '${ipv6_static_def_gw['Address']}' == '${ipv6_gw_addr}'
655          Append To List  ${patch_list}  ${modified_ipv6_gw_addripv6_data}
656      ELSE
657          Append To List  ${patch_list}  ${empty_dict}
658      END
659    END
660
661    # Modify the IPv6 address only if given IPv6 static default gateway is found.
662    ${ip_static_def_gw_found}=  Run Keyword And Return Status  List Should Contain Value
663    ...  ${patch_list}  ${modified_ipv6_gw_addripv6_data}  msg=${ipv6_gw_addr} does not exist on BMC
664    Pass Execution If  ${ip_static_def_gw_found} == ${False}  ${ipv6_gw_addr} does not exist on BMC
665
666    ${data}=  Create Dictionary  IPv6StaticDefaultGateways=${patch_list}
667
668    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
669    ...  body=&{data}  valid_status_codes=${valid_status_codes}
670
671    ${ipv6_staticdef_gateway}=  Get IPv6 Static Default Gateway
672
673    ${ipv6_static_def_gw_list}=  Create List
674    FOR  ${ipv6_staticdef_gateway}  IN  @{ipv6_staticdef_gateway}
675        ${value}=    Get From Dictionary    ${ipv6_staticdef_gateway}    Address
676        Append To List  ${ipv6_static_def_gw_list}  ${value}
677    END
678
679    Should Contain  ${ipv6_static_def_gw_list}  ${new_static_def_gw}
680    # Verify if old static default gateway address is erased.
681    Should Not Contain  ${ipv6_static_def_gw_list}  ${ipv6_gw_addr}
682
683