Debian Codegraph @

ansible_collections/cisco/mso/tests/integration/targets/ndo_l3out_annotation/tasks/main.yml

raw symbols SCIP
1 # Test code for the MSO modules
2 # Copyright: (c) 2024, Sabari Jaganathan (@sajagana) <[email protected]>
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 - name: Test that we have an ACI MultiSite host, username and password
7 ansible.builtin.fail:
8 msg: "Please define the following variables: mso_hostname, mso_username and mso_password."
9 when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
10
11 # CLEAN ENVIRONMENT
12 - name: Set vars
13 ansible.builtin.set_fact:
14 mso_info: &mso_info
15 host: "{{ mso_hostname }}"
16 username: "{{ mso_username }}"
17 password: "{{ mso_password }}"
18 validate_certs: "{{ mso_validate_certs | default(false) }}"
19 use_ssl: "{{ mso_use_ssl | default(true) }}"
20 use_proxy: "{{ mso_use_proxy | default(true) }}"
21 output_level: '{{ mso_output_level | default("debug") }}'
22
23 # QUERY VERSION
24 - name: Query MSO version
25 cisco.mso.mso_version:
26 <<: *mso_info
27 state: query
28 register: version
29
30 - name: Execute tasks only for NDO version > 4.2
31 when: version.current.version is version('4.2', '>')
32 block:
33 # Setup Part
34 - name: Ensure l3out template not exist
35 cisco.mso.ndo_template: &ndo_l3out_template_absent
36 <<: *mso_info
37 template: '{{ ansible_l3out_template | default("ansible_test") }}'
38 template_type: l3out
39 tenant: '{{ ansible_tenant | default("ansible_test") }}'
40 sites:
41 - name: '{{ mso_site | default("ansible_test") }}'
42 state: absent
43
44 - name: Ensure ansible_test schema template not exist
45 cisco.mso.mso_schema_template: &mso_schema_template_absent
46 <<: *mso_info
47 schema: '{{ mso_schema | default("ansible_test") }}'
48 tenant: '{{ ansible_tenant | default("ansible_test") }}'
49 template: "Template1"
50 state: absent
51
52 - name: Ensure ansible_test site exist
53 cisco.mso.mso_site:
54 <<: *mso_info
55 site: '{{ mso_site | default("ansible_test") }}'
56 state: query
57 register: ansible_test_site
58
59 - name: Ensure ansible_test tenant exist
60 cisco.mso.mso_tenant:
61 <<: *mso_info
62 tenant: '{{ ansible_tenant | default("ansible_test") }}'
63 users:
64 - "{{ mso_username }}"
65 sites:
66 - '{{ mso_site | default("ansible_test") }}'
67 state: present
68 when: ansible_test_site.current.common.name == 'ansible_test'
69
70 # Schema Template Setup for the VRF
71 - name: Add an ansible_test schema template
72 cisco.mso.mso_schema_template:
73 <<: *mso_schema_template_absent
74 state: present
75
76 - name: Add a new VRF1
77 cisco.mso.mso_schema_template_vrf: &vrf1_present
78 <<: *mso_info
79 schema: '{{ mso_schema | default("ansible_test") }}'
80 template: "Template1"
81 vrf: VRF1
82 state: present
83
84 - name: Add a new VRF2 with layer3_multicast
85 cisco.mso.mso_schema_template_vrf:
86 <<: *vrf1_present
87 vrf: VRF2
88 layer3_multicast: true
89 state: present
90
91 # L3Out Template Setup
92 - name: Create a new l3out template
93 cisco.mso.ndo_template:
94 <<: *ndo_l3out_template_absent
95 state: present
96 register: create_new_l3out_policy_template
97
98 # Test Part
99 - name: Query all annotations when the L3Out not present
100 cisco.mso.ndo_l3out_annotation:
101 <<: *mso_info
102 template: '{{ ansible_l3out_template | default("ansible_test") }}'
103 l3out: "L3OutAnnotation"
104 state: query
105 ignore_errors: true
106 register: query_all_when_l3out_is_empty
107
108 - name: Create L3out object with default values
109 cisco.mso.ndo_l3out_template:
110 <<: *mso_info
111 l3out_template: '{{ ansible_l3out_template | default("ansible_test") }}'
112 name: "L3OutAnnotation"
113 vrf:
114 name: "VRF1"
115 schema: '{{ mso_schema | default("ansible_test") }}'
116 template: "Template1"
117 state: "present"
118
119 - name: Query all annotations when the L3Out is empty
120 cisco.mso.ndo_l3out_annotation:
121 <<: *mso_info
122 template: '{{ ansible_l3out_template | default("ansible_test") }}'
123 l3out: "L3OutAnnotation"
124 state: query
125 ignore_errors: true
126 register: query_all_when_l3out_is_empty
127
128 - name: Assertion check for query all annotations when the L3Out is empty
129 ansible.builtin.assert:
130 that:
131 - query_all_when_l3out_is_empty is not changed
132 - query_all_when_l3out_is_empty.current == []
133
134 - name: Query an annotation with key when the L3Out is empty
135 cisco.mso.ndo_l3out_annotation:
136 <<: *mso_info
137 template: '{{ ansible_l3out_template | default("ansible_test") }}'
138 l3out: "L3OutAnnotation"
139 annotation_key: "annotation_key_1"
140 state: query
141 ignore_errors: true
142 register: query_when_l3out_is_empty
143
144 - name: Assertion check for query an annotation with key when the L3Out is empty
145 ansible.builtin.assert:
146 that:
147 - query_when_l3out_is_empty is not changed
148 - query_when_l3out_is_empty.current == {}
149
150 - name: Add an annotation without value
151 cisco.mso.ndo_l3out_annotation:
152 <<: *mso_info
153 template: '{{ ansible_l3out_template | default("ansible_test") }}'
154 l3out: "L3OutAnnotation"
155 annotation_key: "annotation_key_1"
156 state: present
157 ignore_errors: true
158 register: nt_add_without_value
159
160 - name: Assertion check for add an annotation without value
161 ansible.builtin.assert:
162 that:
163 - nt_add_without_value is not changed
164 - 'nt_add_without_value.msg == "state is present but all of the following are missing: annotation_value"'
165
166 - name: Add an annotation without key
167 cisco.mso.ndo_l3out_annotation:
168 <<: *mso_info
169 template: '{{ ansible_l3out_template | default("ansible_test") }}'
170 l3out: "L3OutAnnotation"
171 annotation_value: "annotation_value_1"
172 state: present
173 ignore_errors: true
174 register: nt_add_without_key
175
176 - name: Assertion check for add an annotation without key
177 ansible.builtin.assert:
178 that:
179 - nt_add_without_key is not changed
180 - 'nt_add_without_key.msg == "state is present but all of the following are missing: annotation_key"'
181
182 - name: Add an annotation with key and value - check_mode
183 cisco.mso.ndo_l3out_annotation:
184 <<: *mso_info
185 template: '{{ ansible_l3out_template | default("ansible_test") }}'
186 l3out: "L3OutAnnotation"
187 annotation_key: "annotation_key_1"
188 annotation_value: "annotation_value_1"
189 state: present
190 output_level: debug
191 check_mode: true
192 ignore_errors: true
193 register: cm_add
194
195 - name: Assertion check for add an annotation with key and value - check_mode
196 ansible.builtin.assert:
197 that:
198 - cm_add is changed
199 - cm_add.current.tagKey == "annotation_key_1"
200 - cm_add.current.tagValue == "annotation_value_1"
201 - cm_add.previous == {}
202 - cm_add.proposed.tagKey == "annotation_key_1"
203 - cm_add.proposed.tagValue == "annotation_value_1"
204
205 - name: Add an annotation with key and value
206 cisco.mso.ndo_l3out_annotation:
207 <<: *mso_info
208 template: '{{ ansible_l3out_template | default("ansible_test") }}'
209 l3out: "L3OutAnnotation"
210 annotation_key: "annotation_key_1"
211 annotation_value: "annotation_value_1"
212 state: present
213 ignore_errors: true
214 register: nm_add
215
216 - name: Assertion check for add an annotation with key and value
217 ansible.builtin.assert:
218 that:
219 - nm_add is changed
220 - nm_add.current.tagKey == "annotation_key_1"
221 - nm_add.current.tagValue == "annotation_value_1"
222 - nm_add.previous == {}
223
224 - name: Add an annotation with key and value - again
225 cisco.mso.ndo_l3out_annotation:
226 <<: *mso_info
227 template: '{{ ansible_l3out_template | default("ansible_test") }}'
228 l3out: "L3OutAnnotation"
229 annotation_key: "annotation_key_1"
230 annotation_value: "annotation_value_1"
231 state: present
232 ignore_errors: true
233 register: nm_add_again
234
235 - name: Assertion check for add an annotation with key and value - again
236 ansible.builtin.assert:
237 that:
238 - nm_add_again is not changed
239 - nm_add_again.current.tagKey == "annotation_key_1"
240 - nm_add_again.current.tagValue == "annotation_value_1"
241 - nm_add_again.previous.tagKey == "annotation_key_1"
242 - nm_add_again.previous.tagValue == "annotation_value_1"
243
244 - name: Query all annotations
245 cisco.mso.ndo_l3out_annotation:
246 <<: *mso_info
247 template: '{{ ansible_l3out_template | default("ansible_test") }}'
248 l3out: "L3OutAnnotation"
249 state: query
250 ignore_errors: true
251 register: query_all_after_creation
252
253 - name: Assertion check for query all annotations
254 ansible.builtin.assert:
255 that:
256 - query_all_after_creation is not changed
257 - query_all_after_creation.current | length == 1
258 - query_all_after_creation.current.0.tagKey == "annotation_key_1"
259 - query_all_after_creation.current.0.tagValue == "annotation_value_1"
260
261 - name: Query an annotation with key
262 cisco.mso.ndo_l3out_annotation:
263 <<: *mso_info
264 template: '{{ ansible_l3out_template | default("ansible_test") }}'
265 l3out: "L3OutAnnotation"
266 annotation_key: "annotation_key_1"
267 state: query
268 ignore_errors: true
269 register: query_with_key_after_creation
270
271 - name: Assertion check for query an annotation with key
272 ansible.builtin.assert:
273 that:
274 - query_with_key_after_creation is not changed
275 - query_with_key_after_creation.current.tagKey == "annotation_key_1"
276 - query_with_key_after_creation.current.tagValue == "annotation_value_1"
277
278 - name: Update an annotation value - check mode
279 cisco.mso.ndo_l3out_annotation:
280 <<: *mso_info
281 template: '{{ ansible_l3out_template | default("ansible_test") }}'
282 l3out: "L3OutAnnotation"
283 annotation_key: "annotation_key_1"
284 annotation_value: "annotation_value_1_updated"
285 state: present
286 output_level: debug
287 check_mode: true
288 ignore_errors: true
289 register: cm_update
290
291 - name: Assertion check for update an annotation value - check mode
292 ansible.builtin.assert:
293 that:
294 - cm_update is changed
295 - cm_update.current.tagKey == "annotation_key_1"
296 - cm_update.current.tagValue == "annotation_value_1_updated"
297 - cm_update.previous.tagKey == "annotation_key_1"
298 - cm_update.previous.tagValue == "annotation_value_1"
299 - cm_update.proposed.tagKey == "annotation_key_1"
300 - cm_update.proposed.tagValue == "annotation_value_1_updated"
301
302 - name: Update an annotation value
303 cisco.mso.ndo_l3out_annotation:
304 <<: *mso_info
305 template: '{{ ansible_l3out_template | default("ansible_test") }}'
306 l3out: "L3OutAnnotation"
307 annotation_key: "annotation_key_1"
308 annotation_value: "annotation_value_1_updated"
309 state: present
310 ignore_errors: true
311 register: nm_update
312
313 - name: Assertion check for update an annotation value
314 ansible.builtin.assert:
315 that:
316 - nm_update is changed
317 - nm_update.current.tagKey == "annotation_key_1"
318 - nm_update.current.tagValue == "annotation_value_1_updated"
319 - nm_update.previous.tagKey == "annotation_key_1"
320 - nm_update.previous.tagValue == "annotation_value_1"
321
322 - name: Update an annotation value - again
323 cisco.mso.ndo_l3out_annotation:
324 <<: *mso_info
325 template: '{{ ansible_l3out_template | default("ansible_test") }}'
326 l3out: "L3OutAnnotation"
327 annotation_key: "annotation_key_1"
328 annotation_value: "annotation_value_1_updated"
329 state: present
330 ignore_errors: true
331 register: nm_update_again
332
333 - name: Assertion check for update an annotation value - again
334 ansible.builtin.assert:
335 that:
336 - nm_update_again is not changed
337 - nm_update_again.current.tagKey == "annotation_key_1"
338 - nm_update_again.current.tagValue == "annotation_value_1_updated"
339 - nm_update_again.previous.tagKey == "annotation_key_1"
340 - nm_update_again.previous.tagValue == "annotation_value_1_updated"
341
342 - name: Query an annotation with key
343 cisco.mso.ndo_l3out_annotation:
344 <<: *mso_info
345 template: '{{ ansible_l3out_template | default("ansible_test") }}'
346 l3out: "L3OutAnnotation"
347 annotation_key: "annotation_key_1"
348 state: query
349 ignore_errors: true
350 register: query_after_update
351
352 - name: Assertion check for query an annotation with key
353 ansible.builtin.assert:
354 that:
355 - query_after_update is not changed
356 - query_after_update.current.tagKey == "annotation_key_1"
357 - query_after_update.current.tagValue == "annotation_value_1_updated"
358
359 - name: Add an annotation_key_2
360 cisco.mso.ndo_l3out_annotation:
361 <<: *mso_info
362 template: '{{ ansible_l3out_template | default("ansible_test") }}'
363 l3out: "L3OutAnnotation"
364 annotation_key: "annotation_key_2"
365 annotation_value: "annotation_value_2"
366 state: present
367 ignore_errors: true
368 register: add_key_2
369
370 - name: Assertion check for add an annotation_key_2
371 ansible.builtin.assert:
372 that:
373 - add_key_2 is changed
374 - add_key_2.current.tagKey == "annotation_key_2"
375 - add_key_2.current.tagValue == "annotation_value_2"
376 - add_key_2.previous == {}
377
378 - name: Query all annotations
379 cisco.mso.ndo_l3out_annotation:
380 <<: *mso_info
381 template: '{{ ansible_l3out_template | default("ansible_test") }}'
382 l3out: "L3OutAnnotation"
383 state: query
384 ignore_errors: true
385 register: query_all_annotations
386
387 - name: Assertion check for query all annotations
388 ansible.builtin.assert:
389 that:
390 - query_all_annotations is not changed
391 - query_all_annotations.current | length == 2
392
393 - name: Remove an annotation - check_mode
394 cisco.mso.ndo_l3out_annotation:
395 <<: *mso_info
396 template: '{{ ansible_l3out_template | default("ansible_test") }}'
397 l3out: "L3OutAnnotation"
398 annotation_key: "annotation_key_1"
399 state: absent
400 output_level: debug
401 check_mode: true
402 ignore_errors: true
403 register: cm_remove
404
405 - name: Assertion check for remove an annotation - check_mode
406 ansible.builtin.assert:
407 that:
408 - cm_remove is changed
409 - cm_remove.current == {}
410 - cm_remove.previous.tagKey == "annotation_key_1"
411 - cm_remove.previous.tagValue == "annotation_value_1_updated"
412 - cm_remove.proposed == {}
413
414 - name: Remove an annotation
415 cisco.mso.ndo_l3out_annotation:
416 <<: *mso_info
417 template: '{{ ansible_l3out_template | default("ansible_test") }}'
418 l3out: "L3OutAnnotation"
419 annotation_key: "annotation_key_1"
420 state: absent
421 ignore_errors: true
422 register: nm_remove
423
424 - name: Assertion check for remove an annotation
425 ansible.builtin.assert:
426 that:
427 - nm_remove is changed
428 - nm_remove.current == {}
429 - nm_remove.previous.tagKey == "annotation_key_1"
430 - nm_remove.previous.tagValue == "annotation_value_1_updated"
431
432 - name: Remove an annotation - again
433 cisco.mso.ndo_l3out_annotation:
434 <<: *mso_info
435 template: '{{ ansible_l3out_template | default("ansible_test") }}'
436 l3out: "L3OutAnnotation"
437 annotation_key: "annotation_key_1"
438 state: absent
439 ignore_errors: true
440 register: nm_remove_again
441
442 - name: Assertion check for remove an annotation - again
443 ansible.builtin.assert:
444 that:
445 - nm_remove_again is not changed
446 - nm_remove_again.current == {}
447 - nm_remove_again.previous == {}
448
449 # Cleanup Part
450 - name: Remove l3out tenant template
451 cisco.mso.ndo_template:
452 <<: *ndo_l3out_template_absent
453
454 - name: Remove ansible_test schema template not exist
455 cisco.mso.mso_schema_template:
456 <<: *mso_schema_template_absent