xref: /openbmc/openbmc-test-automation/redfish/managers/test_bmc_ipv6.robot (revision 8cda5c3504bfbccdddcc70b7c462d44df5a43590)
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
26*** Test Cases ***
27
28Get IPv6 Address And Verify
29    [Documentation]  Get IPv6 Address And Verify.
30    [Tags]  Get_IPv6_Address_And_Verify
31
32    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
33      Verify IPv6 On BMC  ${ipv6_network_configuration['Address']}
34    END
35
36
37Get PrefixLength And Verify
38    [Documentation]  Get IPv6 prefix length and verify.
39    [Tags]  Get_PrefixLength_And_Verify
40
41    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
42      Verify IPv6 On BMC  ${ipv6_network_configuration['PrefixLength']}
43    END
44
45
46Get IPv6 Default Gateway And Verify
47    [Documentation]  Get IPv6 default gateway and verify.
48    [Tags]  Get_IPv6_Default_Gateway_And_Verify
49
50    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
51    ${ipv6_gateway}=  Get From Dictionary  ${resp.dict}  IPv6DefaultGateway
52    Verify IPv6 Default Gateway On BMC  ${ipv6_gateway}
53
54
55Verify All Configured IPv6 And PrefixLength On BMC
56    [Documentation]  Verify IPv6 address and its prefix length on BMC.
57    [Tags]  Verify_All_Configured_IPv6_And_PrefixLength_On_BMC
58
59    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
60      Verify IPv6 And PrefixLength  ${ipv6_network_configuration['Address']}
61      ...  ${ipv6_network_configuration['PrefixLength']}
62    END
63
64
65Configure IPv6 Address And Verify
66    [Documentation]  Configure IPv6 address and verify.
67    [Tags]  Configure_IPv6_Address_And_Verify
68    [Template]  Configure IPv6 Address On BMC
69
70
71    # IPv6 address     Prefix length
72    ${test_ipv6_addr}  ${test_prefix_length}
73
74
75Delete IPv6 Address And Verify
76    [Documentation]  Delete IPv6 address and verify.
77    [Tags]  Delete_IPv6_Address_And_Verify
78
79    Configure IPv6 Address On BMC  ${test_ipv6_addr}  ${test_prefix_length}
80
81    Delete IPv6 Address  ${test_ipv6_addr}
82
83
84
85Modify IPv6 Address And Verify
86    [Documentation]  Modify IPv6 address and verify.
87    [Tags]  Modify_IPv6_Address_And_Verify
88    [Teardown]  Run Keywords
89    ...  Delete IPv6 Address  ${test_ipv6_addr1}  AND  Test Teardown Execution
90
91    Configure IPv6 Address On BMC  ${test_ipv6_addr}  ${test_prefix_length}
92
93    Modify IPv6 Address  ${test_ipv6_addr}  ${test_ipv6_addr1}  ${test_prefix_length}
94
95
96Verify Persistency Of IPv6 After BMC Reboot
97    [Documentation]  Verify persistency of IPv6 after BMC reboot.
98    [Tags]  Verify_Persistency_Of_IPv6_After_BMC_Reboot
99    [Teardown]  Run Keywords
100    ...  Delete IPv6 Address  ${test_ipv6_addr}  AND  Test Teardown Execution
101
102    Configure IPv6 Address On BMC  ${test_ipv6_addr}  ${test_prefix_length}
103
104    Redfish OBMC Reboot (off)  stack_mode=skip
105
106    # Verifying persistency of IPv6.
107    Verify IPv6 On BMC  ${test_ipv6_addr}
108
109
110Enable SLAACv6 On BMC And Verify
111    [Documentation]  Enable SLAACv6 on BMC and verify.
112    [Tags]  Enable_SLAACv6_On_BMC_And_Verify
113
114    Set SLAACv6 Configuration State And Verify  ${True}
115
116
117Enable DHCPv6 Property On BMC And Verify
118    [Documentation]  Enable DHCPv6 property on BMC and verify.
119    [Tags]  Enable_DHCPv6_Property_On_BMC_And_Verify
120
121    Set And Verify DHCPv6 Property  Enabled
122
123
124*** Keywords ***
125
126Suite Setup Execution
127    [Documentation]  Do suite setup execution.
128
129    ${active_channel_config}=  Get Active Channel Config
130    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
131
132    Set Suite variable  ${ethernet_interface}
133
134
135Test Setup Execution
136    [Documentation]  Test setup execution.
137
138    Redfish.Login
139
140    @{ipv6_network_configurations}=  Get IPv6 Network Configuration
141    Set Test Variable  @{ipv6_network_configurations}
142
143    # Get BMC IPv6 address and prefix length.
144    ${ipv6_data}=  Get BMC IPv6 Info
145    Set Test Variable  ${ipv6_data}
146
147
148Test Teardown Execution
149    [Documentation]  Test teardown execution.
150
151    FFDC On Test Case Fail
152    Redfish.Logout
153
154
155Get IPv6 Network Configuration
156    [Documentation]  Get Ipv6 network configuration.
157    # Sample output:
158    # {
159    #  "@odata.id": "/redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/eth0",
160    #  "@odata.type": "#EthernetInterface.v1_4_1.EthernetInterface",
161    #   "DHCPv4": {
162    #    "DHCPEnabled": false,
163    #    "UseDNSServers": false,
164    #    "UseDomainName": true,
165    #    "UseNTPServers": false
166    #  },
167    #  "DHCPv6": {
168    #    "OperatingMode": "Disabled",
169    #    "UseDNSServers": false,
170    #    "UseDomainName": true,
171    #    "UseNTPServers": false
172    #  },
173    #  "Description": "Management Network Interface",
174    #  "FQDN": "localhost",
175    #  "HostName": "localhost",
176    #  "IPv4Addresses": [
177    #    {
178    #      "Address": "xx.xx.xx.xx",
179    #      "AddressOrigin": "Static",
180    #      "Gateway": "xx.xx.xx.1",
181    #      "SubnetMask": "xx.xx.xx.0"
182    #    },
183    #    {
184    #      "Address": "169.254.xx.xx",
185    #      "AddressOrigin": "IPv4LinkLocal",
186    #      "Gateway": "0.0.0.0",
187    #      "SubnetMask": "xx.xx.0.0"
188    #    },
189    #  ],
190    #  "IPv4StaticAddresses": [
191    #    {
192    #      "Address": "xx.xx.xx.xx",
193    #      "AddressOrigin": "Static",
194    #      "Gateway": "xx.xx.xx.1",
195    #      "SubnetMask": "xx.xx.0.0"
196    #    }
197    # }
198    #  ],
199    #  "IPv6AddressPolicyTable": [],
200    #  "IPv6Addresses": [
201    #    {
202    #      "Address": "fe80::xxxx:xxxx:xxxx:xxxx",
203    #      "AddressOrigin": "LinkLocal",
204    #      "AddressState": null,
205    #      "PrefixLength": xx
206    #    }
207    #  ],
208    #  "IPv6DefaultGateway": "",
209    #  "IPv6StaticAddresses": [
210    #    { "Address": "xxxx:xxxx:xxxx:xxxx::xxxx",
211    #      "AddressOrigin": "Static",
212    #      "AddressState": null,
213    #      "PrefixLength": xxx
214    #    }
215    #  ],
216    #  "Id": "eth0",
217    #  "InterfaceEnabled": true,
218    #  "LinkStatus": "LinkUp",
219    #  "MACAddress": "xx:xx:xx:xx:xx:xx",
220    #  "Name": "Manager Ethernet Interface",
221    #  "NameServers": [],
222    #  "SpeedMbps": 0,
223    #  "StaticNameServers": [],
224    #  "Status": {
225    #    "Health": "OK",
226    #    "HealthRollup": "OK",
227    #    "State": "Enabled"
228    #  },
229    #  "VLANs": {
230    #    "@odata.id": "/redfish/v1/Managers/${MANAGER_ID}/EthernetInterfaces/eth0/VLANs"
231
232
233    ${active_channel_config}=  Get Active Channel Config
234    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${active_channel_config['${CHANNEL_NUMBER}']['name']}
235
236    @{ipv6_network_configurations}=  Get From Dictionary  ${resp.dict}  IPv6StaticAddresses
237    RETURN  @{ipv6_network_configurations}
238
239
240Verify IPv6 And PrefixLength
241    [Documentation]  Verify IPv6 address and prefix length on BMC.
242    [Arguments]  ${ipv6_addr}  ${prefix_len}
243
244    # Description of the argument(s):
245    # ipv6_addr   IPv6 address to be verified.
246    # prefix_len  PrefixLength value to be verified.
247
248    # Catenate IPv6 address and its prefix length.
249    ${ipv6_with_prefix}=  Catenate  ${ipv6_addr}/${prefix_len}
250
251    # Get IPv6 address details on BMC using IP command.
252    @{ip_data}=  Get BMC IPv6 Info
253
254    # Verify if IPv6 and prefix length is configured on BMC.
255
256    Should Contain  ${ip_data}  ${ipv6_with_prefix}
257    ...  msg=IPv6 and prefix length pair does not exist.
258
259
260Configure IPv6 Address On BMC
261    [Documentation]  Add IPv6 Address on BMC.
262    [Arguments]  ${ipv6_addr}  ${prefix_len}  ${valid_status_codes}=${HTTP_OK}
263
264    # Description of argument(s):
265    # ipv6_addr           IPv6 address to be added (e.g. "2001:EEEE:2222::2022").
266    # prefix_len          Prefix length for the IPv6 to be added
267    #                     (e.g. "64").
268    # valid_status_codes  Expected return code from patch operation
269    #                     (e.g. "200").
270
271    ${prefix_length}=  Convert To Integer  ${prefix_len}
272    ${empty_dict}=  Create Dictionary
273    ${ipv6_data}=  Create Dictionary  Address=${ipv6_addr}
274    ...  PrefixLength=${prefix_length}
275
276    ${patch_list}=  Create List
277
278    # Get existing static IPv6 configurations on BMC.
279    ${ipv6_network_configurations}=  Get IPv6 Network Configuration
280    ${num_entries}=  Get Length  ${ipv6_network_configurations}
281
282    FOR  ${INDEX}  IN RANGE  0  ${num_entries}
283      Append To List  ${patch_list}  ${empty_dict}
284    END
285
286    ${valid_status_codes}=  Run Keyword If  '${valid_status_codes}' == '${HTTP_OK}'
287    ...  Set Variable   ${HTTP_OK},${HTTP_NO_CONTENT}
288    ...  ELSE  Set Variable  ${valid_status_codes}
289
290    # We need not check for existence of IPv6 on BMC while adding.
291    Append To List  ${patch_list}  ${ipv6_data}
292    ${data}=  Create Dictionary  IPv6StaticAddresses=${patch_list}
293
294    ${active_channel_config}=  Get Active Channel Config
295    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
296
297    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{data}
298    ...  valid_status_codes=[${valid_status_codes}]
299
300    Return From Keyword If  '${valid_status_codes}' != '${HTTP_OK},${HTTP_NO_CONTENT}'
301
302    # Note: Network restart takes around 15-18s after patch request processing.
303    Sleep  ${NETWORK_TIMEOUT}s
304    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
305
306    Verify IPv6 And PrefixLength  ${ipv6_addr}  ${prefix_len}
307
308    # Verify if existing static IPv6 addresses still exist.
309    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
310      Verify IPv6 On BMC  ${ipv6_network_configuration['Address']}
311    END
312
313    Validate IPv6 Network Config On BMC
314
315
316Validate IPv6 Network Config On BMC
317    [Documentation]  Check that IPv6 network info obtained via redfish matches info
318    ...              obtained via CLI.
319    @{ipv6_network_configurations}=  Get IPv6 Network Configuration
320    ${ipv6_data}=  Get BMC IPv6 Info
321    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
322      Should Contain Match  ${ipv6_data}  ${ipv6_network_configuration['Address']}/*
323      ...  msg=IPv6 address does not exist.
324    END
325
326
327Delete IPv6 Address
328    [Documentation]  Delete IPv6 address of BMC.
329    [Arguments]  ${ipv6_addr}
330    ...          ${valid_status_codes}=[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}]
331
332    # Description of argument(s):
333    # ipv6_addr           IPv6 address to be deleted (e.g. "2001:1234:1234:1234::1234").
334    # valid_status_codes  Expected return code from patch operation
335    #                     (e.g. "200").  See prolog of rest_request
336    #                     method in redfish_plus.py for details.
337
338    ${empty_dict}=  Create Dictionary
339    ${patch_list}=  Create List
340
341    @{ipv6_network_configurations}=  Get IPv6 Network Configuration
342    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
343        IF  '${ipv6_network_configuration['Address']}' == '${ipv6_addr}'
344            Append To List  ${patch_list}  ${null}
345        ELSE
346            Append To List  ${patch_list}  ${empty_dict}
347        END
348    END
349
350    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
351    ...  ${patch_list}  ${null}  msg=${ipv6_addr} does not exist on BMC
352    Pass Execution If  ${ip_found} == ${False}  ${ipv6_addr} does not exist on BMC
353
354    # Run patch command only if given IP is found on BMC
355    ${data}=  Create Dictionary  IPv6StaticAddresses=${patch_list}
356
357    ${active_channel_config}=  Get Active Channel Config
358    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
359
360    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  body=&{data}
361    ...  valid_status_codes=[${HTTP_OK},${HTTP_ACCEPTED},${HTTP_NO_CONTENT}]
362
363    # Note: Network restart takes around 15-18s after patch request processing
364    Sleep  ${NETWORK_TIMEOUT}s
365    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
366
367    # IPv6 address that is deleted should not be there on BMC.
368    ${delete_status}=  Run Keyword And Return Status  Verify IPv6 On BMC  ${ipv6_addr}
369    IF  '${valid_status_codes}' == '${HTTP_OK}'
370        Should Be True  '${delete_status}' == '${False}'
371    ELSE
372        Should Be True  '${delete_status}' == '${True}'
373    END
374
375    Validate IPv6 Network Config On BMC
376
377
378Modify IPv6 Address
379    [Documentation]  Modify and verify IPv6 address of BMC.
380    [Arguments]  ${ipv6}  ${new_ipv6}  ${prefix_len}
381    ...  ${valid_status_codes}=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
382
383    # Description of argument(s):
384    # ipv6                  IPv6 address to be replaced (e.g. "2001:AABB:CCDD::AAFF").
385    # new_ipv6              New IPv6 address to be configured.
386    # prefix_len            Prefix length value (Range 1 to 128).
387    # valid_status_codes    Expected return code from patch operation
388    #                       (e.g. "200", "201").
389
390    ${empty_dict}=  Create Dictionary
391    ${patch_list}=  Create List
392    ${prefix_length}=  Convert To Integer  ${prefix_len}
393    ${ipv6_data}=  Create Dictionary
394    ...  Address=${new_ipv6}  PrefixLength=${prefix_length}
395
396    # Sample IPv6 network configurations:
397    #  "IPv6AddressPolicyTable": [],
398    #  "IPv6Addresses": [
399    #    {
400    #      "Address": "X002:db8:0:2::XX0",
401    #      "AddressOrigin": "DHCPv6",
402    #      "PrefixLength": 128
403    #    },
404    #    {
405    #      "Address": “X002:db8:0:2:a94:XXff:fe82:XXXX",
406    #      "AddressOrigin": "SLAAC",
407    #      "PrefixLength": 64
408    #    },
409    #    {
410    #      "Address": “Y002:db8:0:2:a94:efff:fe82:5000",
411    #      "AddressOrigin": "Static",
412    #      "PrefixLength": 56
413    #    },
414    #    {
415    #      "Address": “Z002:db8:0:2:a94:efff:fe82:5000",
416    #      "AddressOrigin": "Static",
417    #      "PrefixLength": 56
418    #    },
419    #    {
420    #      "Address": “Xe80::a94:efff:YYYY:XXXX",
421    #      "AddressOrigin": "LinkLocal",
422    #      "PrefixLength": 64
423    #    },
424    #    {
425    #     "Address": “X002:db8:1:2:eff:233:fee:546",
426    #      "AddressOrigin": "Static",
427    #      "PrefixLength": 56
428    #    }
429    #  ],
430    #  "IPv6DefaultGateway": “XXXX::ab2e:80fe:87df:XXXX”,
431    #  "IPv6StaticAddresses": [
432    #    {
433    #      "Address": “X002:db8:0:2:a94:efff:fe82:5000",
434    #      "PrefixLength": 56
435    #    },
436    #    {
437    #      "Address": “Y002:db8:0:2:a94:efff:fe82:5000",
438    #      "PrefixLength": 56
439    #    },
440    #    {
441    #      "Address": “Z002:db8:1:2:eff:233:fee:546",
442    #      "PrefixLength": 56
443    #    }
444    #  ],
445    #  "IPv6StaticDefaultGateways": [],
446
447    # Find the position of IPv6 address to be modified.
448    @{ipv6_network_configurations}=  Get IPv6 Network Configuration
449    FOR  ${ipv6_network_configuration}  IN  @{ipv6_network_configurations}
450      Run Keyword If  '${ipv6_network_configuration['Address']}' == '${ipv6}'
451      ...  Append To List  ${patch_list}  ${ipv6_data}
452      ...  ELSE  Append To List  ${patch_list}  ${empty_dict}
453    END
454
455    # Modify the IPv6 address only if given IPv6 is found
456    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
457    ...  ${patch_list}  ${ipv6_data}  msg=${ipv6} does not exist on BMC
458    Pass Execution If  ${ip_found} == ${False}  ${ipv6} does not exist on BMC
459
460    ${data}=  Create Dictionary  IPv6StaticAddresses=${patch_list}
461
462    ${active_channel_config}=  Get Active Channel Config
463    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
464
465    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
466    ...  body=&{data}  valid_status_codes=${valid_status_codes}
467
468    # Note: Network restart takes around 15-18s after patch request processing.
469    Sleep  ${NETWORK_TIMEOUT}s
470    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
471
472    # Verify if new IPv6 address is configured on BMC.
473    Verify IPv6 On BMC  ${new_ipv6}
474
475    # Verify if old IPv6 address is erased.
476    ${cmd_status}=  Run Keyword And Return Status
477    ...  Verify IPv6 On BMC  ${ipv6}
478    Should Be Equal  ${cmd_status}  ${False}  msg=Old IPv6 address is not deleted.
479
480    Validate IPv6 Network Config On BMC
481
482
483Set SLAACv6 Configuration State And Verify
484    [Documentation]  Set SLAACv6 configuration state and verify.
485    [Arguments]  ${slaac_state}  ${valid_status_codes}=${HTTP_OK}
486
487    # Description of argument(s):
488    # slaac_state         SLAACv6 state('True' or 'False').
489    # valid_status_code   Expected valid status codes.
490
491    ${active_channel_config}=  Get Active Channel Config
492    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
493
494    ${data}=  Set Variable If  ${slaac_state} == ${False}  ${DISABLE_SLAAC}  ${ENABLE_SLAAC}
495    ${resp}=  Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
496    ...  body=${data}  valid_status_codes=[${valid_status_codes}]
497
498    # Verify SLAACv6 is set correctly.
499    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
500    ${slaac_verify}=  Get From Dictionary  ${resp.dict}  StatelessAddressAutoConfig
501
502    Run Keyword If  '${slaac_verify['IPv6AutoConfigEnabled']}' != '${slaac_state}'
503    ...  Fail  msg=SLAACv6 not set properly.
504
505Set And Verify DHCPv6 Property
506    [Documentation]  Set DHCPv6 attribute and verify.
507    [Arguments]  ${dhcpv6_operating_mode}=${Disabled}
508
509    # Description of argument(s):
510    # dhcpv6_operating_mode    Enabled if user wants to enable DHCPv6('Enabled' or 'Disabled').
511
512    ${data}=  Set Variable If  '${dhcpv6_operating_mode}' == 'Disabled'  ${DISABLE_DHCPv6}  ${ENABLE_DHCPv6}
513    ${active_channel_config}=  Get Active Channel Config
514    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
515
516    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
517    ...  body=${data}  valid_status_codes=[${HTTP_OK},${HTTP_NO_CONTENT}]
518
519    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
520    ${dhcpv6_verify}=  Get From Dictionary  ${resp.dict}  DHCPv6
521
522    Should Be Equal  '${dhcpv6_verify['OperatingMode']}'  '${dhcpv6_operating_mode}'
523