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