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