Debian Codegraph @

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

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2017, Dag Wieers (@dagwieers) <[email protected]>
3 # Copyright: (c) 2020, Lionel Hercot (@lhercot) <[email protected]>
4 # Copyright: (c) 2024, Samita Bhattacharjee (@samiib) <[email protected]>
5
6 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
7
8 - name: Test that we have an ACI APIC host, ACI username and ACI password
9 ansible.builtin.fail:
10 msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
11 when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined
12
13 - include_tasks: httpapi_connection.yml
14 tags: httpapi_connection
15
16 - name: Delete old log files to clean test directory
17 ansible.builtin.file:
18 path: "{{ item }}"
19 state: absent
20 with_items:
21 - "{{ aci_hostname }}_cm_add_tenant.json"
22 - "{{ aci_hostname }}_nm_add_tenant.json"
23 - "{{ aci_hostname }}_cm_add_tenant_again.json"
24 - "{{ aci_hostname }}_nm_add_tenant_again.json"
25 - "{{ aci_hostname }}_cm_add_tenant_descr.json"
26 - "{{ aci_hostname }}_nm_add_tenant_descr.json"
27 - "{{ aci_hostname }}_cm_add_tenant_descr_again.json"
28 - "{{ aci_hostname }}_nm_add_tenant_descr_again.json"
29 - "{{ aci_hostname }}_cm_remove_tenant.json"
30 - "{{ aci_hostname }}_nm_remove_tenant.json"
31 - "{{ aci_hostname }}_cm_remove_tenant_again.json"
32 - "{{ aci_hostname }}_nm_remove_tenant_again.json"
33
34 # CLEAN ENVIRONMENT
35 - name: Remove tenant
36 cisco.aci.aci_tenant: &tenant_absent
37 host: '{{ aci_hostname }}'
38 username: '{{ aci_username }}'
39 password: '{{ aci_password }}'
40 validate_certs: '{{ aci_validate_certs | default(false) }}'
41 use_ssl: '{{ aci_use_ssl | default(true) }}'
42 use_proxy: '{{ aci_use_proxy | default(true) }}'
43 output_level: '{{ aci_output_level | default("info") }}'
44 tenant: ansible_test
45 state: absent
46
47 # ADD TENANT
48 - name: Add tenant (check_mode)
49 cisco.aci.aci_tenant: &tenant_present
50 host: '{{ aci_hostname }}'
51 username: '{{ aci_username }}'
52 password: '{{ aci_password }}'
53 validate_certs: '{{ aci_validate_certs | default(false) }}'
54 use_ssl: '{{ aci_use_ssl | default(true) }}'
55 use_proxy: '{{ aci_use_proxy | default(true) }}'
56 output_level: '{{ aci_output_level | default("info") }}'
57 tenant: ansible_test
58 state: present
59 annotation: ansible_test
60 owner_key: ansible_key
61 owner_tag: ansible_tag
62 output_path: "{{ aci_hostname }}_cm_add_tenant.json"
63 check_mode: true
64 register: cm_add_tenant
65
66 - name: Dump content of files
67 ansible.builtin.debug:
68 msg: "{{ lookup('file', aci_hostname +'_cm_add_tenant.json')}}"
69
70 - name: Add tenant (normal mode)
71 cisco.aci.aci_tenant:
72 <<: *tenant_present
73 output_path: "{{ aci_hostname }}_nm_add_tenant.json"
74 register: nm_add_tenant
75
76 - name: Add tenant again (check_mode)
77 cisco.aci.aci_tenant:
78 <<: *tenant_present
79 output_path: "{{ aci_hostname }}_cm_add_tenant_again.json"
80 check_mode: true
81 register: cm_add_tenant_again
82
83 - name: Add tenant again (normal mode)
84 cisco.aci.aci_tenant:
85 <<: *tenant_present
86 output_path: "{{ aci_hostname }}_nm_add_tenant_again.json"
87 register: nm_add_tenant_again
88
89 - name: Dump content of files
90 ansible.builtin.debug:
91 msg: "{{ lookup('file', aci_hostname + '_cm_add_tenant.json')}}"
92
93
94 - name: Store file content on variables for create object
95 ansible.builtin.set_fact:
96 fc_cm_add_tenant: "{{ lookup('file', aci_hostname + '_cm_add_tenant.json') | from_json }}"
97 fc_nm_add_tenant: "{{ lookup('file', aci_hostname + '_nm_add_tenant.json') | from_json }}"
98 fc_cm_add_tenant_again: "{{ lookup('file', aci_hostname + '_cm_add_tenant_again.json') }}"
99 fc_nm_add_tenant_again: "{{ lookup('file', aci_hostname + '_nm_add_tenant_again.json') }}"
100
101 - name: Log file content verification for create object
102 ansible.builtin.assert:
103 that:
104 - fc_cm_add_tenant.0.fvTenant.attributes.name == 'ansible_test'
105 - fc_cm_add_tenant.0.fvTenant.attributes.dn == 'uni/tn-ansible_test'
106 - fc_nm_add_tenant.0.fvTenant.attributes.name == 'ansible_test'
107 - fc_nm_add_tenant.0.fvTenant.attributes.dn == 'uni/tn-ansible_test'
108 - fc_cm_add_tenant_again == ''
109 - fc_nm_add_tenant_again == ''
110
111 - name: Verify add_tenant
112 ansible.builtin.assert:
113 that:
114 - cm_add_tenant is changed
115 - nm_add_tenant is changed
116 - cm_add_tenant_again is not changed
117 - nm_add_tenant_again is not changed
118 - nm_add_tenant.current[0].fvTenant.attributes.annotation == 'ansible_test'
119 - cm_add_tenant.proposed.fvTenant.attributes.annotation == 'ansible_test'
120 - nm_add_tenant.current[0].fvTenant.attributes.ownerKey == 'ansible_key'
121 - cm_add_tenant.proposed.fvTenant.attributes.ownerKey == 'ansible_key'
122 - nm_add_tenant.current[0].fvTenant.attributes.ownerTag == 'ansible_tag'
123 - cm_add_tenant.proposed.fvTenant.attributes.ownerTag == 'ansible_tag'
124
125 # CHANGE TENANT
126 - name: Change description and annotation/owner_tag/owner_key of tenant (check_mode)
127 cisco.aci.aci_tenant:
128 <<: *tenant_present
129 description: Ansible test tenant
130 annotation: ansible_test_changed
131 owner_key: ansible_key_changed
132 owner_tag: ansible_tag_changed
133 output_path: "{{ aci_hostname }}_cm_add_tenant_descr.json"
134 check_mode: true
135 register: cm_add_tenant_descr
136
137 - name: Change description and annotation/owner_tag/owner_key of tenant (normal mode)
138 cisco.aci.aci_tenant:
139 <<: *tenant_present
140 description: Ansible test tenant
141 annotation: ansible_test_changed
142 owner_key: ansible_key_changed
143 owner_tag: ansible_tag_changed
144 output_path: "{{ aci_hostname }}_nm_add_tenant_descr.json"
145 register: nm_add_tenant_descr
146
147 - name: Change description and annotation/owner_tag/owner_key of tenant again (check_mode)
148 cisco.aci.aci_tenant:
149 <<: *tenant_present
150 description: Ansible test tenant
151 annotation: ansible_test_changed
152 owner_key: ansible_key_changed
153 owner_tag: ansible_tag_changed
154 output_path: "{{ aci_hostname }}_cm_add_tenant_descr_again.json"
155 check_mode: true
156 register: cm_add_tenant_descr_again
157
158 - name: Change description and annotation of tenant again (normal mode)
159 cisco.aci.aci_tenant:
160 <<: *tenant_present
161 description: Ansible test tenant
162 annotation: ansible_test_changed
163 owner_key: ansible_key_changed
164 owner_tag: ansible_tag_changed
165 output_path: "{{ aci_hostname }}_nm_add_tenant_descr_again.json"
166 register: nm_add_tenant_descr_again
167
168 - name: Store file content on variables for update object
169 ansible.builtin.set_fact:
170 fc_cm_add_tenant_descr: "{{ lookup('file', aci_hostname + '_cm_add_tenant_descr.json') | from_json }}"
171 fc_nm_add_tenant_descr: "{{ lookup('file', aci_hostname + '_nm_add_tenant_descr.json') | from_json }}"
172 fc_cm_add_tenant_descr_again: "{{ lookup('file', aci_hostname + '_cm_add_tenant_descr_again.json') }}"
173 fc_nm_add_tenant_descr_again: "{{ lookup('file', aci_hostname + '_nm_add_tenant_descr_again.json') }}"
174
175 - name: Log file content verification for update object
176 ansible.builtin.assert:
177 that:
178 - fc_cm_add_tenant_descr.0.fvTenant.attributes.descr == 'Ansible test tenant'
179 - fc_nm_add_tenant_descr.0.fvTenant.attributes.descr == 'Ansible test tenant'
180 - fc_cm_add_tenant_descr_again == ''
181 - fc_nm_add_tenant_descr_again == ''
182
183 - name: Verify add_tenant_descr
184 ansible.builtin.assert:
185 that:
186 - cm_add_tenant_descr is changed
187 - nm_add_tenant_descr is changed
188 - cm_add_tenant_descr_again is not changed
189 - nm_add_tenant_descr_again is not changed
190 - cm_add_tenant_descr.proposed.fvTenant.attributes.annotation == 'ansible_test_changed'
191 - nm_add_tenant_descr.current[0].fvTenant.attributes.annotation == 'ansible_test_changed'
192 - cm_add_tenant_descr_again.proposed.fvTenant.attributes.annotation == 'ansible_test_changed'
193 - nm_add_tenant_descr_again.current[0].fvTenant.attributes.annotation == 'ansible_test_changed'
194 - nm_add_tenant_descr.current[0].fvTenant.attributes.ownerKey == 'ansible_key_changed'
195 - cm_add_tenant_descr.proposed.fvTenant.attributes.ownerKey == 'ansible_key_changed'
196 - nm_add_tenant_descr_again.current[0].fvTenant.attributes.ownerKey == 'ansible_key_changed'
197 - cm_add_tenant_descr_again.proposed.fvTenant.attributes.ownerKey == 'ansible_key_changed'
198 - nm_add_tenant_descr.current[0].fvTenant.attributes.ownerTag == 'ansible_tag_changed'
199 - cm_add_tenant_descr.proposed.fvTenant.attributes.ownerTag == 'ansible_tag_changed'
200 - nm_add_tenant_descr_again.current[0].fvTenant.attributes.ownerTag == 'ansible_tag_changed'
201 - cm_add_tenant_descr_again.proposed.fvTenant.attributes.ownerTag == 'ansible_tag_changed'
202
203
204 # ADD TENANT AGAIN
205 - name: Add tenant again with no description (check_mode)
206 cisco.aci.aci_tenant:
207 <<: *tenant_present
208 annotation: ansible_test_changed
209 owner_key: ansible_key_changed
210 owner_tag: ansible_tag_changed
211 check_mode: true
212 register: cm_add_tenant_again_no_descr
213
214 - name: Add tenant again with no description (normal mode)
215 cisco.aci.aci_tenant:
216 <<: *tenant_present
217 annotation: ansible_test_changed
218 owner_key: ansible_key_changed
219 owner_tag: ansible_tag_changed
220 register: nm_add_tenant_again_no_descr
221
222 - name: Verify add_tenant_again_no_descr
223 ansible.builtin.assert:
224 that:
225 - cm_add_tenant_again_no_descr is not changed
226 - nm_add_tenant_again_no_descr is not changed
227
228 # TEST NO VERIFICATION
229 - name: Create tenant with no verification (check mode)
230 cisco.aci.aci_tenant: &aci_tenant_no_verify
231 <<: *tenant_present
232 tenant: anstest-no-verify
233 description: Ansible Test
234 no_verification: true
235 check_mode: true
236 register: tenant_present_no_verify_cm
237
238 - name: Create tenant with no verification
239 cisco.aci.aci_tenant:
240 <<: *aci_tenant_no_verify
241 register: tenant_present_no_verify
242
243 - name: Create tenant with no verification again
244 cisco.aci.aci_tenant:
245 <<: *aci_tenant_no_verify
246 register: tenant_present_no_verify_again
247
248 - name: Update tenant with no verification
249 cisco.aci.aci_tenant:
250 <<: *aci_tenant_no_verify
251 description: Ansible Test No Verify
252 register: update_tenant_present_no_verify
253
254 - name: Delete tenant with no verification
255 cisco.aci.aci_tenant:
256 <<: *aci_tenant_no_verify
257 state: absent
258 register: delete_tenant_present_no_verify
259
260 - name: Delete tenant with no verification again
261 cisco.aci.aci_tenant:
262 <<: *aci_tenant_no_verify
263 state: absent
264 register: delete_tenant_present_no_verify_again
265
266 - name: No verification asserts
267 ansible.builtin.assert:
268 that:
269 - tenant_present_no_verify_cm is changed
270 - tenant_present_no_verify_cm.current_verified == false
271 - tenant_present_no_verify_cm.current.0 == tenant_present_no_verify_cm.proposed
272 - tenant_present_no_verify is changed
273 - tenant_present_no_verify.current_verified == false
274 - tenant_present_no_verify.current.0 == tenant_present_no_verify.proposed
275 - tenant_present_no_verify.previous == []
276 - tenant_present_no_verify_again is not changed
277 - tenant_present_no_verify_again.current_verified == true
278 - tenant_present_no_verify_again.current.0.fvTenant.attributes.name == "anstest-no-verify"
279 - tenant_present_no_verify_again.current.0.fvTenant.attributes.descr == "Ansible Test"
280 - tenant_present_no_verify_again.previous.0.fvTenant.attributes.name == "anstest-no-verify"
281 - tenant_present_no_verify_again.previous.0.fvTenant.attributes.descr == "Ansible Test"
282 - update_tenant_present_no_verify is changed
283 - update_tenant_present_no_verify.current_verified == false
284 - update_tenant_present_no_verify.current.0 == update_tenant_present_no_verify.proposed
285 - update_tenant_present_no_verify.previous.0.fvTenant.attributes.name == "anstest-no-verify"
286 - update_tenant_present_no_verify.previous.0.fvTenant.attributes.descr == "Ansible Test"
287 - delete_tenant_present_no_verify is changed
288 - delete_tenant_present_no_verify.current_verified == false
289 - delete_tenant_present_no_verify.current.0 == delete_tenant_present_no_verify.proposed
290 - delete_tenant_present_no_verify.previous.0.fvTenant.attributes.name == "anstest-no-verify"
291 - delete_tenant_present_no_verify.previous.0.fvTenant.attributes.descr == "Ansible Test No Verify"
292 - delete_tenant_present_no_verify_again is not changed
293 - delete_tenant_present_no_verify_again.current_verified == true
294 - delete_tenant_present_no_verify_again.current == []
295 - delete_tenant_present_no_verify_again.previous == []
296 - delete_tenant_present_no_verify_again.proposed == {}
297
298 # QUERY ALL TENANTS
299 - name: Query all tenants (check_mode)
300 cisco.aci.aci_tenant: &tenant_query
301 host: '{{ aci_hostname }}'
302 username: '{{ aci_username }}'
303 password: '{{ aci_password }}'
304 validate_certs: '{{ aci_validate_certs | default(false) }}'
305 use_ssl: '{{ aci_use_ssl | default(true) }}'
306 use_proxy: '{{ aci_use_proxy | default(true) }}'
307 output_level: '{{ aci_output_level | default("info") }}'
308 state: query
309 check_mode: true
310 register: cm_query_all_tenants
311
312 - name: Query all tenants (normal mode)
313 cisco.aci.aci_tenant: *tenant_query
314 register: nm_query_all_tenants
315
316 - name: Verify query_all_tenants
317 ansible.builtin.assert:
318 that:
319 - cm_query_all_tenants is not changed
320 - nm_query_all_tenants is not changed
321 # NOTE: Order of tenants is not stable between calls
322 #- cm_query_all_tenants == nm_query_all_tenants
323
324
325 # QUERY A TENANT
326 - name: Query our tenant
327 cisco.aci.aci_tenant:
328 <<: *tenant_query
329 tenant: ansible_test
330 check_mode: true
331 register: cm_query_tenant
332
333 - name: Query our tenant
334 cisco.aci.aci_tenant:
335 <<: *tenant_query
336 tenant: ansible_test
337 register: nm_query_tenant
338
339 - name: Verify query_tenant
340 ansible.builtin.assert:
341 that:
342 - cm_query_tenant is not changed
343 - nm_query_tenant is not changed
344 - cm_query_tenant == nm_query_tenant
345 - cm_query_tenant.current[0].fvTenant.attributes.annotation == 'ansible_test_changed'
346 - nm_query_tenant.current[0].fvTenant.attributes.annotation == 'ansible_test_changed'
347 - nm_query_tenant.current[0].fvTenant.attributes.ownerKey == 'ansible_key_changed'
348 - cm_query_tenant.current[0].fvTenant.attributes.ownerKey == 'ansible_key_changed'
349 - nm_query_tenant.current[0].fvTenant.attributes.ownerTag == 'ansible_tag_changed'
350 - cm_query_tenant.current[0].fvTenant.attributes.ownerTag == 'ansible_tag_changed'
351
352
353 - name: Update tenant with default annotation
354 cisco.aci.aci_tenant:
355 <<: *tenant_present
356 annotation: "{{ fake_var | default(omit) }}"
357 register: default_annotation
358
359 - name: Assertion check for update tenant with default annotation
360 ansible.builtin.assert:
361 that:
362 - default_annotation is changed
363 - default_annotation.current.0.fvTenant.attributes.annotation == 'orchestrator:ansible'
364
365 # REMOVE TENANT
366 - name: Remove tenant (check_mode)
367 cisco.aci.aci_tenant:
368 <<: *tenant_absent
369 output_path: "{{ aci_hostname }}_cm_remove_tenant.json"
370 check_mode: true
371 register: cm_remove_tenant
372
373 - name: Remove tenant (normal mode)
374 cisco.aci.aci_tenant:
375 <<: *tenant_absent
376 output_path: "{{ aci_hostname }}_nm_remove_tenant.json"
377 register: nm_remove_tenant
378
379 - name: Remove tenant again (check_mode)
380 cisco.aci.aci_tenant:
381 <<: *tenant_absent
382 output_path: "{{ aci_hostname }}_cm_remove_tenant_again.json"
383 check_mode: true
384 register: cm_remove_tenant_again
385
386 - name: Remove tenant again (normal mode)
387 cisco.aci.aci_tenant:
388 <<: *tenant_absent
389 output_path: "{{ aci_hostname }}_nm_remove_tenant_again.json"
390 register: nm_remove_tenant_again
391
392 - name: Store file content on variables for delete object
393 ansible.builtin.set_fact:
394 fc_cm_remove_tenant: "{{ lookup('file', aci_hostname + '_cm_remove_tenant.json') | from_json }}"
395 fc_nm_remove_tenant: "{{ lookup('file', aci_hostname + '_nm_remove_tenant.json') | from_json }}"
396 fc_cm_remove_tenant_again: "{{ lookup('file', aci_hostname + '_cm_remove_tenant_again.json') }}"
397 fc_nm_remove_tenant_again: "{{ lookup('file', aci_hostname + '_nm_remove_tenant_again.json') }}"
398
399 - name: Log file content verification for delete object
400 ansible.builtin.assert:
401 that:
402 - fc_cm_remove_tenant.0.fvTenant.attributes.status == 'deleted'
403 - fc_cm_remove_tenant.0.fvTenant.attributes.dn == 'uni/tn-ansible_test'
404 - fc_nm_remove_tenant == [{}]
405 - fc_cm_remove_tenant_again == ''
406 - fc_nm_remove_tenant_again == ''
407
408 - name: Verify remove_tenant
409 ansible.builtin.assert:
410 that:
411 - cm_remove_tenant is changed
412 - nm_remove_tenant is changed
413 - cm_remove_tenant_again is not changed
414 - nm_remove_tenant_again is not changed
415
416
417 # QUERY NON-EXISTING TENANT
418 - name: Query non-existing tenant (check_mode)
419 cisco.aci.aci_tenant:
420 <<: *tenant_query
421 tenant: ansible_test
422 check_mode: true
423 register: cm_query_non_tenant
424
425 - name: Query non-existing tenant (normal mode)
426 cisco.aci.aci_tenant:
427 <<: *tenant_query
428 tenant: ansible_test
429 register: nm_query_non_tenant
430
431 # TODO: Implement more tests
432 - name: Verify query_non_tenant
433 ansible.builtin.assert:
434 that:
435 - cm_query_non_tenant is not changed
436 - nm_query_non_tenant is not changed
437 - cm_query_non_tenant == nm_query_non_tenant