Debian Codegraph @

ansible_collections/cisco/intersight/tests/integration/targets/intersight_vlan_policy/tasks/tests.yml

raw
1 ---
2 - block:
3 - name: Define anchor for Intersight API login info
4 ansible.builtin.set_fact:
5 api_info: &api_info
6 api_private_key: "{{ api_private_key }}"
7 api_key_id: "{{ api_key_id }}"
8 api_uri: "{{ api_uri | default(omit) }}"
9 validate_certs: "{{ validate_certs | default(omit) }}"
10 organization: "{{ organization }}"
11
12 - name: Make sure Env is clean
13 cisco.intersight.intersight_vlan_policy:
14 <<: *api_info
15 name: "{{ item }}"
16 state: absent
17 loop:
18 - test_vlan_policy
19 - test_vlan_policy_2
20 - test_vlan_policy_minimal
21 - test_vlan_policy_with_vlans
22 - test_private_vlan_policy
23 - test_vlan_policy_with_ranges
24 - test_vlan_policy_bulk_chunking
25 - test_vlan_policy_multicast_to_shared
26
27 - name: Create vlan policy - check-mode
28 cisco.intersight.intersight_vlan_policy:
29 <<: *api_info
30 name: test_vlan_policy
31 description: "Test VLAN policy description"
32 tags:
33 - Key: Site
34 Value: Test
35 - Key: Site2
36 Value: Test2
37 check_mode: true
38 register: creation_res_check_mode
39
40 - name: Verify vlan policy was not created - check-mode
41 ansible.builtin.assert:
42 that:
43 - creation_res_check_mode is changed
44 - creation_res_check_mode.api_response.vlan_policy == {}
45 - creation_res_check_mode.api_response.vlans | length == 0
46
47 - name: Create vlan policy
48 cisco.intersight.intersight_vlan_policy:
49 <<: *api_info
50 name: test_vlan_policy
51 description: "Test VLAN policy description"
52 tags:
53 - Key: Site
54 Value: Test
55 - Key: Site2
56 Value: Test2
57 register: creation_res
58
59 - name: Fetch info after creation
60 cisco.intersight.intersight_vlan_policy_info:
61 <<: *api_info
62 name: test_vlan_policy
63 register: creation_info_res
64
65 - name: Verify vlan policy creation by info
66 ansible.builtin.assert:
67 that:
68 - creation_res.changed
69 - creation_info_res.api_response.vlan_policy.Name == 'test_vlan_policy'
70
71 - name: Verify vlan policy creation response aligns with info response
72 ansible.builtin.assert:
73 that:
74 - creation_res.api_response.vlan_policy.Name == creation_info_res.api_response.vlan_policy.Name
75
76 - name: Create vlan policy (idempotency check)
77 cisco.intersight.intersight_vlan_policy:
78 <<: *api_info
79 name: test_vlan_policy
80 description: "Test VLAN policy description"
81 tags:
82 - Key: Site
83 Value: Test
84 - Key: Site2
85 Value: Test2
86 register: creation_res_ide
87
88 - name: Verify vlan policy creation (idempotency check)
89 ansible.builtin.assert:
90 that:
91 - not creation_res_ide.changed
92
93 - name: Update description of an existing vlan policy
94 cisco.intersight.intersight_vlan_policy:
95 <<: *api_info
96 name: test_vlan_policy
97 description: "Updated VLAN policy description"
98 tags:
99 - Key: Site
100 Value: Test
101 - Key: Site2
102 Value: Test2
103 register: changed_res
104
105 - name: Fetch info after change
106 cisco.intersight.intersight_vlan_policy_info:
107 <<: *api_info
108 name: test_vlan_policy
109 register: change_info_res
110
111 - name: Verify vlan policy change by info
112 ansible.builtin.assert:
113 that:
114 - changed_res.changed
115 - change_info_res.api_response.vlan_policy.Name == 'test_vlan_policy'
116 - change_info_res.api_response.vlan_policy.Description == 'Updated VLAN policy description'
117
118 - name: Create another vlan policy
119 cisco.intersight.intersight_vlan_policy:
120 <<: *api_info
121 name: test_vlan_policy_2
122 description: "Test another VLAN policy description"
123 register: creation_res_b
124
125 - name: Fetch all vlan policies under selected organization
126 cisco.intersight.intersight_vlan_policy_info:
127 <<: *api_info
128 register: creation_info_res_b
129
130 - name: Check that there are at least 2 vlan policies under this organization
131 ansible.builtin.assert:
132 that:
133 - creation_info_res_b.api_response | length > 1
134
135 - name: Test creation without optional parameters
136 cisco.intersight.intersight_vlan_policy:
137 <<: *api_info
138 name: test_vlan_policy_minimal
139 register: creation_res_minimal
140
141 - name: Verify minimal vlan policy creation
142 ansible.builtin.assert:
143 that:
144 - creation_res_minimal.changed
145 - creation_res_minimal.api_response.vlan_policy.Name == 'test_vlan_policy_minimal'
146
147 - name: Create Multicast policy
148 cisco.intersight.intersight_multicast_policy:
149 <<: *api_info
150 name: multicast_policy_for_vlan_policy
151 description: "Test multicast policy description"
152 register: multicast_policy_res
153
154 # Test VLAN Policy with VLANs
155 - name: Create VLAN policy with standard VLANs
156 cisco.intersight.intersight_vlan_policy:
157 <<: *api_info
158 name: test_vlan_policy_with_vlans
159 description: "Policy with standard VLANs"
160 vlans:
161 - prefix: "prod"
162 vlan_id: 100
163 auto_allow_on_uplinks: true
164 enable_sharing: false
165 multicast_policy_name: "multicast_policy_for_vlan_policy"
166 is_native: false
167 state: present
168 - prefix: "dev"
169 vlan_id: 200
170 auto_allow_on_uplinks: false
171 enable_sharing: false
172 multicast_policy_name: "multicast_policy_for_vlan_policy"
173 is_native: false
174 state: present
175 - prefix: "mgmt"
176 vlan_id: 300
177 auto_allow_on_uplinks: true
178 enable_sharing: false
179 multicast_policy_name: "multicast_policy_for_vlan_policy"
180 is_native: true
181 register: vlan_policy_with_vlans
182
183 - name: Verify VLAN policy with VLANs creation
184 ansible.builtin.assert:
185 that:
186 - vlan_policy_with_vlans.changed
187 - vlan_policy_with_vlans.api_response.vlan_policy.Name == 'test_vlan_policy_with_vlans'
188 - vlan_policy_with_vlans.api_response.vlans | length == 3
189 - vlan_policy_with_vlans.api_response.vlans[0].Name == 'prod_100'
190 - vlan_policy_with_vlans.api_response.vlans[1].Name == 'dev_200'
191 - vlan_policy_with_vlans.api_response.vlans[2].Name == 'mgmt_300'
192 - vlan_policy_with_vlans.api_response.vlans[0].IsNative == false
193 - vlan_policy_with_vlans.api_response.vlans[2].IsNative == true
194 - vlan_policy_with_vlans.api_response.vlans[0].VlanId == 100
195 - vlan_policy_with_vlans.api_response.vlans[1].VlanId == 200
196 - vlan_policy_with_vlans.api_response.vlans[2].VlanId == 300
197
198
199 - name: Create VLAN policy with Private VLANs
200 cisco.intersight.intersight_vlan_policy:
201 <<: *api_info
202 name: test_private_vlan_policy
203 description: "Policy with Private VLANs"
204 vlans:
205 - prefix: "primary"
206 vlan_id: 79
207 enable_sharing: true
208 sharing_type: "primary"
209 auto_allow_on_uplinks: true
210 - prefix: "isolated"
211 vlan_id: 80
212 enable_sharing: true
213 sharing_type: "isolated"
214 primary_vlan_id: 79
215 auto_allow_on_uplinks: true
216 - prefix: "community"
217 vlan_id: 81
218 enable_sharing: true
219 sharing_type: "community"
220 primary_vlan_id: 79
221 auto_allow_on_uplinks: true
222 register: private_vlan_policy
223
224 - name: Verify Private VLAN policy creation
225 ansible.builtin.assert:
226 that:
227 - private_vlan_policy.changed
228 - private_vlan_policy.api_response.vlan_policy.Name == 'test_private_vlan_policy'
229 - private_vlan_policy.api_response.vlans | length == 3
230 - private_vlan_policy.api_response.vlans[0].Name == 'primary_79'
231 - private_vlan_policy.api_response.vlans[1].Name == 'isolated_80'
232 - private_vlan_policy.api_response.vlans[2].Name == 'community_81'
233 - private_vlan_policy.api_response.vlans[0].VlanId == 79
234 - private_vlan_policy.api_response.vlans[1].VlanId == 80
235 - private_vlan_policy.api_response.vlans[2].VlanId == 81
236 - private_vlan_policy.api_response.vlans[0].SharingType == 'Primary'
237 - private_vlan_policy.api_response.vlans[1].SharingType == 'Isolated'
238 - private_vlan_policy.api_response.vlans[2].SharingType == 'Community'
239 - private_vlan_policy.api_response.vlans[1].PrimaryVlanId == 79
240 - private_vlan_policy.api_response.vlans[2].PrimaryVlanId == 79
241
242 - name: Create VLAN policy with VLAN ranges
243 cisco.intersight.intersight_vlan_policy:
244 <<: *api_info
245 name: test_vlan_policy_with_ranges
246 description: "Policy with VLAN ranges"
247 vlans:
248 - prefix: "range1"
249 vlan_id: "30-35"
250 auto_allow_on_uplinks: true
251 enable_sharing: false
252 multicast_policy_name: "multicast_policy_for_vlan_policy"
253 - prefix: "range2"
254 vlan_id: "40-42"
255 auto_allow_on_uplinks: false
256 enable_sharing: false
257 multicast_policy_name: "multicast_policy_for_vlan_policy"
258 - prefix: "single"
259 vlan_id: 50
260 auto_allow_on_uplinks: true
261 enable_sharing: false
262 multicast_policy_name: "multicast_policy_for_vlan_policy"
263 register: vlan_policy_with_ranges
264
265 - name: Verify VLAN policy with ranges creation
266 ansible.builtin.assert:
267 that:
268 - vlan_policy_with_ranges.changed
269 - vlan_policy_with_ranges.api_response.vlan_policy.Name == 'test_vlan_policy_with_ranges'
270 - vlan_policy_with_ranges.api_response.vlans | length == 10
271 - vlan_policy_with_ranges.api_response.vlans[0].Name == 'range1_30'
272 - vlan_policy_with_ranges.api_response.vlans[0].VlanId == 30
273 - vlan_policy_with_ranges.api_response.vlans[5].Name == 'range1_35'
274 - vlan_policy_with_ranges.api_response.vlans[5].VlanId == 35
275 - vlan_policy_with_ranges.api_response.vlans[6].Name == 'range2_40'
276 - vlan_policy_with_ranges.api_response.vlans[6].VlanId == 40
277 - vlan_policy_with_ranges.api_response.vlans[8].Name == 'range2_42'
278 - vlan_policy_with_ranges.api_response.vlans[8].VlanId == 42
279 - vlan_policy_with_ranges.api_response.vlans[9].Name == 'single_50'
280 - vlan_policy_with_ranges.api_response.vlans[9].VlanId == 50
281 - vlan_policy_with_ranges.api_response.vlans[0].AutoAllowOnUplinks == true
282 - vlan_policy_with_ranges.api_response.vlans[6].AutoAllowOnUplinks == false
283
284 - name: Create VLAN policy with ranges again (idempotency check)
285 cisco.intersight.intersight_vlan_policy:
286 <<: *api_info
287 name: test_vlan_policy_with_ranges
288 description: "Policy with VLAN ranges"
289 vlans:
290 - prefix: "range1"
291 vlan_id: "30-35"
292 auto_allow_on_uplinks: true
293 enable_sharing: false
294 multicast_policy_name: "multicast_policy_for_vlan_policy"
295 - prefix: "range2"
296 vlan_id: "40-42"
297 auto_allow_on_uplinks: false
298 enable_sharing: false
299 multicast_policy_name: "multicast_policy_for_vlan_policy"
300 - prefix: "single"
301 vlan_id: 50
302 auto_allow_on_uplinks: true
303 enable_sharing: false
304 multicast_policy_name: "multicast_policy_for_vlan_policy"
305 register: vlan_policy_with_ranges_idempotent
306
307 - name: Verify VLAN policy with ranges idempotency
308 ansible.builtin.assert:
309 that:
310 - not vlan_policy_with_ranges_idempotent.changed
311
312 - name: Create VLAN policy with large VLAN range (bulk chunking test)
313 cisco.intersight.intersight_vlan_policy:
314 <<: *api_info
315 name: test_vlan_policy_bulk_chunking
316 description: "Policy with large VLAN range to test bulk API chunking"
317 vlans:
318 - prefix: "bulk"
319 vlan_id: "100-250"
320 auto_allow_on_uplinks: true
321 enable_sharing: false
322 multicast_policy_name: "multicast_policy_for_vlan_policy"
323 register: vlan_policy_bulk_chunking
324
325 - name: Verify VLAN policy with large range creation (bulk chunking)
326 ansible.builtin.assert:
327 that:
328 - vlan_policy_bulk_chunking.changed
329 - vlan_policy_bulk_chunking.api_response.vlan_policy.Name == 'test_vlan_policy_bulk_chunking'
330 - vlan_policy_bulk_chunking.api_response.vlans | length == 151
331 - vlan_policy_bulk_chunking.api_response.vlans[0].Name == 'bulk_100'
332 - vlan_policy_bulk_chunking.api_response.vlans[0].VlanId == 100
333 - vlan_policy_bulk_chunking.api_response.vlans[150].Name == 'bulk_250'
334 - vlan_policy_bulk_chunking.api_response.vlans[150].VlanId == 250
335
336 - name: Update VLAN policy with large range (idempotency check for bulk operations)
337 cisco.intersight.intersight_vlan_policy:
338 <<: *api_info
339 name: test_vlan_policy_bulk_chunking
340 description: "Policy with large VLAN range to test bulk API chunking"
341 vlans:
342 - prefix: "bulk"
343 vlan_id: "100-250"
344 auto_allow_on_uplinks: true
345 enable_sharing: false
346 multicast_policy_name: "multicast_policy_for_vlan_policy"
347 register: vlan_policy_bulk_chunking_idempotent
348
349 - name: Verify bulk operation idempotency
350 ansible.builtin.assert:
351 that:
352 - not vlan_policy_bulk_chunking_idempotent.changed
353
354 # Test info module with various filters
355 - name: Test info module - fetch specific policy with VLANs
356 cisco.intersight.intersight_vlan_policy_info:
357 <<: *api_info
358 name: test_vlan_policy_with_vlans
359 register: specific_policy_info
360
361 - name: Verify specific policy info
362 ansible.builtin.assert:
363 that:
364 - specific_policy_info.api_response.vlan_policy.Name == 'test_vlan_policy_with_vlans'
365 - specific_policy_info.api_response.vlans | length == 4 # 3 created + 1 default VLAN
366
367 - name: Test info module - fetch all policies
368 cisco.intersight.intersight_vlan_policy_info:
369 <<: *api_info
370 register: all_policies_info
371
372 - name: Verify all policies info
373 ansible.builtin.assert:
374 that:
375 - all_policies_info.api_response | length >= 4
376
377 - name: Test info module - filter by VLAN name
378 cisco.intersight.intersight_vlan_policy_info:
379 <<: *api_info
380 vlan_name: "prod_100"
381 name: test_vlan_policy_with_vlans
382 register: vlan_filtered_info
383
384 - name: Verify VLAN filtered info
385 ansible.builtin.assert:
386 that:
387 - vlan_filtered_info.api_response.vlans | length == 1
388 - vlan_filtered_info.api_response.vlan_policy.Name == 'test_vlan_policy_with_vlans'
389 - vlan_filtered_info.api_response.vlans[0].Name == 'prod_100'
390 - vlan_filtered_info.api_response.vlans[0].VlanId == 100
391 - vlan_filtered_info.api_response.vlans[0].IsNative == false
392 - vlan_filtered_info.api_response.vlans[0].AutoAllowOnUplinks == true
393
394 # Test converting from multicast-based (non-shared) to shared VLANs
395 - name: Create VLAN policy with multicast-based VLANs
396 cisco.intersight.intersight_vlan_policy:
397 <<: *api_info
398 name: test_vlan_policy_multicast_to_shared
399 description: "Policy with multicast VLANs that will be converted to shared"
400 vlans:
401 - prefix: "convert"
402 vlan_id: "500-505"
403 auto_allow_on_uplinks: true
404 enable_sharing: false
405 multicast_policy_name: "multicast_policy_for_vlan_policy"
406 register: multicast_vlan_creation
407
408 - name: Verify multicast-based VLANs creation
409 ansible.builtin.assert:
410 that:
411 - multicast_vlan_creation.changed
412 - multicast_vlan_creation.api_response.vlan_policy.Name == 'test_vlan_policy_multicast_to_shared'
413 - multicast_vlan_creation.api_response.vlans | length == 6
414 - multicast_vlan_creation.api_response.vlans[0].SharingType == 'None'
415
416 - name: Convert multicast VLANs to shared VLANs (Primary)
417 cisco.intersight.intersight_vlan_policy:
418 <<: *api_info
419 name: test_vlan_policy_multicast_to_shared
420 description: "Policy with VLANs converted to shared"
421 vlans:
422 - prefix: "convert"
423 vlan_id: "500-505"
424 auto_allow_on_uplinks: true
425 enable_sharing: true
426 sharing_type: "primary"
427 register: multicast_to_shared_conversion
428
429 - name: Verify conversion from multicast to shared VLANs
430 ansible.builtin.assert:
431 that:
432 - multicast_to_shared_conversion.changed
433 - multicast_to_shared_conversion.api_response.vlan_policy.Name == 'test_vlan_policy_multicast_to_shared'
434 - multicast_to_shared_conversion.api_response.vlans | length == 6
435 - multicast_to_shared_conversion.api_response.vlans[0].SharingType == 'Primary'
436 - multicast_to_shared_conversion.api_response.vlans[0].Name == 'convert_500'
437 - multicast_to_shared_conversion.api_response.vlans[5].Name == 'convert_505'
438
439 - name: Re-apply shared VLANs configuration (idempotency test)
440 cisco.intersight.intersight_vlan_policy:
441 <<: *api_info
442 name: test_vlan_policy_multicast_to_shared
443 description: "Policy with VLANs converted to shared"
444 vlans:
445 - prefix: "convert"
446 vlan_id: "500-505"
447 auto_allow_on_uplinks: true
448 enable_sharing: true
449 sharing_type: "primary"
450 register: shared_vlans_idempotent
451
452 - name: Verify idempotency of shared VLANs configuration
453 ansible.builtin.assert:
454 that:
455 - not shared_vlans_idempotent.changed
456 - shared_vlans_idempotent.api_response.vlans | length == 6
457
458 # Test VLAN removal
459 - name: Update VLAN policy - remove one VLAN
460 cisco.intersight.intersight_vlan_policy:
461 <<: *api_info
462 name: test_vlan_policy_with_vlans
463 description: "Policy with reduced VLANs"
464 vlans:
465 - prefix: "prod"
466 vlan_id: 100
467 auto_allow_on_uplinks: true
468 enable_sharing: false
469 multicast_policy_name: "multicast_policy_for_vlan_policy"
470 - prefix: "dev"
471 vlan_id: 200
472 auto_allow_on_uplinks: false
473 enable_sharing: false
474 multicast_policy_name: "multicast_policy_for_vlan_policy"
475 state: absent
476 - prefix: "mgmt"
477 vlan_id: 300
478 auto_allow_on_uplinks: true
479 enable_sharing: false
480 multicast_policy_name: "multicast_policy_for_vlan_policy"
481 is_native: true
482 register: vlan_removal_result
483
484 - name: Verify VLAN removal
485 ansible.builtin.assert:
486 that:
487 - vlan_removal_result.changed
488 - vlan_removal_result.api_response.vlan_policy.Name == 'test_vlan_policy_with_vlans'
489 - vlan_removal_result.api_response.vlans | length == 2
490 always:
491 - name: Remove vlan policies
492 cisco.intersight.intersight_vlan_policy:
493 <<: *api_info
494 name: "{{ item }}"
495 state: absent
496 loop:
497 - test_vlan_policy
498 - test_vlan_policy_2
499 - test_vlan_policy_minimal
500 - test_vlan_policy_with_vlans
501 - test_private_vlan_policy
502 - test_vlan_policy_with_ranges
503 - test_vlan_policy_bulk_chunking
504 - test_vlan_policy_multicast_to_shared
505
506 - name: Remove multicast policy
507 cisco.intersight.intersight_multicast_policy:
508 <<: *api_info
509 name: multicast_policy_for_vlan_policy
510 state: absent