blob: 33542a4a5baef0fd107935f1f819a17617525430 [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
16Library Collections
17
18Suite Teardown Suite Teardown Execution
19
20
21*** Variables ***
22${vlan_id} ${53}
23${invalid_vlan_id} abc
24${vlan_resource} ${NETWORK_MANAGER}action/VLAN
25${network_resource} xyz.openbmc_project.Network.IP.Protocol.IPv4
26${static_network_resource} xyz.openbmc_project.Network.IP.AddressOrigin.Static
27${ip} 10.6.6.10
28${netmask} ${24}
29${gateway} 0.0.0.0
30${initial_vlan_config} @{EMPTY}
31
32
33*** Test Cases ***
34
35
36Add VLAN Via REST And Verify
37 [Documentation] Add VLAN via REST and verify it via REST and IPMI.
38 [Tags] Add_VLAN_Via_REST_And_Verify
39 [Setup] Test Setup Execution
40 [Teardown] Delete VLAN ${vlan_id}
41
42 Create VLAN ${vlan_id}
43 Verify Existence Of VLAN ${vlan_id}
44
45 ${lan_config}= Get LAN Print Dict
46 Valid Value lan_config['802.1q VLAN ID'] ["${vlan_id}"]
47
48
49Add Invalid VLAN Via REST And Verify
50 [Documentation] Add Invalid VLAN via REST and verify.
51 [Tags] Add_Invalid_VLAN_Via_REST_And_Verify
52
53 Create VLAN ${invalid_vlan_id} expected_result=error
54
55
56Delete VLAN Via REST
57 [Documentation] Delete VLAN via REST and verify it via REST and IPMI.
58 [Tags] Delete_VLAN_Via_REST
59 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
60
61 Verify Existence Of VLAN ${vlan_id}
62 Delete VLAN ${vlan_id}
63 Verify Existence Of VLAN ${vlan_id} expected_result=error
64
65 ${lan_config}= Get LAN Print Dict
66 Valid Value lan_config['802.1q VLAN ID'] ["Disabled"]
67
68
69Configure Network Settings On VLAN Via REST
70 [Documentation] Configure IP on VLAN and verify it via REST and IPMI.
71 [Tags] Configure_Network_Settings_On_VLAN_Via_REST
72 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
73 [Teardown] Delete VLAN ${vlan_id}
74
75 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
76 Get VLAN URI For IP ${vlan_id} ${ip}
77
78 ${lan_config}= Get LAN Print Dict
79 Valid Value lan_config['IP Address'] ["${ip}"]
80
81
82Delete IP On VLAN Via REST
83 [Documentation] Delete IP on VLAN and verify it via REST and IPMI.
84 [Tags] Delete_IP_On_VLAN_Via_REST
85 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
86 [Teardown] Delete VLAN ${vlan_id}
87
88 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
89 ${lan_config}= Get LAN Print Dict
90 Valid Value lan_config['IP Address'] ["${ip}"]
91
92 ${vlan_ip_uri}= Get VLAN URI For IP ${vlan_id} ${ip}
93 Delete IP And Object ${ip} ${vlan_ip_uri}
94
95 Get VLAN URI For IP ${vlan_id} ${ip} expected_result=error
96
97 ${lan_config}= Get LAN Print Dict
98 Should Not Match ${lan_config['IP Address']} ${ip}
99
100
101Delete VLAN When IP Is Configured Via REST
102 [Documentation] Delete IP on VLAN and verify using IPMI.
103 [Tags] Delete_VLAN_When_IP_Is_Configured_Via_REST
104 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id}
105 [Teardown] Delete VLAN ${vlan_id}
106
107 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
108 ${lan_config}= Get LAN Print Dict
109 Valid Value lan_config['IP Address'] ["${ip}"]
110 Delete VLAN ${vlan_id}
111
112 Verify Existence Of VLAN ${vlan_id} expected_result=error
113
114 ${lan_config}= Get LAN Print Dict
115 Valid Value lan_config['802.1q VLAN ID'] ["Disabled"]
116
117
118Configure VLAN And Check Persistency On Reboot
119 [Documentation] Create VLAN ID & IP , reboot and verify.
120 [Tags] Configure_VLAN_And_Check_Persistency_On_Reboot
121 [Setup] Test Setup Execution
122 [Teardown] Delete VLAN ${vlan_id}
123
124 Create VLAN ${vlan_id}
125 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask}
126 ${lan_config}= Get LAN Print Dict
127 Valid Value lan_config['IP Address'] ["${ip}"]
128 Valid Value lan_config['802.1q VLAN ID'] ["${vlan_id}"]
129
130 Initiate BMC Reboot
131
132 Verify Existence Of VLAN ${vlan_id}
133 Get VLAN URI For IP ${vlan_id} ${ip}
134
135 ${lan_config}= Get LAN Print Dict
136 Valid Value lan_config['IP Address'] ["${ip}"]
137 Valid Value lan_config['802.1q VLAN ID'] ["${vlan_id}"]
138
139
140*** Keywords ***
141
142
143Test Setup Execution
144 [Documentation] Check and delete all previously created VLAN if any.
145
146 ${lan_config}= Get LAN Print Dict
147 Return From Keyword If '${lan_config['802.1q VLAN ID']}' == 'Disabled'
148
149 # Get all VLAN ID on interface eth0.
150 ${vlan_ids}= Get VLAN IDs
151
152 ${initial_vlan_config}= Create List
153 Set Suite Variable ${initial_vlan_config}
154
155 FOR ${vlan_id} IN @{vlan_ids}
156 ${vlan_records}= Read Properties
157 ... ${NETWORK_MANAGER}eth0_${vlan_id}${/}enumerate quiet=1
158 ${vlan_record}= Filter Struct
159 ... ${vlan_records} [('Origin', '${static_network_resource}')]
160
161 ${id}= Convert To Integer ${vlan_id}
162 Set Initial VLAN Config ${vlan_record} ${id}
163 END
164 Rprint Vars initial_vlan_config
165
166 FOR ${vlan_id} IN @{vlan_ids}
167 Delete VLAN ${vlan_id}
168 END
169
170
171Set Initial VLAN Config
172 [Documentation] Set suite level list of Initial VLAN Config.
173 [Arguments] ${vlan_record} ${id}
174
175 # Description of argument(s):
176 # vlan_record Dictionary of IP configuration information of a VLAN.
177 # Example:
178 # /xyz/openbmc_project/network/eth0_55/ipv4/5fb2cfe6": {
179 # "Address": "x.x.x.x",
180 # "Gateway": "",
181 # "Origin": "xyz.openbmc_project.Network.IP.AddressOrigin.Static",
182 # "PrefixLength": 16,
183 # "Type": "xyz.openbmc_project.Network.IP.Protocol.IPv4"}
184 #
185 # id The VLAN ID corresponding to the IP Configuration records contained
186 # in the variable "vlan_record".
187
188 ${uris}= Get Dictionary Keys ${vlan_record}
189 FOR ${uri} IN @{uris}
190 Append To List ${initial_vlan_config} ${id} ${vlan_record['${uri}']['Address']}
191 ... ${vlan_record['${uri}']['PrefixLength']}
192 END
193 Run Keyword If @{uris} == @{EMPTY}
194 ... Append To List ${initial_vlan_config} ${id} ${EMPTY} ${EMPTY}
195
196
197Suite Teardown Execution
198 [Documentation] Restore VLAN configuration.
199
200 ${length}= Get Length ${initial_vlan_config}
201 Return From Keyword If ${length} == ${0}
202
203 ${previous_id}= Set Variable ${EMPTY}
204 FOR ${index} IN RANGE 0 ${length} 3
205
206 Run Keyword If '${initial_vlan_config[${index+1}]}' == '${EMPTY}'
207 ... Create VLAN ${initial_vlan_config[${index}]}
208 ... ELSE IF '${previous_id}' == '${initial_vlan_config[${index}]}'
209 ... Configure Network Settings On VLAN ${initial_vlan_config[${index}]}
210 ... ${initial_vlan_config[${index+1}]} ${initial_vlan_config[${index+2}]}
211 ... ELSE Run Keywords Create VLAN ${initial_vlan_config[${index}]} AND
212 ... Configure Network Settings On VLAN ${initial_vlan_config[${index}]}
213 ... ${initial_vlan_config[${index+1}]} ${initial_vlan_config[${index+2}]}
214
215 ${previous_id}= Set Variable ${initial_vlan_config[${index}]}
216 END
217
218
219Delete VLAN
220 [Documentation] Delete a VLAN.
221 [Arguments] ${id} ${interface}=eth0
222
223 # Description of argument(s):
224 # id The VLAN ID (e.g. '53').
225 # interface The physical interface for the VLAN(e.g. 'eth0').
226
227 OpenBMC Delete Request ${NETWORK_MANAGER}${interface}_${id}
228 Sleep ${NETWORK_TIMEOUT}s
229
230
231Create VLAN
232 [Documentation] Create a VLAN.
233 [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid
234
235 # Description of argument(s):
236 # id The VLAN ID (e.g. '53').
237 # interface The physical interface for the VLAN(e.g. 'eth0').
238
239 @{data_vlan_id}= Create List ${interface} ${id}
240 ${data}= Create Dictionary data=@{data_vlan_id}
241 ${resp}= OpenBMC Post Request ${vlan_resource} data=${data}
242 ${resp.status_code}= Convert To String ${resp.status_code}
243 ${status}= Run Keyword And Return Status
244 ... Valid Value resp.status_code ["${HTTP_OK}"]
245
246 Run Keyword If '${expected_result}' == 'error'
247 ... Should Be Equal ${status} ${False}
248 ... msg=Configuration of an invalid VLAN ID Failed.
249 ... ELSE
250 ... Should Be Equal ${status} ${True}
251 ... msg=Configuration of a valid VLAN ID Failed.
252
253 Sleep ${NETWORK_TIMEOUT}s
254
255
256Get VLAN IDs
257 [Documentation] Return all VLAN IDs.
258
259 ${vlan_ids} ${stderr} ${rc}= BMC Execute Command
260 ... /sbin/ip addr | grep @eth0 | cut -f1 -d@ | cut -f2 -d.
261 ${vlan_ids}= Split String ${vlan_ids}
262
263 [Return] @{vlan_ids}
264
265
266Configure Network Settings On VLAN
267 [Documentation] Configure network settings.
268 [Arguments] ${id} ${ip_addr} ${prefix_len} ${gateway_ip}=${gateway}
269 ... ${expected_result}=valid ${interface}=eth0
270
271 # Description of argument(s):
272 # id The VLAN ID (e.g. '53').
273 # ip_addr IP address of VLAN Interface.
274 # prefix_len Prefix length of VLAN Interface.
275 # gateway_ip Gateway IP address of VLAN Interface.
276 # expected_result Expected status of network setting configuration.
277 # interface Physical Interface on which the VLAN is defined.
278
279 @{ip_parm_list}= Create List ${network_resource}
280 ... ${ip_addr} ${prefix_len} ${gateway_ip}
281
282 ${data}= Create Dictionary data=@{ip_parm_list}
283
284 Run Keyword And Ignore Error OpenBMC Post Request
285 ... ${NETWORK_MANAGER}${interface}_${id}/action/IP data=${data}
286
287 # After any modification on network interface, BMC restarts network
288 # module, wait until it is reachable. Then wait 15 seconds for new
289 # configuration to be updated on BMC.
290
291 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_TIMEOUT}
292 ... ${NETWORK_RETRY_TIME}
293 Sleep ${NETWORK_TIMEOUT}s
294
295 # Verify whether new IP address is populated on BMC system.
296 # It should not allow to configure invalid settings.
297 ${status}= Run Keyword And Return Status
298 ... Verify IP On BMC ${ip_addr}
299
300 Run Keyword If '${expected_result}' == 'error'
301 ... Should Be Equal ${status} ${False}
302 ... msg=Configuration of invalid IP Failed.
303 ... ELSE
304 ... Should Be Equal ${status} ${True}
305 ... msg=Configuration of valid IP Failed.
306
307
308Get VLAN URI For IP
309 [Documentation] Get and return the URI for a VLAN IP.
310 [Arguments] ${vlan_id} ${vlan_ip} ${expected_result}=valid
311
312 # Description of argument(s):
313 # vlan_id The VLAN ID (e.g. '53').
314 # vlan_ip The VLAN IP (e.g. 'x.x.x.x').
315
316 ${vlan_records}= Read Properties
317 ... ${NETWORK_MANAGER}eth0_${vlan_id}${/}enumerate quiet=1
318 ${vlan_record}= Filter Struct ${vlan_records} [('Address', '${vlan_ip}')]
319 ${num_vlan_records}= Get Length ${vlan_record}
320 ${status}= Run Keyword And Return Status Should Be True ${num_vlan_records} > 0
321 ... msg=Could not find a uri for vlan "${vlan_id}" with IP "${vlan_ip}".
322
323 Run Keyword If '${expected_result}' == 'valid'
324 ... Should Be Equal ${status} ${True}
325 ... msg=VLAN IP URI Dosen't exist!.
326 ... ELSE
327 ... Should Be Equal ${status} ${False}
328 ... msg=VLAN IP URI exists!.
329 ${uris}= Get Dictionary Keys ${vlan_record}
330 Return From Keyword If @{uris} == @{EMPTY}
331
332 [Return] ${uris[${0}]}
333
334
335Verify Existence Of VLAN
336 [Documentation] Verify VLAN ID exists.
337 [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid
338
339 # Description of argument(s):
340 # id The VLAN ID (e.g. id:'53').
341 # interface Physical Interface on which the VLAN is defined.
342 # expected_result Expected status to check existence or non-existence of VLAN.
343
344 ${vlan_ids}= Get VLAN IDs
345 ${cli_status}= Run Keyword And Return Status
346 ... Valid List vlan_ids required_values=['${id}']
347
348 ${network_records}= Read Properties ${NETWORK_MANAGER}
349 ${rest_status}= Run Keyword And Return Status Valid List network_records
350 ... required_values=['${NETWORK_MANAGER}${interface}_${id}']
351
352 Should Be Equal ${rest_status} ${cli_status}
353 ... msg=REST and CLI Output are not the same.
354 Run Keyword If '${expected_result}' == 'valid'
355 ... Should Be Equal ${rest_status} ${True}
356 ... msg=VLAN ID Dosen't exist!.
357 ... ELSE
358 ... Should Be Equal ${rest_status} ${False}
359 ... msg=VLAN ID exists!.