Debian Codegraph @

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

raw
1 # Test code for the MSO modules
2 # Copyright: (c) 2025, Samita Bhattacharjee (@samiib) <[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.3
31 when: version.current.version is version('4.3', '>')
32 block:
33
34 # SETUP
35 - name: Ensure Fabric Resource template does not exist
36 cisco.mso.ndo_template: &ndo_fabric_resource_template_absent
37 <<: *mso_info
38 template: ansible_fabric_resource_policy_template
39 type: fabric_resource
40 state: absent
41
42 - name: Ensure Fabric Policy template does not exist
43 cisco.mso.ndo_template: &ndo_fabric_policy_template_absent
44 <<: *mso_info
45 template: '{{ ansible_fabric_template | default("ansible_test") }}'
46 template_type: fabric_policy
47 state: absent
48
49 - name: Create a new Fabric Policy template
50 cisco.mso.ndo_template:
51 <<: *ndo_fabric_policy_template_absent
52 state: present
53 register: create_fabric_policy
54
55 - name: Create a new Fabric Resource template
56 cisco.mso.ndo_template:
57 <<: *ndo_fabric_resource_template_absent
58 state: present
59 register: create_fabric_resource
60
61 - name: Create Node Setting objects
62 cisco.mso.ndo_node_setting:
63 <<: *mso_info
64 template: '{{ ansible_fabric_template | default("ansible_test") }}'
65 name: '{{ item }}'
66 state: present
67 register: node_setting
68 loop: [node_setting_1, node_setting_2]
69
70 # CREATE
71 - name: Create Node Profile (check mode)
72 cisco.mso.ndo_node_profile: &add_node_profile
73 <<: *mso_info
74 template: ansible_fabric_resource_policy_template
75 name: ansible_node_profile
76 description: Test Ansible Node Profile
77 nodes: [101, 102, 103-105]
78 node_setting_uuid: '{{ node_setting.results[0].current.uuid }}'
79 state: present
80 check_mode: true
81 register: cm_node_profile
82
83 - name: Create Node Profile
84 cisco.mso.ndo_node_profile:
85 <<: *add_node_profile
86 register: nm_node_profile
87
88 - name: Create Node Profile again
89 cisco.mso.ndo_node_profile:
90 <<: *add_node_profile
91 register: nm_node_profile_again
92
93 - name: Assert Node Profile is created
94 ansible.builtin.assert:
95 that:
96 - cm_node_profile is changed
97 - nm_node_profile is changed
98 - cm_node_profile.previous == nm_node_profile.previous == {}
99 - cm_node_profile.current.name == nm_node_profile.current.name == "ansible_node_profile"
100 - cm_node_profile.current.description == nm_node_profile.current.description == "Test Ansible Node Profile"
101 - cm_node_profile.current.nodes | length == nm_node_profile.current.nodes | length == 3
102 - cm_node_profile.current.nodes[0] == nm_node_profile.current.nodes[0] == "101"
103 - cm_node_profile.current.nodes[1] == nm_node_profile.current.nodes[1] == "102"
104 - cm_node_profile.current.nodes[2] == nm_node_profile.current.nodes[2] == "103-105"
105 - cm_node_profile.current.policy == nm_node_profile.current.policy == node_setting.results[0].current.uuid
106 - cm_node_profile.current.policyName == nm_node_profile.current.policyName == node_setting.results[0].current.name
107 - cm_node_profile.current.policyTemplateName == nm_node_profile.current.policyTemplateName == create_fabric_policy.current.displayName
108 - cm_node_profile.current.policyTemplateId == nm_node_profile.current.policyTemplateId == create_fabric_policy.current.templateId
109 - cm_node_profile.current.templateName == nm_node_profile.current.templateName == create_fabric_resource.current.displayName
110 - cm_node_profile.current.templateId == nm_node_profile.current.templateId == create_fabric_resource.current.templateId
111 - nm_node_profile.current.uuid is defined
112 - nm_node_profile_again is not changed
113 - nm_node_profile_again.previous.name == nm_node_profile_again.current.name == "ansible_node_profile"
114 - nm_node_profile_again.previous.description == nm_node_profile_again.current.description == "Test Ansible Node Profile"
115 - nm_node_profile_again.previous.nodes | length == nm_node_profile_again.current.nodes | length == 3
116 - nm_node_profile_again.previous.nodes[0] == nm_node_profile_again.current.nodes[0] == "101"
117 - nm_node_profile_again.previous.nodes[1] == nm_node_profile_again.current.nodes[1] == "102"
118 - nm_node_profile_again.previous.nodes[2] == nm_node_profile_again.current.nodes[2] == "103-105"
119 - nm_node_profile_again.previous.policy == nm_node_profile_again.current.policy == nm_node_profile.current.policy
120 - nm_node_profile_again.previous.policyName == nm_node_profile_again.current.policyName == nm_node_profile.current.policyName
121 - nm_node_profile_again.previous.policyTemplateId == nm_node_profile_again.current.policyTemplateId == nm_node_profile.current.policyTemplateId
122 - nm_node_profile_again.previous.policyTemplateName == nm_node_profile_again.current.policyTemplateName == nm_node_profile.current.policyTemplateName
123 - nm_node_profile_again.previous.templateName == nm_node_profile_again.current.templateName == nm_node_profile.current.templateName
124 - nm_node_profile_again.previous.templateId == nm_node_profile_again.current.templateId == nm_node_profile.current.templateId
125 - nm_node_profile_again.previous.uuid == nm_node_profile.current.uuid
126
127 # UPDATE
128 - name: Update Node Profile (check mode)
129 cisco.mso.ndo_node_profile: &update_node_profile
130 <<: *add_node_profile
131 template: '{{ omit }}'
132 template_id: '{{ create_fabric_resource.current.templateId }}'
133 nodes: [103]
134 description: Test Ansible Node Profile 2
135 node_setting_uuid: '{{ omit }}'
136 node_setting:
137 name: node_setting_2
138 template_id: '{{ create_fabric_policy.current.templateId }}'
139 check_mode: true
140 register: cm_update_node_profile
141
142 - name: Update Node Profile
143 cisco.mso.ndo_node_profile:
144 <<: *update_node_profile
145 register: nm_update_node_profile
146
147 - name: Update Node Profile again
148 cisco.mso.ndo_node_profile:
149 <<: *update_node_profile
150 register: nm_update_node_profile_again
151
152 - name: Update Node Profile name using UUID
153 cisco.mso.ndo_node_profile:
154 <<: *update_node_profile
155 name: ansible_node_profile_1
156 uuid: "{{ nm_node_profile.current.uuid }}"
157 register: nm_update_node_profile_name
158
159 - name: Assert Node Profile is updated
160 ansible.builtin.assert:
161 that:
162 - cm_update_node_profile is changed
163 - nm_update_node_profile is changed
164 - cm_update_node_profile.previous == nm_update_node_profile.previous
165 - cm_update_node_profile.previous.name == nm_update_node_profile.previous.name == "ansible_node_profile"
166 - cm_update_node_profile.current.name == nm_update_node_profile.current.name == "ansible_node_profile"
167 - cm_update_node_profile.previous.description == nm_update_node_profile.previous.description == "Test Ansible Node Profile"
168 - cm_update_node_profile.current.description == nm_update_node_profile.current.description == "Test Ansible Node Profile 2"
169 - cm_update_node_profile.previous.nodes | length == nm_update_node_profile.previous.nodes | length == 3
170 - cm_update_node_profile.previous.nodes[0] == nm_update_node_profile.previous.nodes[0] == "101"
171 - cm_update_node_profile.previous.nodes[1] == nm_update_node_profile.previous.nodes[1] == "102"
172 - cm_update_node_profile.previous.nodes[2] == nm_update_node_profile.previous.nodes[2] == "103-105"
173 - cm_update_node_profile.current.nodes | length == nm_update_node_profile.current.nodes | length == 1
174 - cm_update_node_profile.current.nodes[0] == nm_update_node_profile.current.nodes[0] == "103"
175 - cm_update_node_profile.previous.policy == nm_update_node_profile.previous.policy == node_setting.results[0].current.uuid
176 - cm_update_node_profile.previous.policyName == nm_update_node_profile.previous.policyName == node_setting.results[0].current.name
177 - cm_update_node_profile.previous.policyTemplateName == nm_update_node_profile.previous.policyTemplateName == create_fabric_policy.current.displayName
178 - cm_update_node_profile.previous.policyTemplateId == nm_update_node_profile.previous.policyTemplateId == create_fabric_policy.current.templateId
179 - cm_update_node_profile.previous.templateName == nm_update_node_profile.previous.templateName == create_fabric_resource.current.displayName
180 - cm_update_node_profile.previous.templateId == nm_update_node_profile.previous.templateId == create_fabric_resource.current.templateId
181 - cm_update_node_profile.current.policy == nm_update_node_profile.current.policy == node_setting.results[1].current.uuid
182 - cm_update_node_profile.current.policyName == nm_update_node_profile.current.policyName == node_setting.results[1].current.name
183 - cm_update_node_profile.current.policyTemplateName == nm_update_node_profile.current.policyTemplateName == create_fabric_policy.current.displayName
184 - cm_update_node_profile.current.policyTemplateId == nm_update_node_profile.current.policyTemplateId == create_fabric_policy.current.templateId
185 - cm_update_node_profile.current.templateName == nm_update_node_profile.current.templateName == create_fabric_resource.current.displayName
186 - cm_update_node_profile.current.templateId == nm_update_node_profile.current.templateId == create_fabric_resource.current.templateId
187 - cm_update_node_profile.current.policy != cm_update_node_profile.previous.policy
188 - nm_update_node_profile.current.policy != nm_update_node_profile.previous.policy
189 - cm_update_node_profile.current.uuid == nm_update_node_profile.current.uuid
190 - nm_update_node_profile_again is not changed
191 - nm_update_node_profile_again.previous.name == nm_update_node_profile_again.current.name == "ansible_node_profile"
192 - nm_update_node_profile_again.previous.description == nm_update_node_profile_again.current.description == "Test Ansible Node Profile 2"
193 - nm_update_node_profile_again.previous.nodes | length == nm_update_node_profile_again.current.nodes | length == 1
194 - nm_update_node_profile_again.previous.nodes[0] == nm_update_node_profile_again.current.nodes[0] == "103"
195 - nm_update_node_profile_again.previous.policy == nm_update_node_profile_again.current.policy
196 - nm_update_node_profile_again.previous.uuid == nm_update_node_profile.current.uuid
197 - nm_update_node_profile_again.current.uuid is defined
198 - nm_update_node_profile_name is changed
199 - nm_update_node_profile_name.previous.name == "ansible_node_profile"
200 - nm_update_node_profile_name.current.name == "ansible_node_profile_1"
201
202 # QUERY
203 - name: Create another Node Profile
204 cisco.mso.ndo_node_profile:
205 <<: *add_node_profile
206 name: ansible_node_profile_2
207 node_setting_uuid: '{{ omit }}'
208 node_setting:
209 name: node_setting_1
210 template: '{{ ansible_fabric_template | default("ansible_test") }}'
211 register: nm_node_profile_2
212
213 - name: Query one Node Profile by name
214 cisco.mso.ndo_node_profile:
215 <<: *mso_info
216 name: ansible_node_profile_2
217 template: ansible_fabric_resource_policy_template
218 state: query
219 register: query_name
220
221 - name: Query one Node Profile by UUID
222 cisco.mso.ndo_node_profile:
223 <<: *mso_info
224 uuid: '{{ nm_node_profile.current.uuid }}'
225 template: ansible_fabric_resource_policy_template
226 state: query
227 register: query_uuid
228
229 - name: Query all Node Profiles
230 cisco.mso.ndo_node_profile: &query_all_node_profiles
231 <<: *mso_info
232 template: ansible_fabric_resource_policy_template
233 state: query
234 register: query_all
235
236 - name: Assert Node Profile is queried
237 ansible.builtin.assert:
238 that:
239 - query_name is not changed
240 - query_uuid is not changed
241 - query_all is not changed
242 - query_name.current == nm_node_profile_2.current
243 - query_uuid.current == nm_update_node_profile_name.current
244 - query_all.current | length == 2
245 - query_all.current[0].name == "ansible_node_profile_1"
246 - query_all.current[1].name == "ansible_node_profile_2"
247
248 # ERRORS
249 - name: Update Node Profile without nodes
250 cisco.mso.ndo_node_profile:
251 <<: *add_node_profile
252 description: "This should fail"
253 nodes: '{{ omit }}'
254 register: update_without_nodes
255 ignore_errors: true
256
257 - name: Update Node Profile without node setting
258 cisco.mso.ndo_node_profile:
259 <<: *add_node_profile
260 description: "This should fail"
261 node_setting_uuid: '{{ omit }}'
262 node_setting: '{{ omit }}'
263 register: update_without_node_setting
264 ignore_errors: true
265
266 - name: Update Node Profile using node_setting and invalid node_setting_uuid
267 cisco.mso.ndo_node_profile:
268 <<: *add_node_profile
269 description: "This should fail"
270 node_setting_uuid: 'this_is_invalid'
271 node_setting:
272 name: node_setting_2
273 template: '{{ ansible_fabric_template | default("ansible_test") }}'
274 register: update_with_invalid_uuid
275 ignore_errors: true
276
277 - name: Assert errors
278 ansible.builtin.assert:
279 that:
280 - update_without_nodes is failed
281 - 'update_without_nodes.msg == "state is present but all of the following are missing: nodes"'
282 - update_without_node_setting is failed
283 - 'update_without_node_setting.msg == "state is present but any of the following are missing: node_setting_uuid, node_setting"'
284 - update_with_invalid_uuid is failed
285 - 'update_with_invalid_uuid.msg == "parameters are mutually exclusive: node_setting_uuid|node_setting"'
286
287 # DELETE
288 - name: Delete Node Profile (check mode)
289 cisco.mso.ndo_node_profile: &delete_node_profile
290 <<: *mso_info
291 template: ansible_fabric_resource_policy_template
292 name: ansible_node_profile_1
293 state: absent
294 check_mode: true
295 register: cm_delete_node_profile
296
297 - name: Delete Node Profile
298 cisco.mso.ndo_node_profile:
299 <<: *delete_node_profile
300 register: nm_delete_node_profile
301
302 - name: Delete Node Profile
303 cisco.mso.ndo_node_profile:
304 <<: *delete_node_profile
305 register: nm_delete_node_profile_again
306
307 - name: Delete Node Profile with UUID
308 cisco.mso.ndo_node_profile:
309 <<: *mso_info
310 template: ansible_fabric_resource_policy_template
311 uuid: "{{ nm_node_profile_2.current.uuid }}"
312 state: absent
313 register: nm_delete_node_profile_with_uuid
314
315 - name: Assert Node Profile is deleted
316 ansible.builtin.assert:
317 that:
318 - cm_delete_node_profile is changed
319 - nm_delete_node_profile is changed
320 - cm_delete_node_profile.current == nm_delete_node_profile.current == {}
321 - cm_delete_node_profile.previous == nm_delete_node_profile.previous
322 - cm_delete_node_profile.previous.name == nm_delete_node_profile.previous.name == "ansible_node_profile_1"
323 - cm_delete_node_profile.previous.uuid is defined
324 - nm_delete_node_profile_again is not changed
325 - nm_delete_node_profile_again.previous == nm_delete_node_profile_again.current == {}
326 - nm_delete_node_profile_again.current.uuid is not defined
327 - nm_delete_node_profile_with_uuid is changed
328 - nm_delete_node_profile_with_uuid.current == {}
329 - nm_delete_node_profile_with_uuid.previous.name == "ansible_node_profile_2"
330
331 # NO POLICIES
332 - name: Query all Node Profiles in the template when all are deleted
333 cisco.mso.ndo_node_profile:
334 <<: *query_all_node_profiles
335 register: query_all_none
336
337 - name: Update Node Profile with non-existing UUID
338 cisco.mso.ndo_node_profile:
339 <<: *mso_info
340 template: ansible_fabric_resource_policy_template
341 uuid: non-existing-uuid
342 node_setting_uuid: "{{ node_setting.results[0].current.uuid }}"
343 nodes: [104]
344 state: present
345 ignore_errors: true
346 register: update_non_existing_uuid
347
348 - name: Set error message for non_existing_uuid
349 ansible.builtin.set_fact:
350 error_message_non_existing_uuid: "Node Profile with the UUID: 'non-existing-uuid' not found"
351
352 - name: Assert no Node Profile found
353 assert:
354 that:
355 - query_all_none is not changed
356 - query_all_none.current == []
357 - update_non_existing_uuid is failed
358 - update_non_existing_uuid.msg == error_message_non_existing_uuid
359
360 # CLEANUP
361 - name: Ensure fabric resource template does not exist
362 cisco.mso.ndo_template:
363 <<: *ndo_fabric_resource_template_absent
364
365 - name: Ensure fabric policy template does not exist
366 cisco.mso.ndo_template:
367 <<: *ndo_fabric_policy_template_absent