blob: 8feb2fb35b4eefb2d8047151d5ff206cfdf8cf51 [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
10Resource ../lib/ipmi_client.robot
11Resource ../lib/bmc_network_utils.robot
12Resource ../lib/state_manager.robot
13Library ../lib/utilities.py
14Library ../lib/ipmi_utils.py
15Library ../lib/var_funcs.py
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060016Library ../lib/func_args.py
Naman Navin Hegdead14a722019-11-04 12:28:21 -060017Library Collections
18
19Suite Teardown Suite Teardown Execution
20
George Keishing87dc4422023-10-20 12:56:30 +053021Force Tags VLAN_Network
Naman Navin Hegdead14a722019-11-04 12:28:21 -060022
23*** Variables ***
George Keishing87dc4422023-10-20 12:56:30 +053024
Naman Navin Hegdead14a722019-11-04 12:28:21 -060025${vlan_id} ${53}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060026@{vlan_ids} ${35} ${55}
Naman Navin Hegdead14a722019-11-04 12:28:21 -060027${invalid_vlan_id} abc
28${vlan_resource} ${NETWORK_MANAGER}action/VLAN
29${network_resource} xyz.openbmc_project.Network.IP.Protocol.IPv4
30${static_network_resource} xyz.openbmc_project.Network.IP.AddressOrigin.Static
31${ip} 10.6.6.10
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060032@{ip_addresses} 10.5.5.10 10.4.5.7
Naman Navin Hegdead14a722019-11-04 12:28:21 -060033${netmask} ${24}
34${gateway} 0.0.0.0
35${initial_vlan_config} @{EMPTY}
36
37
38*** Test Cases ***
39
Naman Navin Hegdead14a722019-11-04 12:28:21 -060040Add VLAN Via REST And Verify
41 [Documentation] Add VLAN via REST and verify it via REST and IPMI.
42 [Tags] Add_VLAN_Via_REST_And_Verify
43 [Setup] Test Setup Execution
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060044 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -060045
46 Create VLAN ${vlan_id}
47 Verify Existence Of VLAN ${vlan_id}
48
49 ${lan_config}= Get LAN Print Dict
50 Valid Value lan_config['802.1q VLAN ID'] ["${vlan_id}"]
51
52
53Add Invalid VLAN Via REST And Verify
54 [Documentation] Add Invalid VLAN via REST and verify.
55 [Tags] Add_Invalid_VLAN_Via_REST_And_Verify
56
57 Create VLAN ${invalid_vlan_id} expected_result=error
58
59
60Delete VLAN Via REST
61 [Documentation] Delete VLAN via REST and verify it via REST and IPMI.
62 [Tags] Delete_VLAN_Via_REST
63 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
64
65 Verify Existence Of VLAN ${vlan_id}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060066 Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -060067 Verify Existence Of VLAN ${vlan_id} expected_result=error
68
69 ${lan_config}= Get LAN Print Dict
70 Valid Value lan_config['802.1q VLAN ID'] ["Disabled"]
71
72
73Configure Network Settings On VLAN Via REST
74 [Documentation] Configure IP on VLAN and verify it via REST and IPMI.
75 [Tags] Configure_Network_Settings_On_VLAN_Via_REST
76 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060077 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -060078
79 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
80 Get VLAN URI For IP ${vlan_id} ${ip}
81
82 ${lan_config}= Get LAN Print Dict
83 Valid Value lan_config['IP Address'] ["${ip}"]
84
85
86Delete IP On VLAN Via REST
87 [Documentation] Delete IP on VLAN and verify it via REST and IPMI.
88 [Tags] Delete_IP_On_VLAN_Via_REST
89 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -060090 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -060091
92 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
93 ${lan_config}= Get LAN Print Dict
94 Valid Value lan_config['IP Address'] ["${ip}"]
95
96 ${vlan_ip_uri}= Get VLAN URI For IP ${vlan_id} ${ip}
97 Delete IP And Object ${ip} ${vlan_ip_uri}
98
99 Get VLAN URI For IP ${vlan_id} ${ip} expected_result=error
100
101 ${lan_config}= Get LAN Print Dict
102 Should Not Match ${lan_config['IP Address']} ${ip}
103
104
105Delete VLAN When IP Is Configured Via REST
106 [Documentation] Delete IP on VLAN and verify using IPMI.
107 [Tags] Delete_VLAN_When_IP_Is_Configured_Via_REST
108 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600109 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600110
111 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
112 ${lan_config}= Get LAN Print Dict
113 Valid Value lan_config['IP Address'] ["${ip}"]
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600114 Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600115
116 Verify Existence Of VLAN ${vlan_id} expected_result=error
117
118 ${lan_config}= Get LAN Print Dict
119 Valid Value lan_config['802.1q VLAN ID'] ["Disabled"]
120
121
122Configure VLAN And Check Persistency On Reboot
123 [Documentation] Create VLAN ID & IP , reboot and verify.
124 [Tags] Configure_VLAN_And_Check_Persistency_On_Reboot
125 [Setup] Test Setup Execution
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600126 [Teardown] Delete VLANs [${vlan_id}]
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600127
128 Create VLAN ${vlan_id}
129 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
130 ${lan_config}= Get LAN Print Dict
131 Valid Value lan_config['IP Address'] ["${ip}"]
132 Valid Value lan_config['802.1q VLAN ID'] ["${vlan_id}"]
133
134 Initiate BMC Reboot
135
136 Verify Existence Of VLAN ${vlan_id}
137 Get VLAN URI For IP ${vlan_id} ${ip}
138
139 ${lan_config}= Get LAN Print Dict
140 Valid Value lan_config['IP Address'] ["${ip}"]
141 Valid Value lan_config['802.1q VLAN ID'] ["${vlan_id}"]
142
143
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600144Add Multiple VLANs Via REST And Verify
145 [Documentation] Add multiple VLANs via REST and verify them via CLI.
146 [Tags] Add_Multiple_VLANs_Via_REST_And_Verify
147 [Setup] Test Setup Execution
148 [Teardown] Delete VLANs ${vlan_ids}
149
150 FOR ${vlan_id} IN @{vlan_ids}
151 Create VLAN ${vlan_id}
152 Verify Existence Of VLAN ${vlan_id}
153 END
154
155 ${lan_config}= Get LAN Print Dict
156 ${vlan_id_ipmi}= Convert To Integer ${lan_config["802.1q VLAN ID"]}
157 Valid List vlan_ids required_values=[${vlan_id_ipmi}]
158
159Delete Multiple IPs On VLAN And Verify
160 [Documentation] Delete multiple IPs on VLAN and verify each via REST and IPMI.
George Keishingb98036a2022-01-31 12:39:47 -0600161 [Tags] Delete_Multiple_IPs_On_VLAN_And_Verify
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600162 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
163 [Teardown] Delete VLANs [${vlan_id}]
164
165 FOR ${ip} IN @{ip_addresses}
166 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
167 ${vlan_ip_uri}= Get VLAN URI For IP ${vlan_id} ${ip}
168 Delete IP And Object ${ip} ${vlan_ip_uri}
169
170 Get VLAN URI For IP ${vlan_id} ${ip} expected_result=error
171
172 ${lan_config}= Get LAN Print Dict
173 Should Not Match ${lan_config['IP Address']} ${ip}
174 END
175
176Delete Multiple VLANs Via REST
177 [Documentation] Delete multiple VLANs via REST and verify each via REST and IPMI.
178 [Tags] Delete_Multiple_VLANs_Via_REST
179 [Setup] Test Setup Execution
180
181 FOR ${vlan_id} IN @{vlan_ids}
182 Create VLAN ${vlan_id}
183 END
184
185 Delete VLANs ${vlan_ids}
186
187 ${lan_config}= Get LAN Print Dict
188 Valid Value lan_config['802.1q VLAN ID'] ["Disabled"]
189
190Configure Multiple IPs On VLAN Via REST
191 [Documentation] Configure Multiple IPs on VLAN and verify each via REST.
192 [Tags] Configure_Multiple_IPs_On_VLAN_Via_REST
193 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
194 [Teardown] Delete VLANs [${vlan_id}]
195
196 FOR ${ip} IN @{ip_addresses}
197 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
198 END
199
200 ${lan_config}= Get LAN Print Dict
201 Valid Value lan_config['IP Address'] ["${ip_addresses[0]}"]
202
Anvesh Kumar Rayankula80d6b5a2020-04-06 05:57:06 -0500203
204Create And Delete VLAN And IP On It Multiple Times With BMC Reboot
205 [Documentation] Create and delete VLAN and IP on it multiple times with BMC reboot.
206 [Tags] Create_And_Delete_VLAN_And_IP_On_It_Multiple_Times_With_BMC_Reboot
207 [Setup] Test Setup Execution
208
209 FOR ${i} IN RANGE ${5}
210 Create VLAN ${vlan_id}
211 Verify Existence Of VLAN ${vlan_id}
212 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
213 ${vlan_ip_uri}= Get VLAN URI For IP ${vlan_id} ${ip}
214 Delete IP And Object ${ip} ${vlan_ip_uri}
215 Get VLAN URI For IP ${vlan_id} ${ip} expected_result=error
216 Delete VLANs [${vlan_id}]
217 Verify Existence Of VLAN ${vlan_id} expected_result=error
218 Initiate BMC Reboot
219 Sleep ${NETWORK_TIMEOUT}s
220 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
221 Verify Existence Of VLAN ${vlan_id} expected_result=error
222 END
223
224 ${lan_config}= Get LAN Print Dict
225 Valid Value lan_config['802.1q VLAN ID'] ["Disabled"]
226
227
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600228*** Keywords ***
229
230
231Test Setup Execution
232 [Documentation] Check and delete all previously created VLAN if any.
233
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600234 Printn
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600235 ${lan_config}= Get LAN Print Dict
236 Return From Keyword If '${lan_config['802.1q VLAN ID']}' == 'Disabled'
237
238 # Get all VLAN ID on interface eth0.
239 ${vlan_ids}= Get VLAN IDs
240
241 ${initial_vlan_config}= Create List
242 Set Suite Variable ${initial_vlan_config}
243
244 FOR ${vlan_id} IN @{vlan_ids}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600245 ${vlan_records}= Read Properties
246 ... ${NETWORK_MANAGER}eth0_${vlan_id}${/}enumerate quiet=1
247 ${vlan_record}= Filter Struct
248 ... ${vlan_records} [('Origin', '${static_network_resource}')]
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600249
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600250 ${id}= Convert To Integer ${vlan_id}
251 Set Initial VLAN Config ${vlan_record} ${id}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600252 END
253 Rprint Vars initial_vlan_config
254
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600255 Delete VLANs ${vlan_ids}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600256
257
258Set Initial VLAN Config
259 [Documentation] Set suite level list of Initial VLAN Config.
260 [Arguments] ${vlan_record} ${id}
261
262 # Description of argument(s):
263 # vlan_record Dictionary of IP configuration information of a VLAN.
264 # Example:
265 # /xyz/openbmc_project/network/eth0_55/ipv4/5fb2cfe6": {
266 # "Address": "x.x.x.x",
267 # "Gateway": "",
268 # "Origin": "xyz.openbmc_project.Network.IP.AddressOrigin.Static",
269 # "PrefixLength": 16,
270 # "Type": "xyz.openbmc_project.Network.IP.Protocol.IPv4"}
271 #
272 # id The VLAN ID corresponding to the IP Configuration records contained
273 # in the variable "vlan_record".
274
275 ${uris}= Get Dictionary Keys ${vlan_record}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600276
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600277 FOR ${uri} IN @{uris}
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600278 Append To List ${initial_vlan_config} ${id} ${vlan_record['${uri}']['Address']}
279 ... ${vlan_record['${uri}']['PrefixLength']}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600280 END
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600281
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600282 Run Keyword If @{uris} == @{EMPTY}
283 ... Append To List ${initial_vlan_config} ${id} ${EMPTY} ${EMPTY}
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
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600295 Run Keyword If '${initial_vlan_config[${index+1}]}' == '${EMPTY}'
296 ... Create VLAN ${initial_vlan_config[${index}]}
297 ... ELSE IF '${previous_id}' == '${initial_vlan_config[${index}]}'
298 ... Configure Network Settings On VLAN ${initial_vlan_config[${index}]}
299 ... ${initial_vlan_config[${index+1}]} ${initial_vlan_config[${index+2}]}
300 ... ELSE Run Keywords Create VLAN ${initial_vlan_config[${index}]} AND
301 ... Configure Network Settings On VLAN ${initial_vlan_config[${index}]}
302 ... ${initial_vlan_config[${index+1}]} ${initial_vlan_config[${index+2}]}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600303
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600304 ${previous_id}= Set Variable ${initial_vlan_config[${index}]}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600305 END
306
307
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600308Delete VLANs
309 [Documentation] Delete one or more VLANs.
310 [Arguments] ${ids} ${interface}=eth0
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600311
312 # Description of argument(s):
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600313 # ids A list of VLAN IDs (e.g. ['53'] or ['53', '35', '12']). Note that the
314 # caller may simply pass a list variable or he/she may specify a
315 # python-like list specification (see examples below).
316 # interface The physical interface for the VLAN (e.g. 'eth0').
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600317
Anvesh Kumar Rayankula14455f42019-12-12 03:06:21 -0600318 # Example calls:
319 # Delete VLANs ${vlan_ids}
320 # Delete Vlans [53, 35]
321
322 # Allow for python-like list specifications (e.g. ids=['53']).
323 ${vlan_ids}= Source To Object ${ids}
324
325 FOR ${id} IN @{vlan_ids}
326 OpenBMC Delete Request ${NETWORK_MANAGER}${interface}_${id}
327 END
328 Run Key U Sleep \ ${NETWORK_TIMEOUT}s
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600329
330
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600331Get VLAN IDs
332 [Documentation] Return all VLAN IDs.
333
334 ${vlan_ids} ${stderr} ${rc}= BMC Execute Command
335 ... /sbin/ip addr | grep @eth0 | cut -f1 -d@ | cut -f2 -d.
336 ${vlan_ids}= Split String ${vlan_ids}
337
George Keishing409df052024-01-17 22:36:14 +0530338 RETURN @{vlan_ids}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600339
340
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600341Get VLAN URI For IP
342 [Documentation] Get and return the URI for a VLAN IP.
343 [Arguments] ${vlan_id} ${vlan_ip} ${expected_result}=valid
344
345 # Description of argument(s):
346 # vlan_id The VLAN ID (e.g. '53').
347 # vlan_ip The VLAN IP (e.g. 'x.x.x.x').
348
349 ${vlan_records}= Read Properties
350 ... ${NETWORK_MANAGER}eth0_${vlan_id}${/}enumerate quiet=1
351 ${vlan_record}= Filter Struct ${vlan_records} [('Address', '${vlan_ip}')]
352 ${num_vlan_records}= Get Length ${vlan_record}
353 ${status}= Run Keyword And Return Status Should Be True ${num_vlan_records} > 0
354 ... msg=Could not find a uri for vlan "${vlan_id}" with IP "${vlan_ip}".
355
356 Run Keyword If '${expected_result}' == 'valid'
357 ... Should Be Equal ${status} ${True}
George Keishingf7022192019-12-11 11:30:09 -0600358 ... msg=VLAN IP URI doesn't exist!.
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600359 ... ELSE
360 ... Should Be Equal ${status} ${False}
361 ... msg=VLAN IP URI exists!.
362 ${uris}= Get Dictionary Keys ${vlan_record}
363 Return From Keyword If @{uris} == @{EMPTY}
364
George Keishing409df052024-01-17 22:36:14 +0530365 RETURN ${uris[${0}]}
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600366
367
368Verify Existence Of VLAN
369 [Documentation] Verify VLAN ID exists.
370 [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid
371
372 # Description of argument(s):
373 # id The VLAN ID (e.g. id:'53').
374 # interface Physical Interface on which the VLAN is defined.
375 # expected_result Expected status to check existence or non-existence of VLAN.
376
377 ${vlan_ids}= Get VLAN IDs
378 ${cli_status}= Run Keyword And Return Status
379 ... Valid List vlan_ids required_values=['${id}']
380
381 ${network_records}= Read Properties ${NETWORK_MANAGER}
382 ${rest_status}= Run Keyword And Return Status Valid List network_records
383 ... required_values=['${NETWORK_MANAGER}${interface}_${id}']
384
385 Should Be Equal ${rest_status} ${cli_status}
386 ... msg=REST and CLI Output are not the same.
387 Run Keyword If '${expected_result}' == 'valid'
388 ... Should Be Equal ${rest_status} ${True}
George Keishingf7022192019-12-11 11:30:09 -0600389 ... msg=VLAN ID doesn't exist!.
Naman Navin Hegdead14a722019-11-04 12:28:21 -0600390 ... ELSE
391 ... Should Be Equal ${rest_status} ${False}
392 ... msg=VLAN ID exists!.