Debian Codegraph @

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

raw symbols SCIP
1 # Test code for the MSO modules
2 # Copyright: (c) 2025, Akini Ross (@akinross) <[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 - name: Set vars
12 ansible.builtin.set_fact:
13 mso_info: &mso_info
14 host: "{{ mso_hostname }}"
15 username: "{{ mso_username }}"
16 password: "{{ mso_password }}"
17 validate_certs: "{{ mso_validate_certs | default(false) }}"
18 use_ssl: "{{ mso_use_ssl | default(true) }}"
19 use_proxy: "{{ mso_use_proxy | default(true) }}"
20 output_level: '{{ mso_output_level | default("debug") }}'
21
22 # QUERY VERSION
23 - name: Query MSO version
24 cisco.mso.mso_version:
25 <<: *mso_info
26 state: query
27 register: version
28
29 - name: Execute tasks only for NDO version >= 4.4
30 when: version.current.version is version('4.4', '>=')
31 block:
32 # CLEAN TEST ENVIRONMENT
33 - name: Ensure Fabric Resource template does not exist
34 cisco.mso.ndo_template: &rm_fabric_resource_template
35 <<: *mso_info
36 template: ansible_fabric_resource_template
37 template_type: fabric_resource
38 state: absent
39
40 - name: Ensure Fabric Policy template does not exist
41 cisco.mso.ndo_template: &rm_fabric_policy_template
42 <<: *mso_info
43 template: ansible_fabric_policy_template
44 template_type: fabric_policy
45 state: absent
46
47 - name: Ensure Fabric Policy template exist
48 cisco.mso.ndo_template:
49 <<: *rm_fabric_policy_template
50 state: present
51 register: fabric_policy_template
52
53 - name: Ensure Fabric Resource template exist
54 cisco.mso.ndo_template:
55 <<: *rm_fabric_resource_template
56 state: present
57
58 - name: Ensure Pod Settings exists
59 cisco.mso.ndo_pod_settings:
60 <<: *mso_info
61 template: ansible_fabric_policy_template
62 name: ansible_pod_settings_1
63 state: present
64 register: pod_settings
65
66 # CREATE Pod Profile
67
68 - name: Create Pod Profile (check_mode)
69 cisco.mso.ndo_pod_profile: &create_pod_profile
70 <<: *mso_info
71 template: ansible_fabric_resource_template
72 name: ansible_pod_profile_1
73 pod_settings:
74 name: ansible_pod_settings_1
75 template: ansible_fabric_policy_template
76 state: present
77 register: cm_create_pod_profile
78 check_mode: true
79
80 - name: Create Pod Profile
81 cisco.mso.ndo_pod_profile:
82 <<: *create_pod_profile
83 register: nm_create_pod_profile
84
85 - name: Create Pod Profile again
86 cisco.mso.ndo_pod_profile:
87 <<: *create_pod_profile
88 register: nm_create_pod_profile_again
89
90 - name: Assert Pod Profile creation
91 ansible.builtin.assert:
92 that:
93 - cm_create_pod_profile is changed
94 - cm_create_pod_profile.previous == {}
95 - cm_create_pod_profile.proposed == cm_create_pod_profile.current
96 - cm_create_pod_profile.current.name == 'ansible_pod_profile_1'
97 - cm_create_pod_profile.current.kind == 'all'
98 - cm_create_pod_profile.current.policyName == 'ansible_pod_settings_1'
99 - cm_create_pod_profile.current.policy is defined
100 - cm_create_pod_profile.current.policyTemplateId is defined
101 - cm_create_pod_profile.current.policyTemplateName == 'ansible_fabric_policy_template'
102 - cm_create_pod_profile.current.uuid is not defined
103 - cm_create_pod_profile.current.templateId is defined
104 - cm_create_pod_profile.current.templateName == 'ansible_fabric_resource_template'
105 - nm_create_pod_profile is changed
106 - nm_create_pod_profile.previous == {}
107 - nm_create_pod_profile.proposed != nm_create_pod_profile.current
108 - nm_create_pod_profile.current.name == 'ansible_pod_profile_1'
109 - nm_create_pod_profile.current.kind == 'all'
110 - nm_create_pod_profile.current.policyName == 'ansible_pod_settings_1'
111 - nm_create_pod_profile.current.policy is defined
112 - nm_create_pod_profile.current.policyTemplateId is defined
113 - nm_create_pod_profile.current.policyTemplateName == 'ansible_fabric_policy_template'
114 - nm_create_pod_profile.current.uuid is defined
115 - nm_create_pod_profile.current.templateId is defined
116 - nm_create_pod_profile.current.templateName == 'ansible_fabric_resource_template'
117 - nm_create_pod_profile_again is not changed
118 - nm_create_pod_profile_again.previous == nm_create_pod_profile_again.current == nm_create_pod_profile.current
119
120 # UPDATE Pod Profile
121
122 - name: Update Pod Profile (check_mode)
123 cisco.mso.ndo_pod_profile: &update_pod_profile
124 <<: *create_pod_profile
125 name: ansible_pod_profile_1
126 description: Updated Pod Profile
127 pods:
128 - 1
129 - 2
130 register: cm_update_pod_profile
131 check_mode: true
132
133 - name: Update Pod Profile
134 cisco.mso.ndo_pod_profile:
135 <<: *update_pod_profile
136 register: nm_update_pod_profile
137
138 - name: Update Pod Profile again
139 cisco.mso.ndo_pod_profile:
140 <<: *update_pod_profile
141 register: nm_update_pod_profile_again
142
143 - name: Update Pod Profile back to type all
144 cisco.mso.ndo_pod_profile:
145 <<: *update_pod_profile
146 name: ansible_pod_profile_1
147 description: Updated Pod Profile
148 pods: []
149 register: nm_update_pod_profile_back_to_all
150
151 - name: Update Pod Profile back to type range
152 cisco.mso.ndo_pod_profile:
153 <<: *update_pod_profile
154 name: ansible_pod_profile_1
155 description: Updated Pod Profile
156 pods:
157 - 1
158 register: nm_update_pod_profile_back_to_range
159
160 - name: Assert Pod Profile update
161 ansible.builtin.assert:
162 that:
163 - cm_update_pod_profile is changed
164 - cm_update_pod_profile.previous.name == 'ansible_pod_profile_1'
165 - cm_update_pod_profile.previous.uuid is defined
166 - cm_update_pod_profile.previous != cm_update_pod_profile.current
167 - cm_update_pod_profile.proposed == cm_update_pod_profile.current
168 - cm_update_pod_profile.current.name == 'ansible_pod_profile_1'
169 - cm_update_pod_profile.current.description == 'Updated Pod Profile'
170 - cm_update_pod_profile.current.kind == 'podRange'
171 - cm_update_pod_profile.current.policyName == 'ansible_pod_settings_1'
172 - cm_update_pod_profile.current.blocks | length == 2
173 - cm_update_pod_profile.current.blocks[0] == 1
174 - cm_update_pod_profile.current.blocks[1] == 2
175 - cm_update_pod_profile.current.policy is defined
176 - cm_update_pod_profile.current.policyTemplateId is defined
177 - cm_update_pod_profile.current.policyTemplateName == 'ansible_fabric_policy_template'
178 - cm_update_pod_profile.current.templateId is defined
179 - cm_update_pod_profile.current.templateName == 'ansible_fabric_resource_template'
180 - cm_update_pod_profile.current.uuid is defined
181 - nm_update_pod_profile is changed
182 - nm_update_pod_profile.previous.name == 'ansible_pod_profile_1'
183 - nm_update_pod_profile.previous.uuid is defined
184 - nm_update_pod_profile.previous != nm_update_pod_profile.current
185 - nm_update_pod_profile.proposed == nm_update_pod_profile.current
186 - nm_update_pod_profile.current.name == 'ansible_pod_profile_1'
187 - nm_update_pod_profile.current.description == 'Updated Pod Profile'
188 - nm_update_pod_profile.current.kind == 'podRange'
189 - nm_update_pod_profile.current.policyName == 'ansible_pod_settings_1'
190 - nm_update_pod_profile.current.blocks | length == 2
191 - nm_update_pod_profile.current.blocks[0] == 1
192 - nm_update_pod_profile.current.blocks[1] == 2
193 - nm_update_pod_profile.current.policy is defined
194 - nm_update_pod_profile.current.policyTemplateId is defined
195 - nm_update_pod_profile.current.policyTemplateName == 'ansible_fabric_policy_template'
196 - nm_update_pod_profile.current.templateId is defined
197 - nm_update_pod_profile.current.templateName == 'ansible_fabric_resource_template'
198 - nm_update_pod_profile.current.uuid is defined
199 - nm_update_pod_profile_again is not changed
200 - nm_update_pod_profile_again.previous == nm_update_pod_profile_again.current == nm_update_pod_profile.current
201 - nm_update_pod_profile_back_to_all is changed
202 - nm_update_pod_profile_back_to_all.previous.name == 'ansible_pod_profile_1'
203 - nm_update_pod_profile_back_to_all.previous.uuid is defined
204 - nm_update_pod_profile_back_to_all.previous != nm_update_pod_profile_back_to_all.current
205 - nm_update_pod_profile_back_to_all.proposed == nm_update_pod_profile_back_to_all.current
206 - nm_update_pod_profile_back_to_all.current.name == 'ansible_pod_profile_1'
207 - nm_update_pod_profile_back_to_all.current.description == 'Updated Pod Profile'
208 - nm_update_pod_profile_back_to_all.current.kind == 'all'
209 - nm_update_pod_profile_back_to_all.current.policyName == 'ansible_pod_settings_1'
210 - nm_update_pod_profile_back_to_all.current.blocks is not defined
211 - nm_update_pod_profile_back_to_all.current.policy is defined
212 - nm_update_pod_profile_back_to_all.current.uuid is defined
213 - nm_update_pod_profile_back_to_range is changed
214 - nm_update_pod_profile_back_to_range.previous.name == 'ansible_pod_profile_1'
215 - nm_update_pod_profile_back_to_range.previous.uuid is defined
216 - nm_update_pod_profile_back_to_range.previous != nm_update_pod_profile_back_to_range.current
217 - nm_update_pod_profile_back_to_range.proposed == nm_update_pod_profile_back_to_range.current
218 - nm_update_pod_profile_back_to_range.current.name == 'ansible_pod_profile_1'
219 - nm_update_pod_profile_back_to_range.current.description == 'Updated Pod Profile'
220 - nm_update_pod_profile_back_to_range.current.kind == 'podRange'
221 - nm_update_pod_profile_back_to_range.current.policyName == 'ansible_pod_settings_1'
222 - nm_update_pod_profile_back_to_range.current.blocks | length == 1
223 - nm_update_pod_profile_back_to_range.current.blocks[0] == 1
224 - nm_update_pod_profile_back_to_range.current.policy is defined
225 - nm_update_pod_profile_back_to_range.current.policyTemplateId is defined
226 - nm_update_pod_profile_back_to_range.current.policyTemplateName == 'ansible_fabric_policy_template'
227 - nm_update_pod_profile_back_to_range.current.templateId is defined
228 - nm_update_pod_profile_back_to_range.current.templateName == 'ansible_fabric_resource_template'
229 - nm_update_pod_profile_back_to_range.current.uuid is defined
230
231 - name: Update description to empty string
232 cisco.mso.ndo_pod_profile:
233 <<: *create_pod_profile
234 description: ""
235 register: nm_update_pod_profile_empty_description
236
237 - name: Assert Pod Profile update with empty description
238 ansible.builtin.assert:
239 that:
240 - nm_update_pod_profile_empty_description is changed
241 - nm_update_pod_profile_empty_description.previous.name == 'ansible_pod_profile_1'
242 - nm_update_pod_profile_empty_description.previous.description == 'Updated Pod Profile'
243 - nm_update_pod_profile_empty_description.previous.uuid is defined
244 - nm_update_pod_profile_empty_description.proposed == nm_update_pod_profile_empty_description.current
245 - nm_update_pod_profile_empty_description.current.description == ''
246 - nm_update_pod_profile_empty_description.current.uuid is defined
247
248 - name: Create another Pod Profile with pod_settings_uuid
249 cisco.mso.ndo_pod_profile: &create_pod_profile_2
250 <<: *mso_info
251 template: ansible_fabric_resource_template
252 name: ansible_pod_profile_2
253 pod_settings_uuid: "{{ pod_settings.current.uuid }}"
254 pods:
255 - 2
256 state: present
257 register: create_pod_profile_2
258
259 - name: Update name of Pod Profile
260 cisco.mso.ndo_pod_profile:
261 <<: *create_pod_profile_2
262 name: ansible_pod_profile_2_changed
263 uuid: "{{create_pod_profile_2.current.uuid}}"
264 register: update_pod_profile_name
265
266 - name: Assert update of Pod Profile name
267 ansible.builtin.assert:
268 that:
269 - update_pod_profile_name is changed
270 - update_pod_profile_name.previous.name == 'ansible_pod_profile_2'
271 - update_pod_profile_name.current.name == 'ansible_pod_profile_2_changed'
272 - update_pod_profile_name.current.uuid == update_pod_profile_name.previous.uuid
273 - update_pod_profile_name.current.policyName == 'ansible_pod_settings_1'
274
275 # QUERY Pod Profile
276
277 - name: Query Pod Profile
278 cisco.mso.ndo_pod_profile:
279 <<: *create_pod_profile
280 state: query
281 register: query_pod_profile
282
283 - name: Query all Pod Profile in Fabric Policy template
284 cisco.mso.ndo_pod_profile:
285 <<: *mso_info
286 template: ansible_fabric_resource_template
287 state: query
288 register: query_all_pod_profile
289
290 - name: Assert Pod Profile query
291 ansible.builtin.assert:
292 that:
293 - query_pod_profile is not changed
294 - query_pod_profile.current.name == 'ansible_pod_profile_1'
295 - query_all_pod_profile is not changed
296 - query_all_pod_profile.current | length == 2
297 - query_all_pod_profile.current[0].name == 'ansible_pod_profile_1'
298 - query_all_pod_profile.current[1].name == 'ansible_pod_profile_2_changed'
299
300 # ERROR HANDLING
301
302 - name: Pod Profile with mutually exclusive template parameters (error)
303 cisco.mso.ndo_pod_profile:
304 <<: *create_pod_profile
305 template_id: template_id
306 register: err_mutually_exclusive_template
307 ignore_errors: true
308
309 - name: Pod Profile with mutually exclusive pod_settings parameters (error)
310 cisco.mso.ndo_pod_profile:
311 <<: *create_pod_profile
312 pod_settings:
313 name: ansible_pod_settings_1
314 template: ansible_fabric_policy_template
315 pod_settings_uuid: "{{ pod_settings.current.uuid }}"
316 register: err_mutually_exclusive_pod_settings
317 ignore_errors: true
318
319 - name: Pod Profile with mutually exclusive pod_settings_template parameters (error)
320 cisco.mso.ndo_pod_profile:
321 <<: *create_pod_profile
322 pod_settings:
323 template: ansible_fabric_policy_template
324 template_id: "{{ fabric_policy_template.current.templateId }}"
325 register: err_mutually_exclusive_pod_settings_template
326 ignore_errors: true
327
328 - name: Assert mutually exclusive error handling
329 ansible.builtin.assert:
330 that:
331 - err_mutually_exclusive_template is failed
332 - 'err_mutually_exclusive_template.msg == "parameters are mutually exclusive: template|template_id"'
333 - err_mutually_exclusive_pod_settings is failed
334 - 'err_mutually_exclusive_pod_settings.msg == "parameters are mutually exclusive: pod_settings|pod_settings_uuid"'
335 - err_mutually_exclusive_pod_settings_template is failed
336 - 'err_mutually_exclusive_pod_settings_template.msg == "parameters are mutually exclusive: template|template_id found in pod_settings"'
337
338 - name: Pod Profile with required if parameters pod_settings and pod_settings_uuid missing (error)
339 cisco.mso.ndo_pod_profile:
340 <<: *mso_info
341 template: ansible_fabric_resource_template
342 name: ansible_pod_profile_1
343 pod_settings:
344 template: ansible_fabric_policy_template
345 state: present
346 register: err_required_parameters_missing_pod_settings
347 ignore_errors: true
348
349 - name: Pod Profile with required if parameters pod_settings_template and pod_settings_template_id missing (error)
350 cisco.mso.ndo_pod_profile:
351 <<: *mso_info
352 template: ansible_fabric_resource_template
353 name: ansible_pod_profile_1
354 pod_settings:
355 name: ansible_pod_settings_1
356 state: present
357 register: err_required_parameters_missing_pod_settings_template
358 ignore_errors: true
359
360 - name: Pod Profile with invalid pod_settings (error)
361 cisco.mso.ndo_pod_profile:
362 <<: *create_pod_profile
363 pod_settings:
364 name: ansible_pod_settings_2
365 template: ansible_fabric_policy_template
366 register: err_invalid_pod_settings_with_template
367 ignore_errors: true
368
369 - name: Pod Profile with invalid pod_settings_uuid (error)
370 cisco.mso.ndo_pod_profile:
371 <<: *mso_info
372 template: ansible_fabric_resource_template
373 name: ansible_pod_profile_invalid_uuid
374 pod_settings_uuid: invalid_uuid
375 state: present
376 register: err_invalid_pod_settings_uuid
377 ignore_errors: true
378
379 - name: Set error messages for Pod Settings errors
380 ansible.builtin.set_fact:
381 error_message_invalid_pod_settings_template: "Provided Pod Settings with '[KVPair(key='name', value='ansible_pod_settings_2')]' not matching existing object(s): ansible_pod_settings_1"
382 error_message_invalid_pod_settings_uuid: "MSO Error 400: {\"errors\":[\"Error validating pod policy group reference: invalid_uuid\"]}"
383
384 - name: Assert Pod Settings error handling
385 ansible.builtin.assert:
386 that:
387 - err_required_parameters_missing_pod_settings is failed
388 - 'err_required_parameters_missing_pod_settings.msg == "missing required arguments: name found in pod_settings"'
389 - err_required_parameters_missing_pod_settings_template is failed
390 - 'err_required_parameters_missing_pod_settings_template.msg == "one of the following is required: template, template_id found in pod_settings"'
391 - err_invalid_pod_settings_with_template is failed
392 - err_invalid_pod_settings_with_template.msg == error_message_invalid_pod_settings_template
393 - err_invalid_pod_settings_uuid is failed
394 - err_invalid_pod_settings_uuid.msg == error_message_invalid_pod_settings_uuid
395
396 # DELETE Pod Profile
397
398 - name: Delete Pod Profile (check_mode)
399 cisco.mso.ndo_pod_profile: &delete_pod_profile
400 <<: *create_pod_profile
401 state: absent
402 register: cm_delete_pod_profile
403 check_mode: true
404
405 - name: Delete Pod Profile
406 cisco.mso.ndo_pod_profile:
407 <<: *delete_pod_profile
408 register: nm_delete_pod_profile
409
410 - name: Delete Pod Profile again
411 cisco.mso.ndo_pod_profile:
412 <<: *delete_pod_profile
413 register: nm_delete_pod_profile_again
414
415 - name: Assert Pod Profile deletion
416 ansible.builtin.assert:
417 that:
418 - cm_delete_pod_profile is changed
419 - cm_delete_pod_profile.previous.name == 'ansible_pod_profile_1'
420 - cm_delete_pod_profile.proposed == {}
421 - cm_delete_pod_profile.current == {}
422 - nm_delete_pod_profile is changed
423 - nm_delete_pod_profile.previous.name == 'ansible_pod_profile_1'
424 - nm_delete_pod_profile.proposed == {}
425 - nm_delete_pod_profile.current == {}
426 - nm_delete_pod_profile_again is not changed
427 - nm_delete_pod_profile_again.previous == nm_delete_pod_profile_again.current == nm_delete_pod_profile.current
428
429 # CLEAN TEST ENVIRONMENT
430
431 - name: Ensure Fabric Resource template does not exist
432 cisco.mso.ndo_template:
433 <<: *rm_fabric_resource_template
434
435 - name: Ensure Fabric Policy template does not exist
436 cisco.mso.ndo_template:
437 <<: *rm_fabric_policy_template