Debian Codegraph @

ansible_collections/cisco/intersight/tests/integration/targets/intersight_domain/tasks/tests.yml

raw
1 ---
2 - block:
3 - name: Define anchor for Intersight API login info
4 ansible.builtin.set_fact:
5 api_info: &api_info
6 api_private_key: "{{ api_private_key }}"
7 api_key_id: "{{ api_key_id }}"
8 api_uri: "{{ api_uri | default(omit) }}"
9 validate_certs: "{{ validate_certs | default(omit) }}"
10 organization: "{{ organization }}"
11
12 - name: Make sure Env is clean - domain profiles
13 cisco.intersight.intersight_domain:
14 <<: *api_info
15 name: "{{ item }}"
16 state: absent
17 loop:
18 - test_domain_basic
19 - test_domain_with_policies
20
21 - name: Make sure Env is clean - System QoS policy
22 cisco.intersight.intersight_system_qos_policy:
23 <<: *api_info
24 name: "{{ item }}"
25 state: absent
26 loop:
27 - test_domain_qos
28 - test_domain_qos_2
29
30 - name: Make sure Env is clean - NTP policy
31 cisco.intersight.intersight_ntp_policy:
32 <<: *api_info
33 name: test_domain_ntp
34 state: absent
35
36 - name: Make sure Env is clean - SNMP policy
37 cisco.intersight.intersight_snmp_policy:
38 <<: *api_info
39 name: test_domain_snmp
40 state: absent
41
42 - name: Create System QoS policy
43 cisco.intersight.intersight_system_qos_policy:
44 <<: *api_info
45 name: test_domain_qos
46 register: qos_policy_res
47
48 - name: Create second System QoS policy for swap test
49 cisco.intersight.intersight_system_qos_policy:
50 <<: *api_info
51 name: test_domain_qos_2
52 register: qos_policy_2_res
53
54 - name: Create NTP policy
55 cisco.intersight.intersight_ntp_policy:
56 <<: *api_info
57 name: test_domain_ntp
58 enable: true
59 ntp_servers:
60 - 0.pool.ntp.org
61 register: ntp_policy_res
62
63 - name: Create SNMP policy
64 cisco.intersight.intersight_snmp_policy:
65 <<: *api_info
66 name: test_domain_snmp
67 enabled: true
68 snmp_port: 161
69 sys_contact: "[email protected]"
70 sys_location: "Lab-DC1"
71 register: snmp_policy_res
72
73 # -- Check Mode --
74
75 - name: Create domain profile - check-mode
76 cisco.intersight.intersight_domain:
77 <<: *api_info
78 name: test_domain_basic
79 description: "Basic domain profile"
80 system_qos_policy: test_domain_qos
81 tags:
82 - Key: "Environment"
83 Value: "Test"
84 check_mode: true
85 register: creation_check_mode_res
86
87 - name: Verify profile was not created - check-mode
88 ansible.builtin.assert:
89 that:
90 - creation_check_mode_res is changed
91 - creation_check_mode_res.api_response == {}
92
93 # -- Create --
94
95 - name: Create domain profile
96 cisco.intersight.intersight_domain:
97 <<: *api_info
98 name: test_domain_basic
99 description: "Basic domain profile"
100 system_qos_policy: test_domain_qos
101 tags:
102 - Key: "Environment"
103 Value: "Test"
104 register: creation_res
105
106 - name: Verify profile creation
107 ansible.builtin.assert:
108 that:
109 - creation_res is changed
110 - creation_res.api_response.Name == 'test_domain_basic'
111 - creation_res.api_response.Moid is defined
112
113 # -- Idempotency --
114
115 - name: Create domain profile (idempotency)
116 cisco.intersight.intersight_domain:
117 <<: *api_info
118 name: test_domain_basic
119 description: "Basic domain profile"
120 system_qos_policy: test_domain_qos
121 tags:
122 - Key: "Environment"
123 Value: "Test"
124 register: creation_idempotent_res
125
126 - name: Verify idempotency - no change
127 ansible.builtin.assert:
128 that:
129 - not creation_idempotent_res.changed
130
131 # -- Update --
132
133 - name: Update domain profile description and tags
134 cisco.intersight.intersight_domain:
135 <<: *api_info
136 name: test_domain_basic
137 description: "Updated domain profile"
138 system_qos_policy: test_domain_qos
139 tags:
140 - Key: "Environment"
141 Value: "Staging"
142 - Key: "Owner"
143 Value: "CI"
144 register: update_res
145
146 - name: Verify update triggered change
147 ansible.builtin.assert:
148 that:
149 - update_res is changed
150 - update_res.api_response.Name == 'test_domain_basic'
151 - update_res.api_response.Description == 'Updated domain profile'
152
153 - name: Update domain profile (idempotency)
154 cisco.intersight.intersight_domain:
155 <<: *api_info
156 name: test_domain_basic
157 description: "Updated domain profile"
158 system_qos_policy: test_domain_qos
159 tags:
160 - Key: "Environment"
161 Value: "Staging"
162 - Key: "Owner"
163 Value: "CI"
164 register: update_idempotent_res
165
166 - name: Verify update idempotency
167 ansible.builtin.assert:
168 that:
169 - not update_idempotent_res.changed
170
171 # -- Info Module --
172
173 - name: Fetch domain profile info by name
174 cisco.intersight.intersight_domain_info:
175 <<: *api_info
176 name: test_domain_basic
177 register: info_res
178
179 - name: Verify info response structure and updated values
180 ansible.builtin.assert:
181 that:
182 - info_res.api_response | length == 1
183 - info_res.api_response[0].Name == 'test_domain_basic'
184 - info_res.api_response[0].ObjectType == 'fabric.SwitchClusterProfile'
185 - info_res.api_response[0].Description == 'Updated domain profile'
186 - info_res.api_response[0].Tags | length == 2
187 - info_res.api_response[0].SwitchProfiles | length == 2
188 - info_res.api_response[0].SwitchProfiles | selectattr('SwitchId', 'equalto', 'A') | list | length == 1
189 - info_res.api_response[0].SwitchProfiles | selectattr('SwitchId', 'equalto', 'B') | list | length == 1
190
191 - name: Verify switch profile A has QoS policy in bucket
192 vars:
193 profile_a: "{{ info_res.api_response[0].SwitchProfiles | selectattr('SwitchId', 'equalto', 'A') | first }}"
194 ansible.builtin.assert:
195 that:
196 - profile_a.PolicyBucket | selectattr('ObjectType', 'equalto', 'fabric.SystemQosPolicy') | list | length == 1
197
198 # -- With Policies --
199
200 - name: Create domain profile with multiple shared policies
201 cisco.intersight.intersight_domain:
202 <<: *api_info
203 name: test_domain_with_policies
204 description: "Profile with policies"
205 system_qos_policy: test_domain_qos
206 ntp_policy: test_domain_ntp
207 snmp_policy: test_domain_snmp
208 register: multi_policy_res
209
210 - name: Verify multi-policy profile creation
211 ansible.builtin.assert:
212 that:
213 - multi_policy_res is changed
214 - multi_policy_res.api_response.Name == 'test_domain_with_policies'
215
216 - name: Fetch multi-policy domain info to verify policies
217 cisco.intersight.intersight_domain_info:
218 <<: *api_info
219 name: test_domain_with_policies
220 register: multi_policy_info_res
221
222 - name: Verify all shared policies attached to both switch profiles
223 vars:
224 profile_a: "{{ multi_policy_info_res.api_response[0].SwitchProfiles | selectattr('SwitchId', 'equalto', 'A') | first }}"
225 profile_b: "{{ multi_policy_info_res.api_response[0].SwitchProfiles | selectattr('SwitchId', 'equalto', 'B') | first }}"
226 expected_policy_types:
227 - fabric.SystemQosPolicy
228 - ntp.Policy
229 - snmp.Policy
230 ansible.builtin.assert:
231 that:
232 - profile_a.PolicyBucket | selectattr('ObjectType', 'equalto', item) | list | length == 1
233 - profile_b.PolicyBucket | selectattr('ObjectType', 'equalto', item) | list | length == 1
234 loop: "{{ expected_policy_types }}"
235
236 - name: Multi-policy domain profile (idempotency)
237 cisco.intersight.intersight_domain:
238 <<: *api_info
239 name: test_domain_with_policies
240 description: "Profile with policies"
241 system_qos_policy: test_domain_qos
242 ntp_policy: test_domain_ntp
243 snmp_policy: test_domain_snmp
244 register: multi_policy_idempotent_res
245
246 - name: Verify multi-policy idempotency
247 ansible.builtin.assert:
248 that:
249 - not multi_policy_idempotent_res.changed
250
251 # -- Policy Swap --
252
253 - name: Swap System QoS policy to a different one
254 cisco.intersight.intersight_domain:
255 <<: *api_info
256 name: test_domain_with_policies
257 description: "Profile with policies"
258 system_qos_policy: test_domain_qos_2
259 ntp_policy: test_domain_ntp
260 snmp_policy: test_domain_snmp
261 register: swap_policy_res
262
263 - name: Verify policy swap triggered change
264 ansible.builtin.assert:
265 that:
266 - swap_policy_res is changed
267
268 - name: Fetch info after policy swap
269 cisco.intersight.intersight_domain_info:
270 <<: *api_info
271 name: test_domain_with_policies
272 register: swap_info_res
273
274 - name: Verify QoS policy was swapped to the new one
275 vars:
276 profile_a: "{{ swap_info_res.api_response[0].SwitchProfiles | selectattr('SwitchId', 'equalto', 'A') | first }}"
277 qos_policy: "{{ profile_a.PolicyBucket | selectattr('ObjectType', 'equalto', 'fabric.SystemQosPolicy') | first }}"
278 ansible.builtin.assert:
279 that:
280 - qos_policy.Moid == qos_policy_2_res.api_response.Moid
281
282 # -- Remove One Policy --
283
284 - name: Remove SNMP policy (keep QoS + NTP)
285 cisco.intersight.intersight_domain:
286 <<: *api_info
287 name: test_domain_with_policies
288 description: "Profile with policies"
289 system_qos_policy: test_domain_qos_2
290 ntp_policy: test_domain_ntp
291 register: remove_one_res
292
293 - name: Verify policy removal triggered change
294 ansible.builtin.assert:
295 that:
296 - remove_one_res is changed
297
298 - name: Fetch info after SNMP policy removal
299 cisco.intersight.intersight_domain_info:
300 <<: *api_info
301 name: test_domain_with_policies
302 register: remove_info_res
303
304 - name: Verify SNMP policy was removed and remaining policies are intact
305 vars:
306 profile_a: "{{ remove_info_res.api_response[0].SwitchProfiles | selectattr('SwitchId', 'equalto', 'A') | first }}"
307 ansible.builtin.assert:
308 that:
309 - profile_a.PolicyBucket | selectattr('ObjectType', 'equalto', 'snmp.Policy') | list | length == 0
310 - profile_a.PolicyBucket | selectattr('ObjectType', 'equalto', 'fabric.SystemQosPolicy') | list | length == 1
311 - profile_a.PolicyBucket | selectattr('ObjectType', 'equalto', 'ntp.Policy') | list | length == 1
312
313 - name: After removing SNMP (idempotency)
314 cisco.intersight.intersight_domain:
315 <<: *api_info
316 name: test_domain_with_policies
317 description: "Profile with policies"
318 system_qos_policy: test_domain_qos_2
319 ntp_policy: test_domain_ntp
320 register: remove_one_idempotent_res
321
322 - name: Verify post-removal idempotency
323 ansible.builtin.assert:
324 that:
325 - not remove_one_idempotent_res.changed
326
327 # -- Info Module (list all) --
328
329 - name: Fetch all domain profiles in the organization
330 cisco.intersight.intersight_domain_info:
331 <<: *api_info
332 register: all_info_res
333
334 - name: Verify at least 2 profiles exist with enriched data
335 ansible.builtin.assert:
336 that:
337 - all_info_res.api_response | length >= 2
338 - all_info_res.api_response | selectattr('Name', 'equalto', 'test_domain_basic') | list | length == 1
339 - all_info_res.api_response | selectattr('Name', 'equalto', 'test_domain_with_policies') | list | length == 1
340 - (all_info_res.api_response | selectattr('Name', 'equalto', 'test_domain_basic') | first).SwitchProfiles is defined
341
342 # -- Delete --
343
344 - name: Delete basic domain profile
345 cisco.intersight.intersight_domain:
346 <<: *api_info
347 name: test_domain_basic
348 state: absent
349 register: delete_basic_res
350
351 - name: Verify basic deletion
352 ansible.builtin.assert:
353 that:
354 - delete_basic_res is changed
355
356 - name: Delete basic domain profile again (idempotency)
357 cisco.intersight.intersight_domain:
358 <<: *api_info
359 name: test_domain_basic
360 state: absent
361 register: delete_basic_idempotent_res
362
363 - name: Verify delete idempotency
364 ansible.builtin.assert:
365 that:
366 - not delete_basic_idempotent_res.changed
367
368 always:
369 - name: Cleanup - remove domain profiles
370 cisco.intersight.intersight_domain:
371 <<: *api_info
372 name: "{{ item }}"
373 state: absent
374 loop:
375 - test_domain_basic
376 - test_domain_with_policies
377 ignore_errors: true
378
379 - name: Cleanup - remove System QoS policies
380 cisco.intersight.intersight_system_qos_policy:
381 <<: *api_info
382 name: "{{ item }}"
383 state: absent
384 loop:
385 - test_domain_qos
386 - test_domain_qos_2
387 ignore_errors: true
388
389 - name: Cleanup - remove NTP policy
390 cisco.intersight.intersight_ntp_policy:
391 <<: *api_info
392 name: test_domain_ntp
393 state: absent
394 ignore_errors: true
395
396 - name: Cleanup - remove SNMP policy
397 cisco.intersight.intersight_snmp_policy:
398 <<: *api_info
399 name: test_domain_snmp
400 state: absent
401 ignore_errors: true