blob: 73106bcdd72d2418887a71aad8b190698e906f7f [file] [log] [blame]
Naman Navin Hegdead14a722019-11-04 12:28:21 -06001*** 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
Naman Navin Hegdead14a722019-11-04 12:28:21 -060010Resource ../lib/bmc_network_utils.robot
11Resource ../lib/state_manager.robot
12Library ../lib/utilities.py
13Library ../lib/ipmi_utils.py
14Library ../lib/var_funcs.py
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060015Library ../lib/func_args.py
Naman Navin Hegdead14a722019-11-04 12:28:21 -060016Library Collections
17
18Suite Teardown Suite Teardown Execution
19
Matt Fischer6fb70d92023-10-24 19:06:33 -060020Test Tags VLAN_Network
Naman Navin Hegdead14a722019-11-04 12:28:21 -060021
22*** Variables ***
George Keishing87dc4422023-10-20 12:56:30 +053023
Naman Navin Hegdead14a722019-11-04 12:28:21 -060024${vlan_id} ${53}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060025@{vlan_ids} ${35} ${55}
Naman Navin Hegdead14a722019-11-04 12:28:21 -060026${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
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060031@{ip_addresses} 10.5.5.10 10.4.5.7
Naman Navin Hegdead14a722019-11-04 12:28:21 -060032${netmask} ${24}
33${gateway} 0.0.0.0
34${initial_vlan_config} @{EMPTY}
35
36
37*** Test Cases ***
38
Naman Navin Hegdead14a722019-11-04 12:28:21 -060039Add 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
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060043 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -060044
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}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060065 Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -060066 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}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060076 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -060077
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}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060089 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -060090
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}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600108 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600109
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}"]
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600113 Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600114
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
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600125 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600126
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
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600143Add 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.
George Keishingb98036a2022-01-31 12:39:47 -0600160 [Tags] Delete_Multiple_IPs_On_VLAN_And_Verify
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600161 [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
Anvesh Kumar Rayankula80d6b5a2020-04-06 05:57:06 -0500202
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
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600227*** Keywords ***
228
229
230Test Setup Execution
231 [Documentation] Check and delete all previously created VLAN if any.
232
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600233 Printn
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600234 ${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}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600244 ${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}')]
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600248
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600249 ${id}= Convert To Integer ${vlan_id}
250 Set Initial VLAN Config ${vlan_record} ${id}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600251 END
252 Rprint Vars initial_vlan_config
253
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600254 Delete VLANs ${vlan_ids}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600255
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}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600275
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600276 FOR ${uri} IN @{uris}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600277 Append To List ${initial_vlan_config} ${id} ${vlan_record['${uri}']['Address']}
278 ... ${vlan_record['${uri}']['PrefixLength']}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600279 END
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600280
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600281 Run Keyword If @{uris} == @{EMPTY}
282 ... Append To List ${initial_vlan_config} ${id} ${EMPTY} ${EMPTY}
283
284
285Suite Teardown Execution
286 [Documentation] Restore VLAN configuration.
287
288 ${length}= Get Length ${initial_vlan_config}
289 Return From Keyword If ${length} == ${0}
290
291 ${previous_id}= Set Variable ${EMPTY}
292 FOR ${index} IN RANGE 0 ${length} 3
293
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600294 Run Keyword 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 Run Keywords Create VLAN ${initial_vlan_config[${index}]} AND
300 ... Configure Network Settings On VLAN ${initial_vlan_config[${index}]}
301 ... ${initial_vlan_config[${index+1}]} ${initial_vlan_config[${index+2}]}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600302
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600303 ${previous_id}= Set Variable ${initial_vlan_config[${index}]}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600304 END
305
306
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600307Delete VLANs
308 [Documentation] Delete one or more VLANs.
309 [Arguments] ${ids} ${interface}=eth0
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600310
311 # Description of argument(s):
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600312 # ids A list of VLAN IDs (e.g. ['53'] or ['53', '35', '12']). Note that the
313 # caller may simply pass a list variable or he/she may specify a
314 # python-like list specification (see examples below).
315 # interface The physical interface for the VLAN (e.g. 'eth0').
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600316
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600317 # Example calls:
318 # Delete VLANs ${vlan_ids}
319 # Delete Vlans [53, 35]
320
321 # Allow for python-like list specifications (e.g. ids=['53']).
322 ${vlan_ids}= Source To Object ${ids}
323
324 FOR ${id} IN @{vlan_ids}
325 OpenBMC Delete Request ${NETWORK_MANAGER}${interface}_${id}
326 END
327 Run Key U Sleep \ ${NETWORK_TIMEOUT}s
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600328
329
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600330Get VLAN IDs
331 [Documentation] Return all VLAN IDs.
332
333 ${vlan_ids} ${stderr} ${rc}= BMC Execute Command
334 ... /sbin/ip addr | grep @eth0 | cut -f1 -d@ | cut -f2 -d.
335 ${vlan_ids}= Split String ${vlan_ids}
336
George Keishing409df052024-01-17 22:36:14 +0530337 RETURN @{vlan_ids}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600338
339
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600340Get VLAN URI For IP
341 [Documentation] Get and return the URI for a VLAN IP.
342 [Arguments] ${vlan_id} ${vlan_ip} ${expected_result}=valid
343
344 # Description of argument(s):
345 # vlan_id The VLAN ID (e.g. '53').
346 # vlan_ip The VLAN IP (e.g. 'x.x.x.x').
347
348 ${vlan_records}= Read Properties
349 ... ${NETWORK_MANAGER}eth0_${vlan_id}${/}enumerate quiet=1
350 ${vlan_record}= Filter Struct ${vlan_records} [('Address', '${vlan_ip}')]
351 ${num_vlan_records}= Get Length ${vlan_record}
352 ${status}= Run Keyword And Return Status Should Be True ${num_vlan_records} > 0
353 ... msg=Could not find a uri for vlan "${vlan_id}" with IP "${vlan_ip}".
354
355 Run Keyword If '${expected_result}' == 'valid'
356 ... Should Be Equal ${status} ${True}
George Keishingf7022192019-12-11 11:30:09 -0600357 ... msg=VLAN IP URI doesn't exist!.
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600358 ... ELSE
359 ... Should Be Equal ${status} ${False}
360 ... msg=VLAN IP URI exists!.
361 ${uris}= Get Dictionary Keys ${vlan_record}
362 Return From Keyword If @{uris} == @{EMPTY}
363
George Keishing409df052024-01-17 22:36:14 +0530364 RETURN ${uris[${0}]}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600365
366
367Verify Existence Of VLAN
368 [Documentation] Verify VLAN ID exists.
369 [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid
370
371 # Description of argument(s):
372 # id The VLAN ID (e.g. id:'53').
373 # interface Physical Interface on which the VLAN is defined.
374 # expected_result Expected status to check existence or non-existence of VLAN.
375
376 ${vlan_ids}= Get VLAN IDs
377 ${cli_status}= Run Keyword And Return Status
378 ... Valid List vlan_ids required_values=['${id}']
379
380 ${network_records}= Read Properties ${NETWORK_MANAGER}
381 ${rest_status}= Run Keyword And Return Status Valid List network_records
382 ... required_values=['${NETWORK_MANAGER}${interface}_${id}']
383
384 Should Be Equal ${rest_status} ${cli_status}
385 ... msg=REST and CLI Output are not the same.
386 Run Keyword If '${expected_result}' == 'valid'
387 ... Should Be Equal ${rest_status} ${True}
George Keishingf7022192019-12-11 11:30:09 -0600388 ... msg=VLAN ID doesn't exist!.
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600389 ... ELSE
390 ... Should Be Equal ${rest_status} ${False}
391 ... msg=VLAN ID exists!.