xref: /openbmc/openbmc-test-automation/network/test_vlan_network.robot (revision 94041a34a992d9b5f6418a43e1cd5273a6d9f9b2)
1*** Settings ***
2Documentation           Test setting VLAN and its configuration.
3
4
5Resource                        ../lib/rest_client.robot
6Resource                        ../lib/ipmi_client.robot
7Resource                        ../lib/utils.robot
8Resource                        ../lib/common_utils.robot
9Resource                        ../lib/openbmc_ffdc.robot
10Resource                        ../lib/bmc_network_utils.robot
11Resource                        ../lib/state_manager.robot
12Library                         ../lib/utilities.py
13Library                         ../lib/ipmi_utils.py
14Library                         ../lib/var_funcs.py
15Library                         ../lib/func_args.py
16Library                         Collections
17
18Suite Teardown                  Suite Teardown Execution
19
20Test Tags                      VLAN_Network
21
22*** Variables ***
23
24${vlan_id}                      ${53}
25@{vlan_ids}                     ${35}  ${55}
26${invalid_vlan_id}              abc
27${vlan_resource}                ${NETWORK_MANAGER}action/VLAN
28${network_resource}             xyz.openbmc_project.Network.IP.Protocol.IPv4
29${static_network_resource}      xyz.openbmc_project.Network.IP.AddressOrigin.Static
30${ip}                           10.6.6.10
31@{ip_addresses}                 10.5.5.10  10.4.5.7
32${netmask}                      ${24}
33${gateway}                      0.0.0.0
34${initial_vlan_config}          @{EMPTY}
35
36
37*** Test Cases ***
38
39Add VLAN Via REST And Verify
40    [Documentation]  Add VLAN via REST and verify it via REST and IPMI.
41    [Tags]  Add_VLAN_Via_REST_And_Verify
42    [Setup]  Test Setup Execution
43    [Teardown]  Delete VLANs  [${vlan_id}]
44
45    Create VLAN  ${vlan_id}
46    Verify Existence Of VLAN  ${vlan_id}
47
48    ${lan_config}=  Get LAN Print Dict
49    Valid Value  lan_config['802.1q VLAN ID']  ["${vlan_id}"]
50
51
52Add Invalid VLAN Via REST And Verify
53    [Documentation]  Add Invalid VLAN via REST and verify.
54    [Tags]  Add_Invalid_VLAN_Via_REST_And_Verify
55
56    Create VLAN  ${invalid_vlan_id}  expected_result=error
57
58
59Delete VLAN Via REST
60    [Documentation]  Delete VLAN via REST and verify it via REST and IPMI.
61    [Tags]  Delete_VLAN_Via_REST
62    [Setup]  Run Keywords  Test Setup Execution  AND  Create VLAN  ${vlan_id}
63
64    Verify Existence Of VLAN  ${vlan_id}
65    Delete VLANs  [${vlan_id}]
66    Verify Existence Of VLAN  ${vlan_id}  expected_result=error
67
68    ${lan_config}=  Get LAN Print Dict
69    Valid Value  lan_config['802.1q VLAN ID']  ["Disabled"]
70
71
72Configure Network Settings On VLAN Via REST
73    [Documentation]  Configure IP on VLAN and verify it via REST and IPMI.
74    [Tags]  Configure_Network_Settings_On_VLAN_Via_REST
75    [Setup]  Run Keywords  Test Setup Execution  AND  Create VLAN  ${vlan_id}
76    [Teardown]  Delete VLANs  [${vlan_id}]
77
78    Configure Network Settings On VLAN  ${vlan_id}  ${ip}  ${netmask}
79    Get VLAN URI For IP  ${vlan_id}  ${ip}
80
81    ${lan_config}=  Get LAN Print Dict
82    Valid Value  lan_config['IP Address']  ["${ip}"]
83
84
85Delete IP On VLAN Via REST
86    [Documentation]  Delete IP on VLAN and verify it via REST and IPMI.
87    [Tags]  Delete_IP_On_VLAN_Via_REST
88    [Setup]  Run Keywords  Test Setup Execution  AND  Create VLAN  ${vlan_id}
89    [Teardown]  Delete VLANs  [${vlan_id}]
90
91    Configure Network Settings On VLAN  ${vlan_id}  ${ip}  ${netmask}
92    ${lan_config}=  Get LAN Print Dict
93    Valid Value  lan_config['IP Address']  ["${ip}"]
94
95    ${vlan_ip_uri}=  Get VLAN URI For IP  ${vlan_id}  ${ip}
96    Delete IP And Object  ${ip}  ${vlan_ip_uri}
97
98    Get VLAN URI For IP  ${vlan_id}  ${ip}  expected_result=error
99
100    ${lan_config}=  Get LAN Print Dict
101    Should Not Match  ${lan_config['IP Address']}  ${ip}
102
103
104Delete VLAN When IP Is Configured Via REST
105    [Documentation]  Delete IP on VLAN and verify using IPMI.
106    [Tags]  Delete_VLAN_When_IP_Is_Configured_Via_REST
107    [Setup]  Run Keywords  Test Setup Execution  AND  Create VLAN  ${vlan_id}
108    [Teardown]  Delete VLANs  [${vlan_id}]
109
110    Configure Network Settings On VLAN  ${vlan_id}  ${ip}  ${netmask}
111    ${lan_config}=  Get LAN Print Dict
112    Valid Value  lan_config['IP Address']  ["${ip}"]
113    Delete VLANs  [${vlan_id}]
114
115    Verify Existence Of VLAN  ${vlan_id}  expected_result=error
116
117    ${lan_config}=  Get LAN Print Dict
118    Valid Value  lan_config['802.1q VLAN ID']  ["Disabled"]
119
120
121Configure VLAN And Check Persistency On Reboot
122    [Documentation]  Create VLAN ID & IP , reboot and verify.
123    [Tags]  Configure_VLAN_And_Check_Persistency_On_Reboot
124    [Setup]  Test Setup Execution
125    [Teardown]  Delete VLANs  [${vlan_id}]
126
127    Create VLAN  ${vlan_id}
128    Configure Network Settings On VLAN  ${vlan_id}  ${ip}  ${netmask}
129    ${lan_config}=  Get LAN Print Dict
130    Valid Value  lan_config['IP Address']  ["${ip}"]
131    Valid Value  lan_config['802.1q VLAN ID']  ["${vlan_id}"]
132
133    Initiate BMC Reboot
134
135    Verify Existence Of VLAN  ${vlan_id}
136    Get VLAN URI For IP  ${vlan_id}  ${ip}
137
138    ${lan_config}=  Get LAN Print Dict
139    Valid Value  lan_config['IP Address']  ["${ip}"]
140    Valid Value  lan_config['802.1q VLAN ID']  ["${vlan_id}"]
141
142
143Add Multiple VLANs Via REST And Verify
144    [Documentation]  Add multiple VLANs via REST and verify them via CLI.
145    [Tags]  Add_Multiple_VLANs_Via_REST_And_Verify
146    [Setup]  Test Setup Execution
147    [Teardown]  Delete VLANs  ${vlan_ids}
148
149    FOR  ${vlan_id}  IN   @{vlan_ids}
150        Create VLAN  ${vlan_id}
151        Verify Existence Of VLAN  ${vlan_id}
152    END
153
154    ${lan_config}=  Get LAN Print Dict
155    ${vlan_id_ipmi}=  Convert To Integer  ${lan_config["802.1q VLAN ID"]}
156    Valid List  vlan_ids  required_values=[${vlan_id_ipmi}]
157
158Delete Multiple IPs On VLAN And Verify
159    [Documentation]  Delete multiple IPs on VLAN and verify each via REST and IPMI.
160    [Tags]  Delete_Multiple_IPs_On_VLAN_And_Verify
161    [Setup]  Run Keywords  Test Setup Execution  AND  Create VLAN  ${vlan_id}
162    [Teardown]  Delete VLANs  [${vlan_id}]
163
164    FOR  ${ip}  IN  @{ip_addresses}
165        Configure Network Settings On VLAN  ${vlan_id}  ${ip}  ${netmask}
166        ${vlan_ip_uri}=  Get VLAN URI For IP  ${vlan_id}  ${ip}
167        Delete IP And Object  ${ip}  ${vlan_ip_uri}
168
169        Get VLAN URI For IP  ${vlan_id}  ${ip}  expected_result=error
170
171        ${lan_config}=  Get LAN Print Dict
172        Should Not Match  ${lan_config['IP Address']}  ${ip}
173    END
174
175Delete Multiple VLANs Via REST
176    [Documentation]  Delete multiple VLANs via REST and verify each via REST and IPMI.
177    [Tags]  Delete_Multiple_VLANs_Via_REST
178    [Setup]  Test Setup Execution
179
180    FOR  ${vlan_id}  IN   @{vlan_ids}
181        Create VLAN  ${vlan_id}
182    END
183
184    Delete VLANs  ${vlan_ids}
185
186    ${lan_config}=  Get LAN Print Dict
187    Valid Value  lan_config['802.1q VLAN ID']  ["Disabled"]
188
189Configure Multiple IPs On VLAN Via REST
190    [Documentation]  Configure Multiple IPs on VLAN and verify each via REST.
191    [Tags]  Configure_Multiple_IPs_On_VLAN_Via_REST
192    [Setup]  Run Keywords  Test Setup Execution  AND  Create VLAN  ${vlan_id}
193    [Teardown]  Delete VLANs  [${vlan_id}]
194
195    FOR  ${ip}  IN  @{ip_addresses}
196        Configure Network Settings On VLAN  ${vlan_id}  ${ip}  ${netmask}
197    END
198
199    ${lan_config}=  Get LAN Print Dict
200    Valid Value  lan_config['IP Address']  ["${ip_addresses[0]}"]
201
202
203Create And Delete VLAN And IP On It Multiple Times With BMC Reboot
204    [Documentation]  Create and delete VLAN and IP on it multiple times with BMC reboot.
205    [Tags]  Create_And_Delete_VLAN_And_IP_On_It_Multiple_Times_With_BMC_Reboot
206    [Setup]  Test Setup Execution
207
208    FOR  ${i}  IN RANGE   ${5}
209      Create VLAN  ${vlan_id}
210      Verify Existence Of VLAN  ${vlan_id}
211      Configure Network Settings On VLAN  ${vlan_id}  ${ip}  ${netmask}
212      ${vlan_ip_uri}=  Get VLAN URI For IP  ${vlan_id}  ${ip}
213      Delete IP And Object  ${ip}  ${vlan_ip_uri}
214      Get VLAN URI For IP  ${vlan_id}  ${ip}  expected_result=error
215      Delete VLANs  [${vlan_id}]
216      Verify Existence Of VLAN  ${vlan_id}  expected_result=error
217      Initiate BMC Reboot
218      Sleep  ${NETWORK_TIMEOUT}s
219      Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
220      Verify Existence Of VLAN  ${vlan_id}  expected_result=error
221    END
222
223    ${lan_config}=  Get LAN Print Dict
224    Valid Value  lan_config['802.1q VLAN ID']  ["Disabled"]
225
226
227*** Keywords ***
228
229
230Test Setup Execution
231    [Documentation]  Check and delete all previously created VLAN if any.
232
233    Printn
234    ${lan_config}=  Get LAN Print Dict
235    Return From Keyword If  '${lan_config['802.1q VLAN ID']}' == 'Disabled'
236
237    # Get all VLAN ID on interface eth0.
238    ${vlan_ids}=  Get VLAN IDs
239
240    ${initial_vlan_config}=  Create List
241    Set Suite Variable  ${initial_vlan_config}
242
243    FOR  ${vlan_id}  IN  @{vlan_ids}
244        ${vlan_records}=  Read Properties
245        ...  ${NETWORK_MANAGER}eth0_${vlan_id}${/}enumerate  quiet=1
246        ${vlan_record}=  Filter Struct
247        ...  ${vlan_records}  [('Origin', '${static_network_resource}')]
248
249        ${id}=  Convert To Integer  ${vlan_id}
250        Set Initial VLAN Config  ${vlan_record}  ${id}
251    END
252    Rprint Vars  initial_vlan_config
253
254    Delete VLANs  ${vlan_ids}
255
256
257Set Initial VLAN Config
258    [Documentation]  Set suite level list of Initial VLAN Config.
259    [Arguments]  ${vlan_record}  ${id}
260
261    # Description of argument(s):
262    # vlan_record  Dictionary of IP configuration information of a VLAN.
263    # Example:
264    #  /xyz/openbmc_project/network/eth0_55/ipv4/5fb2cfe6": {
265    #  "Address": "x.x.x.x",
266    #  "Gateway": "",
267    #  "Origin": "xyz.openbmc_project.Network.IP.AddressOrigin.Static",
268    #  "PrefixLength": 16,
269    #  "Type": "xyz.openbmc_project.Network.IP.Protocol.IPv4"}
270    #
271    # id  The VLAN ID corresponding to the IP Configuration records contained
272    #     in the variable "vlan_record".
273
274    ${uris}=  Get Dictionary Keys  ${vlan_record}
275
276    FOR  ${uri}  IN  @{uris}
277        Append To List  ${initial_vlan_config}  ${id}  ${vlan_record['${uri}']['Address']}
278        ...  ${vlan_record['${uri}']['PrefixLength']}
279    END
280
281    IF  @{uris} == @{EMPTY}
282        Append To List  ${initial_vlan_config}  ${id}  ${EMPTY}  ${EMPTY}
283    END
284
285
286Suite Teardown Execution
287    [Documentation]  Restore VLAN configuration.
288
289    ${length}=  Get Length  ${initial_vlan_config}
290    Return From Keyword If  ${length} == ${0}
291
292    ${previous_id}=  Set Variable  ${EMPTY}
293    FOR  ${index}  IN RANGE  0  ${length}  3
294        IF  '${initial_vlan_config[${index+1}]}' == '${EMPTY}'
295            Create VLAN  ${initial_vlan_config[${index}]}
296        ELSE IF  '${previous_id}' == '${initial_vlan_config[${index}]}'
297            Configure Network Settings On VLAN  ${initial_vlan_config[${index}]}
298            ...  ${initial_vlan_config[${index+1}]}  ${initial_vlan_config[${index+2}]}
299        ELSE
300            Create VLAN  ${initial_vlan_config[${index}]}
301            Configure Network Settings On VLAN  ${initial_vlan_config[${index}]}
302            ...  ${initial_vlan_config[${index+1}]}  ${initial_vlan_config[${index+2}]}
303        END
304
305        ${previous_id}=  Set Variable  ${initial_vlan_config[${index}]}
306    END
307
308
309Delete VLANs
310    [Documentation]  Delete one or more VLANs.
311    [Arguments]  ${ids}  ${interface}=eth0
312
313    # Description of argument(s):
314    # ids                           A list of VLAN IDs (e.g. ['53'] or ['53', '35', '12']). Note that the
315    #                               caller may simply pass a list variable or he/she may specify a
316    #                               python-like list specification (see examples below).
317    # interface                     The physical interface for the VLAN (e.g. 'eth0').
318
319    # Example calls:
320    # Delete VLANs  ${vlan_ids}
321    # Delete Vlans  [53, 35]
322
323    # Allow for python-like list specifications (e.g. ids=['53']).
324    ${vlan_ids}=  Source To Object  ${ids}
325
326    FOR  ${id}  IN  @{vlan_ids}
327        OpenBMC Delete Request  ${NETWORK_MANAGER}${interface}_${id}
328    END
329    Run Key U  Sleep \ ${NETWORK_TIMEOUT}s
330
331
332Get VLAN IDs
333    [Documentation]  Return all VLAN IDs.
334
335    ${vlan_ids}  ${stderr}  ${rc}=  BMC Execute Command
336    ...  /sbin/ip addr | grep @eth0 | cut -f1 -d@ | cut -f2 -d.
337    ${vlan_ids}=  Split String  ${vlan_ids}
338
339    RETURN  @{vlan_ids}
340
341
342Get VLAN URI For IP
343    [Documentation]  Get and return the URI for a VLAN IP.
344    [Arguments]  ${vlan_id}  ${vlan_ip}  ${expected_result}=valid
345
346    # Description of argument(s):
347    # vlan_id          The VLAN ID (e.g. '53').
348    # vlan_ip          The VLAN IP (e.g. 'x.x.x.x').
349    # expected_result  Expected status to check existence of VLAN IP URI. (e.g. 'valid')
350
351    ${vlan_records}=  Read Properties
352    ...  ${NETWORK_MANAGER}eth0_${vlan_id}${/}enumerate  quiet=1
353    ${vlan_record}=  Filter Struct  ${vlan_records}  [('Address', '${vlan_ip}')]
354    ${num_vlan_records}=  Get Length  ${vlan_record}
355    ${status}=  Run Keyword And Return Status  Should Be True  ${num_vlan_records} > 0
356    ...  msg=Could not find a uri for vlan "${vlan_id}" with IP "${vlan_ip}".
357
358    IF  '${expected_result}' == 'valid'
359        Should Be Equal  ${status}  ${True}  msg=VLAN IP URI doesn't exist!.
360    ELSE
361        Should Be Equal  ${status}  ${False} msg=VLAN IP URI exists!.
362    END
363
364    ${uris}=  Get Dictionary Keys  ${vlan_record}
365    Return From Keyword If  @{uris} == @{EMPTY}
366
367    RETURN  ${uris[${0}]}
368
369
370Verify Existence Of VLAN
371    [Documentation]  Verify VLAN ID exists.
372    [Arguments]  ${id}  ${interface}=eth0  ${expected_result}=valid
373
374    # Description of argument(s):
375    # id               The VLAN ID (e.g. id:'53').
376    # interface        Physical Interface on which the VLAN is defined.
377    # expected_result  Expected status to check existence or non-existence of VLAN.
378
379    ${vlan_ids}=  Get VLAN IDs
380    ${cli_status}=  Run Keyword And Return Status
381    ...  Valid List  vlan_ids  required_values=['${id}']
382
383    ${network_records}=  Read Properties  ${NETWORK_MANAGER}
384    ${rest_status}=  Run Keyword And Return Status  Valid List  network_records
385    ...  required_values=['${NETWORK_MANAGER}${interface}_${id}']
386
387    Should Be Equal  ${rest_status}  ${cli_status}
388    ...  msg=REST and CLI Output are not the same.
389    IF  '${expected_result}' == 'valid'
390        Should Be Equal  ${rest_status}  ${True}  msg=VLAN ID doesn't exist!.
391    ELSE
392        Should Be Equal  ${rest_status}  ${False}  msg=VLAN ID exists!.
393    END
394