Debian Codegraph @

ansible_collections/cisco/aci/tests/integration/targets/aci_epg/tasks/main.yml

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2017, Jacob McGill (@jmcgill298)
3 # Copyright: (c) 2020, Shreyas Srish (@shrsr)
4 # Copyright: (c) 2023, Christian Kolrep (@Christian-Kolrep)
5 # Copyright: (c) 2024, Akini Ross (@akinross)
6 # Copyright: (c) 2024, Samita Bhattacharjee (@samiib) <[email protected]>
7
8 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
9
10 - name: Test that we have an ACI APIC host, ACI username and ACI password
11 ansible.builtin.fail:
12 msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
13 when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined
14
15 - name: Set vars
16 ansible.builtin.set_fact:
17 aci_info: &aci_info
18 host: "{{ aci_hostname }}"
19 username: "{{ aci_username }}"
20 password: "{{ aci_password }}"
21 validate_certs: '{{ aci_validate_certs | default(false) }}'
22 use_ssl: '{{ aci_use_ssl | default(true) }}'
23 use_proxy: '{{ aci_use_proxy | default(true) }}'
24 output_level: debug
25
26 - name: Verify Cloud and Non-Cloud Sites in use.
27 ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml
28
29 - name: Execute tasks only for non-cloud sites
30 when: query_cloud.current == [] # This condition will execute only non-cloud sites
31 block: # block specifies execution of tasks within, based on conditions
32 - name: Ensure tenant exists for tests to kick off
33 cisco.aci.aci_tenant: &aci_tenant_present
34 <<: *aci_info
35 state: present
36 tenant: ansible_test
37 register: tenant_present
38
39 - name: Ensure monitoring policy exists
40 cisco.aci.aci_epg_monitoring_policy:
41 <<: *aci_info
42 monitoring_policy: check
43 tenant: ansible_test
44
45 - name: Ensure bd exists for tests to kick off
46 cisco.aci.aci_bd: &aci_bd_present
47 <<: *aci_tenant_present
48 bd: anstest
49 register: bd_present
50
51 - name: Ensure ap exists for tests to kick off
52 cisco.aci.aci_ap: &aci_ap_present
53 <<: *aci_tenant_present
54 ap: anstest
55 register: ap_present
56
57 - name: Ensure epg anstest dont exist for tests to kick off
58 cisco.aci.aci_epg:
59 <<: *aci_ap_present
60 epg: anstest
61 state: absent
62
63 - name: Ensure epg anstest2 dont exist for tests to kick off
64 cisco.aci.aci_epg:
65 <<: *aci_ap_present
66 epg: anstest2
67 state: absent
68
69 - name: Ensure epg anstest_useg_epg dont exist for tests to kick off
70 cisco.aci.aci_epg:
71 <<: *aci_ap_present
72 epg: anstest_useg_epg
73 state: absent
74
75 - name: Create epg - check mode works
76 cisco.aci.aci_epg: &aci_epg_present
77 <<: *aci_ap_present
78 epg: anstest
79 bd: anstest
80 description: Ansible Test
81 monitoring_policy: check
82 custom_qos_policy: check
83 check_mode: true
84 register: epg_present_check_mode
85
86 - name: Create epg - creation works
87 cisco.aci.aci_epg:
88 <<: *aci_epg_present
89 register: epg_present
90
91 - name: Create epg - idempotency works
92 cisco.aci.aci_epg:
93 <<: *aci_epg_present
94 register: epg_present_idempotent
95
96 - name: Update epg - update works
97 cisco.aci.aci_epg:
98 <<: *aci_epg_present
99 description: Ansible Test Update
100 register: epg_present_update
101
102 - name: Create epg - missing param
103 cisco.aci.aci_epg:
104 <<: *aci_epg_present
105 ap: "{{ fakevar | default(omit) }}"
106 ignore_errors: true
107 register: epg_present_missing_param
108
109 - name: Create epg - used for query
110 cisco.aci.aci_epg:
111 <<: *aci_epg_present
112 epg: anstest2
113
114 - name: Create and Update assertions
115 ansible.builtin.assert:
116 that:
117 - epg_present_check_mode is changed
118 - epg_present_check_mode.previous == []
119 - epg_present_check_mode.sent.fvAEPg.attributes != {}
120 - epg_present_check_mode.sent.fvAEPg.children.0.fvRsBd.attributes.tnFvBDName == "anstest"
121 - epg_present_check_mode.sent.fvAEPg.children.1.fvRsAEPgMonPol.attributes.tnMonEPGPolName == 'check'
122 - epg_present_check_mode.sent.fvAEPg.children.2.fvRsCustQosPol.attributes.tnQosCustomPolName == 'check'
123 - epg_present is changed
124 - epg_present.sent == epg_present_check_mode.sent
125 - epg_present.current.0.fvAEPg.attributes.annotation == 'orchestrator:ansible'
126 - epg_present_idempotent is not changed
127 - epg_present_idempotent.sent == {}
128 - epg_present_update is changed
129 - epg_present_update.sent.fvAEPg.attributes.descr == 'Ansible Test Update'
130 - epg_present_missing_param is failed
131 - 'epg_present_missing_param.msg == "state is present but all of the following are missing: ap"'
132
133 # TEST NO VERIFICATION
134 - name: create epg with no verification (check mode)
135 cisco.aci.aci_epg: &aci_epg_no_verify
136 <<: *aci_epg_present
137 epg: anstest-no-verify
138 no_verification: true
139 check_mode: true
140 register: epg_present_no_verify_cm
141
142 - name: create epg with no verification
143 cisco.aci.aci_epg:
144 <<: *aci_epg_no_verify
145 register: epg_present_no_verify
146
147 - name: create epg with no verification again
148 cisco.aci.aci_epg:
149 <<: *aci_epg_no_verify
150 register: epg_present_no_verify_again
151
152 - name: update epg with no verification
153 cisco.aci.aci_epg:
154 <<: *aci_epg_no_verify
155 description: Ansible Test No Verify
156 register: update_epg_present_no_verify
157
158 - name: delete epg with no verification
159 cisco.aci.aci_epg:
160 <<: *aci_epg_no_verify
161 state: absent
162 register: delete_epg_present_no_verify
163
164 - name: delete epg with no verification again
165 cisco.aci.aci_epg:
166 <<: *aci_epg_no_verify
167 state: absent
168 register: delete_epg_present_no_verify_again
169
170 - name: no verification asserts
171 ansible.builtin.assert:
172 that:
173 - epg_present_no_verify_cm is changed
174 - epg_present_no_verify_cm.current_verified == false
175 - epg_present_no_verify_cm.current.0 == epg_present_no_verify_cm.proposed
176 - epg_present_no_verify is changed
177 - epg_present_no_verify.current_verified == false
178 - epg_present_no_verify.current.0 == epg_present_no_verify.proposed
179 - epg_present_no_verify.previous == []
180 - epg_present_no_verify_again is not changed
181 - epg_present_no_verify_again.current_verified == true
182 - epg_present_no_verify_again.current.0.fvAEPg.attributes.name == "anstest-no-verify"
183 - epg_present_no_verify_again.current.0.fvAEPg.attributes.descr == "Ansible Test"
184 - epg_present_no_verify_again.previous.0.fvAEPg.attributes.name == "anstest-no-verify"
185 - epg_present_no_verify_again.previous.0.fvAEPg.attributes.descr == "Ansible Test"
186 - update_epg_present_no_verify is changed
187 - update_epg_present_no_verify.current_verified == false
188 - update_epg_present_no_verify.current.0 == update_epg_present_no_verify.proposed
189 - update_epg_present_no_verify.previous.0.fvAEPg.attributes.name == "anstest-no-verify"
190 - update_epg_present_no_verify.previous.0.fvAEPg.attributes.descr == "Ansible Test"
191 - delete_epg_present_no_verify is changed
192 - delete_epg_present_no_verify.current_verified == false
193 - delete_epg_present_no_verify.current.0 == delete_epg_present_no_verify.proposed
194 - delete_epg_present_no_verify.previous.0.fvAEPg.attributes.name == "anstest-no-verify"
195 - delete_epg_present_no_verify.previous.0.fvAEPg.attributes.descr == "Ansible Test No Verify"
196 - delete_epg_present_no_verify_again is not changed
197 - delete_epg_present_no_verify_again.current_verified == true
198 - delete_epg_present_no_verify_again.current == []
199 - delete_epg_present_no_verify_again.previous == []
200 - delete_epg_present_no_verify_again.proposed == {}
201
202 - name: Query specific epg
203 cisco.aci.aci_epg:
204 <<: *aci_epg_present
205 state: query
206 register: epg_query
207
208 - name: Query all epgs
209 cisco.aci.aci_epg:
210 <<: *aci_tenant_present
211 state: query
212 tenant: "{{ fakevar | default(omit) }}"
213 register: epg_query_all
214
215 - name: Query assertions
216 ansible.builtin.assert:
217 that:
218 - epg_query is not changed
219 - epg_query.current | length == 1
220 - epg_query.current.0.fvAEPg.attributes.name == "anstest"
221 - epg_query.current.0.fvAEPg.children.1.fvRsCustQosPol.attributes.tnQosCustomPolName == 'check'
222 - epg_query.current.0.fvAEPg.children.2.fvRsAEPgMonPol.attributes.tnMonEPGPolName == 'check'
223 - '"tn-ansible_test/ap-anstest/epg-anstest.json" in epg_query.url'
224 - epg_query_all is not changed
225 - epg_query_all.current | length > 1
226 - '"?rsp-subtree=full&rsp-subtree-class=fvCrtrn,fvRsAEPgMonPol,fvRsBd" in epg_query_all.filter_string'
227 - '"class/fvAEPg.json" in epg_query_all.url'
228
229 - name: Delete epg - check mode works
230 cisco.aci.aci_epg: &aci_epg_absent
231 <<: *aci_epg_present
232 state: absent
233 check_mode: true
234 register: delete_epg_check_mode
235
236 - name: Delete epg - delete works
237 cisco.aci.aci_epg:
238 <<: *aci_epg_absent
239 register: delete_epg
240
241 - name: Delete epg - idempotency works
242 cisco.aci.aci_epg:
243 <<: *aci_epg_absent
244 register: delete_epg_idempotent
245
246 - name: Delete epg - cleanup extra epg
247 cisco.aci.aci_epg:
248 <<: *aci_epg_absent
249 epg: anstest2
250
251 - name: Delete epg - missing param fails
252 cisco.aci.aci_epg:
253 <<: *aci_epg_absent
254 tenant: "{{ fakevar | default(omit) }}"
255 ignore_errors: true
256 register: delete_epg_missing_param
257
258 - name: Delete assertions
259 ansible.builtin.assert:
260 that:
261 - delete_epg_check_mode is changed
262 - delete_epg_check_mode.previous != []
263 - delete_epg is changed
264 - delete_epg.previous == delete_epg_check_mode.previous
265 - delete_epg_idempotent is not changed
266 - delete_epg_idempotent.previous == []
267 - delete_epg_missing_param is failed
268 - 'delete_epg_missing_param.msg == "state is absent but all of the following are missing: tenant"'
269
270 # USEG SPECIFIC TESTS
271
272 - name: Create useg epg (check mode)
273 cisco.aci.aci_epg: &cm_useg_epg_present
274 <<: *aci_ap_present
275 epg: anstest_useg_epg
276 bd: anstest
277 useg: yes
278 description: uSeg EPG Ansible Test
279 check_mode: true
280 register: cm_useg_epg_present
281
282 - name: Create useg epg (normal mode)
283 cisco.aci.aci_epg: &nm_useg_epg_present
284 <<: *cm_useg_epg_present
285 register: nm_useg_epg_present
286
287 - name: Create useg epg again
288 cisco.aci.aci_epg:
289 <<: *cm_useg_epg_present
290 register: nm_useg_epg_present_again
291
292 - name: Assertions for creating useg epgs
293 ansible.builtin.assert:
294 that:
295 - cm_useg_epg_present is changed
296 - cm_useg_epg_present.current == []
297 - cm_useg_epg_present.previous == []
298 - cm_useg_epg_present.proposed.fvAEPg.attributes.name == 'anstest_useg_epg'
299 - cm_useg_epg_present.proposed.fvAEPg.attributes.isAttrBasedEPg == 'yes'
300 - cm_useg_epg_present.proposed.fvAEPg.children.1.fvCrtrn.attributes.name == 'default'
301 - cm_useg_epg_present.proposed.fvAEPg.children.0.fvRsBd.attributes.tnFvBDName == 'anstest'
302 - nm_useg_epg_present is changed
303 - nm_useg_epg_present.current | length == 1
304 - nm_useg_epg_present.previous == []
305 - nm_useg_epg_present.current.0.fvAEPg.attributes.name == 'anstest_useg_epg'
306 - nm_useg_epg_present.current.0.fvAEPg.attributes.isAttrBasedEPg == 'yes'
307 - nm_useg_epg_present.current.0.fvAEPg.children.0.fvCrtrn.attributes.name == 'default'
308 - nm_useg_epg_present.current.0.fvAEPg.children.1.fvRsBd.attributes.tnFvBDName == 'anstest'
309 - nm_useg_epg_present_again is not changed
310 - nm_useg_epg_present_again.previous | length == 1
311 - nm_useg_epg_present_again.previous.0.fvAEPg.attributes.name == 'anstest_useg_epg'
312 - nm_useg_epg_present_again.previous.0.fvAEPg.children.0.fvCrtrn.attributes.name == 'default'
313 - nm_useg_epg_present_again.previous.0.fvAEPg.children.1.fvRsBd.attributes.tnFvBDName == 'anstest'
314 - nm_useg_epg_present_again.previous.0.fvAEPg.attributes.isAttrBasedEPg == 'yes'
315 - nm_useg_epg_present_again.current | length == 1
316 - nm_useg_epg_present_again.current.0.fvAEPg.attributes.name == 'anstest_useg_epg'
317 - nm_useg_epg_present_again.current.0.fvAEPg.children.0.fvCrtrn.attributes.name == 'default'
318 - nm_useg_epg_present_again.current.0.fvAEPg.children.1.fvRsBd.attributes.tnFvBDName == 'anstest'
319 - nm_useg_epg_present_again.current.0.fvAEPg.attributes.isAttrBasedEPg == 'yes'
320
321 - name: Query useg epg
322 cisco.aci.aci_epg:
323 <<: *nm_useg_epg_present
324 state: query
325 register: useg_epg_present
326
327 - name: Assertions check for query useg epg
328 ansible.builtin.assert:
329 that:
330 - useg_epg_present is not changed
331 - useg_epg_present.current | length == 1
332 - useg_epg_present.current.0.fvAEPg.attributes.name == 'anstest_useg_epg'
333 - useg_epg_present.current.0.fvAEPg.attributes.isAttrBasedEPg == 'yes'
334 - useg_epg_present.current.0.fvAEPg.children.0.fvCrtrn.attributes.name == 'default'
335 - useg_epg_present.current.0.fvAEPg.children.1.fvRsBd.attributes.tnFvBDName == 'anstest'
336
337 - name: Update useg epg
338 cisco.aci.aci_epg:
339 <<: *cm_useg_epg_present
340 match: all
341 precedence: 1
342 register: nm_useg_epg_update
343
344 - name: Update useg epg (error)
345 cisco.aci.aci_epg:
346 <<: *cm_useg_epg_present
347 useg: no
348 ignore_errors: true
349 register: err_useg_epg_update
350
351 - name: Assertions check for update useg epg
352 assert:
353 that:
354 - nm_useg_epg_update is changed
355 - nm_useg_epg_update.previous | length == 1
356 - nm_useg_epg_update.previous.0.fvAEPg.children.0.fvCrtrn.attributes.name == 'default'
357 - nm_useg_epg_update.previous.0.fvAEPg.children.0.fvCrtrn.attributes.prec == '0'
358 - nm_useg_epg_update.previous.0.fvAEPg.children.0.fvCrtrn.attributes.match == 'any'
359 - nm_useg_epg_update.previous.0.fvAEPg.children.1.fvRsBd.attributes.tnFvBDName == 'anstest'
360 - nm_useg_epg_update.current.0.fvAEPg.attributes == nm_useg_epg_update.previous.0.fvAEPg.attributes
361 - nm_useg_epg_update.current | length == 1
362 - nm_useg_epg_update.current.0.fvAEPg.children.0.fvCrtrn.attributes.name == 'default'
363 - nm_useg_epg_update.current.0.fvAEPg.children.0.fvCrtrn.attributes.prec == '1'
364 - nm_useg_epg_update.current.0.fvAEPg.children.0.fvCrtrn.attributes.match == 'all'
365 - nm_useg_epg_update.current.0.fvAEPg.children.1.fvRsBd.attributes.tnFvBDName == 'anstest'
366 - err_useg_epg_update is failed
367 - 'err_useg_epg_update.msg == "Changing attribute useg on existing EPG is not supported."'
368
369 - name: Delete useg epg with (check mode)
370 cisco.aci.aci_epg: &cm_useg_epg_absent
371 <<: *nm_useg_epg_present
372 state: absent
373 check_mode: true
374 register: cm_useg_epg_absent
375
376 - name: Delete useg epg
377 cisco.aci.aci_epg:
378 <<: *cm_useg_epg_absent
379 register: nm_useg_epg_absent
380
381 - name: Delete useg epg again
382 cisco.aci.aci_epg:
383 <<: *cm_useg_epg_absent
384 register: nm_useg_epg_absent_again
385
386 - name: Assertions check for delete useg epg with check mode
387 ansible.builtin.assert:
388 that:
389 - cm_useg_epg_absent is changed
390 - cm_useg_epg_absent.previous | length == 1
391 - cm_useg_epg_absent.previous.0.fvAEPg.attributes.name == 'anstest_useg_epg'
392 - cm_useg_epg_absent.previous.0.fvAEPg.attributes.isAttrBasedEPg == 'yes'
393 - cm_useg_epg_absent.previous.0.fvAEPg.children.0.fvCrtrn.attributes.name == 'default'
394 - cm_useg_epg_absent.previous.0.fvAEPg.children.1.fvRsBd.attributes.tnFvBDName == 'anstest'
395 - cm_useg_epg_absent.current | length == 1
396 - cm_useg_epg_absent.current.0.fvAEPg.attributes.name == 'anstest_useg_epg'
397 - cm_useg_epg_absent.current.0.fvAEPg.attributes.isAttrBasedEPg == 'yes'
398 - cm_useg_epg_absent.current.0.fvAEPg.children.0.fvCrtrn.attributes.name == 'default'
399 - cm_useg_epg_absent.current.0.fvAEPg.children.1.fvRsBd.attributes.tnFvBDName == 'anstest'
400 - cm_useg_epg_absent.proposed == {}
401 - nm_useg_epg_absent is changed
402 - nm_useg_epg_absent.current == []
403 - nm_useg_epg_absent.previous | length == 1
404 - nm_useg_epg_absent.previous.0.fvAEPg.attributes.name == 'anstest_useg_epg'
405 - nm_useg_epg_absent.previous.0.fvAEPg.attributes.isAttrBasedEPg == 'yes'
406 - nm_useg_epg_absent.previous.0.fvAEPg.children.0.fvCrtrn.attributes.name == 'default'
407 - nm_useg_epg_absent.previous.0.fvAEPg.children.1.fvRsBd.attributes.tnFvBDName == 'anstest'
408 - nm_useg_epg_absent_again is not changed
409 - nm_useg_epg_absent_again.current == []
410 - nm_useg_epg_absent_again.previous == []
411
412 - name: Cleanup tenant
413 cisco.aci.aci_tenant:
414 <<: *aci_tenant_present
415 state: absent