Debian Codegraph @

ansible_collections/cisco/aci/tests/integration/targets/aci_rest/tasks/xml_string.yml

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2017, Dag Wieers (@dagwieers) <[email protected]>
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5 - name: Test that we have an ACI APIC host, ACI username and ACI password
6 ansible.builtin.fail:
7 msg: "Please define the following variables: aci_hostname, aci_username and aci_password."
8 when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined
9
10 - name: Set vars
11 ansible.builtin.set_fact:
12 aci_info: &aci_info
13 host: "{{ aci_hostname }}"
14 username: "{{ aci_username }}"
15 password: "{{ aci_password }}"
16 validate_certs: "{{ aci_validate_certs | default(false) }}"
17 use_ssl: "{{ aci_use_ssl | default(true) }}"
18 use_proxy: "{{ aci_use_proxy | default(true) }}"
19 output_level: "{{ aci_output_level | default('info') }}"
20
21 # CLEAN ENVIRONMENT
22 - name: Remove tenant
23 cisco.aci.aci_rest: &tenant_absent
24 <<: *aci_info
25 path: /api/mo/uni/tn-[ansible_test].xml
26 method: delete
27
28 - name: Remove tenant2
29 cisco.aci.aci_rest: &tenant_absent_2
30 <<: *aci_info
31 path: /api/mo/uni/tn-[ansible_test_2].xml
32 method: delete
33
34 # ADD TENANT
35 - name: Add tenant (check mode)
36 cisco.aci.aci_rest:
37 <<: *aci_info
38 path: /api/mo/uni.xml
39 method: post
40 content:
41 <fvTenant name="ansible_test"/>
42 register: cm_add_tenant
43 check_mode: true
44
45 - name: Add tenant 2 (check mode)
46 cisco.aci.aci_rest:
47 <<: *aci_info
48 path: /api/mo/uni.xml
49 method: post
50 content:
51 {
52 "fvTenant": {
53 "attributes": {
54 "name": "ansible_test"
55 }
56 }
57 }
58 register: cm_add_tenant_2
59 check_mode: true
60
61 - name: Verify checkmode did not create tenant
62 cisco.aci.aci_tenant: &tenant_cm_query
63 <<: *aci_info
64 name: ansible_test
65 state: query
66 register: cm_verify_checkmode_tenant
67
68 - name: Verify checkmode POST operation
69 ansible.builtin.assert:
70 that:
71 - cm_add_tenant is changed
72 - '"ansible_test" in cm_add_tenant.proposed'
73 - '"orchestrator:ansible" in cm_add_tenant.proposed'
74 - cm_add_tenant_2 is changed
75 - '"ansible_test" in cm_add_tenant_2.proposed'
76 - '"orchestrator:ansible" in cm_add_tenant_2.proposed'
77 - cm_verify_checkmode_tenant.current == []
78
79 - name: Add tenant (normal mode)
80 cisco.aci.aci_rest: &tenant_present
81 <<: *aci_info
82 path: /api/mo/uni.xml
83 method: post
84 content:
85 {
86 "fvTenant": {
87 "attributes": {
88 "name": "ansible_test"
89 }
90 }
91 }
92 register: nm_add_tenant
93
94 - name: Add tenant again (normal mode)
95 cisco.aci.aci_rest:
96 <<: *tenant_present
97 path: /api/mo/uni.xml
98 content:
99 <fvTenant name="ansible_test"/>
100 register: nm_add_tenant_again
101
102 - name: Verify add_tenant
103 ansible.builtin.assert:
104 that:
105 - nm_add_tenant is changed
106 - nm_add_tenant_again is not changed
107
108 # CHANGE TENANT
109 - name: Change description of tenant (normal mode)
110 cisco.aci.aci_rest: &tenant_changed
111 <<: *aci_info
112 path: /api/mo/uni.xml
113 method: post
114 content:
115 fvTenant:
116 attributes:
117 name: ansible_test
118 descr: Ansible test tenant
119 register: nm_add_tenant_descr
120
121 - name: Change description of tenant again (normal mode)
122 cisco.aci.aci_rest:
123 <<: *tenant_changed
124 path: /api/mo/uni.xml
125 content:
126 fvTenant:
127 attributes:
128 name: ansible_test
129 descr: Ansible test tenant
130 register: nm_add_tenant_descr_again
131
132 - name: Verify add_tenant_descr
133 ansible.builtin.assert:
134 that:
135 - nm_add_tenant_descr is changed
136 - nm_add_tenant_descr_again is not changed
137
138 # ADD TENANT AGAIN
139 - name: Add tenant again with no description (normal mode)
140 cisco.aci.aci_rest:
141 <<: *tenant_present
142 path: /api/mo/uni.xml
143 content:
144 <fvTenant name="ansible_test"/>
145 register: nm_add_tenant_again_no_descr
146
147 - name: Verify add_tenant_again_no_descr
148 ansible.builtin.assert:
149 that:
150 - nm_add_tenant_again_no_descr is not changed
151
152 # QUERY ALL TENANTS
153 - name: Query all tenants (normal mode)
154 cisco.aci.aci_rest: &tenant_query_all
155 <<: *aci_info
156 path: /api/mo/uni/tn-[ansible_test].xml
157 method: get
158 register: nm_query_all_tenants
159
160 - name: Verify query_all_tenants
161 ansible.builtin.assert:
162 that:
163 - nm_query_all_tenants is not changed
164
165 # ADD TENANT 2
166 - name: Add tenant 2 (normal mode)
167 cisco.aci.aci_rest:
168 <<: *tenant_present
169 path: /api/mo/uni.xml
170 content:
171 <fvTenant name="ansible_test_2"/>
172 register: nm_add_tenant_2
173
174 # QUERY ALL TENANTS WITH PAGINATION
175 - name: Query all tenants with pagination (normal mode)
176 cisco.aci.aci_rest: &tenant_query_all_paginated
177 <<: *aci_info
178 path: /api/class/uni/fvTenant.xml
179 page_size: 10
180 page: 0
181 method: get
182 register: nm_query_all_tenants_paginated
183
184 - name: Query all tenant with pagination - Size 1 / Page 0 (normal mode)
185 cisco.aci.aci_rest:
186 <<: *tenant_query_all_paginated
187 page_size: 1
188 page: 0
189 register: nm_query_all_tenants_paginated_1_0
190
191 - name: Query all tenant with pagination - Size 1 / Page 1 (normal mode)
192 cisco.aci.aci_rest:
193 <<: *tenant_query_all_paginated
194 page_size: 1
195 page: 1
196 register: nm_query_all_tenants_paginated_1_1
197
198 - name: Query all tenant with pagination - Size 2 / Page 0 (normal mode)
199 cisco.aci.aci_rest:
200 <<: *tenant_query_all_paginated
201 page_size: 2
202 page: 0
203 register: nm_query_all_tenants_paginated_2_0
204
205 - name: Verify query_all_tenants_paginated
206 ansible.builtin.assert:
207 that:
208 - nm_query_all_tenants_paginated is not changed
209 - nm_query_all_tenants_paginated_1_0 is not changed
210 - nm_query_all_tenants_paginated_1_1 is not changed
211 - nm_query_all_tenants_paginated_2_0 is not changed
212
213 - name: Verify pagination works as expected
214 ansible.builtin.assert:
215 that:
216 - nm_query_all_tenants_paginated is not changed
217 - nm_query_all_tenants_paginated_1_0.imdata | length == 1
218 - nm_query_all_tenants_paginated_1_1.imdata | length == 1
219 - nm_query_all_tenants_paginated_2_0.imdata | length == 2
220 - nm_query_all_tenants_paginated_1_0.imdata.0.fvTenant.attributes.name == nm_query_all_tenants_paginated_2_0.imdata.0.fvTenant.attributes.name
221 - nm_query_all_tenants_paginated_1_1.imdata.0.fvTenant.attributes.name == nm_query_all_tenants_paginated_2_0.imdata.1.fvTenant.attributes.name
222
223 # QUERY A TENANT
224 - name: Query our tenant
225 cisco.aci.aci_rest: &tenant_query
226 <<: *aci_info
227 path: /api/mo/uni/tn-[ansible_test].xml
228 method: get
229 register: nm_query_tenant
230
231 - name: Verify query_tenant
232 ansible.builtin.assert:
233 that:
234 - nm_query_tenant is not changed
235
236 # REMOVE TENANT
237 - name: Remove tenant (normal mode)
238 cisco.aci.aci_rest: *tenant_absent
239 register: nm_remove_tenant
240
241 - name: Remove tenant again (normal mode)
242 cisco.aci.aci_rest: *tenant_absent
243 register: nm_remove_tenant_again
244
245 - name: Verify remove_tenant
246 ansible.builtin.assert:
247 that:
248 - nm_remove_tenant is changed
249 - nm_remove_tenant_again is not changed
250
251 # QUERY NON-EXISTING TENANT
252 - name: Query non-existing tenant (normal mode)
253 cisco.aci.aci_rest: *tenant_query
254 register: nm_query_non_tenant
255
256 - name: Verify query_non_tenant
257 ansible.builtin.assert:
258 that:
259 - nm_query_non_tenant is not changed
260
261 # VERIFY ANNOTATION
262 - name: Add tenant with annotation (normal mode)
263 cisco.aci.aci_rest: &tenant_annotation
264 <<: *aci_info
265 path: /api/mo/uni.xml
266 method: post
267 annotation: test:label
268 content:
269 <fvTenant name="ansible_test_annotation"/>
270 register: nm_add_tenant_annotation
271
272 # VERIFY ANNOTATION SUPPORT
273 - name: Add tenant with annotation option
274 cisco.aci.aci_rest:
275 <<: *aci_info
276 path: /api/mo/uni.xml
277 method: post
278 annotation: test:inoption
279 content:
280 <fvTenant name="ansible_test" descr="Ansible test tenant"/>
281 register: nm_add_tenant_annotation_option
282
283 - name: Add tenant with annotation in content
284 cisco.aci.aci_rest:
285 <<: *aci_info
286 path: /api/mo/uni.xml
287 method: post
288 content:
289 <fvTenant name="ansible_test" descr="Ansible test tenant" annotation="test:incontent"/>
290 register: nm_add_tenant_annotation_content
291
292 - name: Add tenant with annotation in content and option
293 cisco.aci.aci_rest:
294 <<: *aci_info
295 path: /api/mo/uni.xml
296 method: post
297 annotation: test:inoption
298 content:
299 <fvTenant name="ansible_test" descr="Ansible test tenant" annotation="test:optionincontent"/>
300 register: nm_add_tenant_annotation_option_content
301
302 - name: Add tag to tenant with annotation unsupported
303 cisco.aci.aci_rest:
304 <<: *aci_info
305 path: /api/mo/uni/tn-ansible_test/tagKey-foo.xml
306 method: post
307 annotation: test:inoption
308 content:
309 <tagTag value="bar"/>
310 register: nm_add_tag_no_annotation
311
312 - name: Remove tenant
313 cisco.aci.aci_rest: *tenant_absent
314
315 - name: Add tenant with children objects including annotation
316 cisco.aci.aci_rest:
317 <<: *aci_info
318 path: /api/mo/uni.xml
319 method: post
320 annotation: test:inoption
321 content:
322 <fvTenant name="ansible_test" descr="Ansible test tenant">
323 <fvCtx name="VRF1"/>
324 <fvAp name="Application1">
325 <fvAEPg name="WebTier" annotation="test:inchild"/>
326 </fvAp>
327 </fvTenant>
328 register: nm_add_tenant_annotation_children
329
330 - name: Verify annotation support
331 assert:
332 that:
333 - nm_add_tenant_annotation_option.imdata.0.fvTenant.attributes.annotation == "test:inoption"
334 - nm_add_tenant_annotation_content.imdata.0.fvTenant.attributes.annotation == "test:incontent"
335 - nm_add_tenant_annotation_option_content.imdata.0.fvTenant.attributes.annotation == "test:optionincontent"
336 - nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
337 - nm_add_tenant_annotation_children.imdata.0.fvTenant.attributes.annotation == "test:inoption"
338 - nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.attributes.annotation == "test:inoption"
339 - nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.children.0.fvAEPg.attributes.annotation == "test:inchild"
340 - nm_add_tenant_annotation_children.imdata.0.fvTenant.children.1.fvCtx.attributes.annotation == "test:inoption"
341
342 # Test to check the ansible-core >= 2.19
343 - name: Ensure Port Channel interface policy does not exists
344 cisco.aci.aci_rest:
345 <<: *aci_info
346 path: api/mo/uni/infra/lacpifp-link_aggregation_control_protocol.json
347 method: delete
348 register: rm_link_aggregation_control_protocol
349
350 - name: Add Port Channel interface policy XML with prio attribute str value (check_mode)
351 cisco.aci.aci_rest: &cm_add_link_aggregation_control_protocol_xml
352 <<: *aci_info
353 path: api/mo/uni/infra/lacpifp-link_aggregation_control_protocol.xml
354 method: post
355 content: <lacpIfPol annotation="orchestrator:ansible" descr="test" name="link_aggregation_control_protocol" prio="32768"/>
356 check_mode: true
357 register: cm_add_link_aggregation_control_protocol
358
359 - name: Add Port Channel interface policy XML with prio attribute str value
360 cisco.aci.aci_rest:
361 <<: *cm_add_link_aggregation_control_protocol_xml
362 register: nm_add_link_aggregation_control_protocol
363
364 - name: Add Port Channel interface policy XML with prio attribute str value again
365 cisco.aci.aci_rest:
366 <<: *cm_add_link_aggregation_control_protocol_xml
367 register: nm_add_link_aggregation_control_protocol_again
368
369 - name: Delete Port Channel interface policy
370 cisco.aci.aci_rest:
371 <<: *aci_info
372 path: api/mo/uni/infra/lacpifp-link_aggregation_control_protocol.xml
373 method: delete
374 register: rm_link_aggregation_control_protocol
375
376 - name: Assertion check for add Port Channel interface policy XML with prio attribute str and int value
377 ansible.builtin.assert:
378 that:
379 - cm_add_link_aggregation_control_protocol is changed
380 - cm_add_link_aggregation_control_protocol.proposed == '<lacpIfPol annotation="orchestrator:ansible" descr="test" name="link_aggregation_control_protocol" prio="32768"/>'
381 - nm_add_link_aggregation_control_protocol is changed
382 - nm_add_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.annotation == "orchestrator:ansible"
383 - nm_add_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.descr == "test"
384 - nm_add_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.dn == "uni/infra/lacpifp-link_aggregation_control_protocol"
385 - nm_add_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.name == "link_aggregation_control_protocol"
386 - nm_add_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.prio == "32768"
387 - nm_add_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.rn == ""
388 - nm_add_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.status == "created"
389 - nm_add_link_aggregation_control_protocol.proposed == '<lacpIfPol annotation="orchestrator:ansible" descr="test" name="link_aggregation_control_protocol" prio="32768"/>'
390 - nm_add_link_aggregation_control_protocol_again is not changed
391 - nm_add_link_aggregation_control_protocol_again.imdata == {}
392 - nm_add_link_aggregation_control_protocol_again.proposed == '<lacpIfPol annotation="orchestrator:ansible" descr="test" name="link_aggregation_control_protocol" prio="32768"/>'
393 - rm_link_aggregation_control_protocol is changed
394 - rm_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.annotation == "orchestrator:ansible"
395 - rm_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.descr == "test"
396 - rm_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.dn == "uni/infra/lacpifp-link_aggregation_control_protocol"
397 - rm_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.name == "link_aggregation_control_protocol"
398 - rm_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.prio == "32768"
399 - rm_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.rn == ""
400 - rm_link_aggregation_control_protocol.imdata.0.lacpIfPol.attributes.status == "deleted"