Debian Codegraph @

ansible_collections/cisco/intersight/tests/integration/targets/intersight_chassis_profile/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 - chassis profiles
13 cisco.intersight.intersight_chassis_profile:
14 <<: *api_info
15 name: "{{ item }}"
16 state: absent
17 loop:
18 - test_cp_basic
19 - test_cp_with_policies
20 - test_cp_multi_policy
21
22 - name: Make sure Env is clean - Power policy
23 cisco.intersight.intersight_power_policy:
24 <<: *api_info
25 name: "{{ item }}"
26 state: absent
27 loop:
28 - test_cp_power_policy
29 - test_cp_power_policy_2
30
31 - name: Make sure Env is clean - SNMP policy
32 cisco.intersight.intersight_snmp_policy:
33 <<: *api_info
34 name: test_cp_snmp_policy
35 state: absent
36
37 - name: Make sure Env is clean - Thermal policy
38 cisco.intersight.intersight_thermal_policy:
39 <<: *api_info
40 name: test_cp_thermal_policy
41 state: absent
42
43 - name: Create Power policy
44 cisco.intersight.intersight_power_policy:
45 <<: *api_info
46 name: test_cp_power_policy
47 target_platform: Chassis
48 power_redundancy: Grid
49 register: power_policy_res
50
51 - name: Create second Power policy for swap test
52 cisco.intersight.intersight_power_policy:
53 <<: *api_info
54 name: test_cp_power_policy_2
55 target_platform: Chassis
56 power_redundancy: "N+1"
57 register: power_policy_2_res
58
59 - name: Create SNMP policy
60 cisco.intersight.intersight_snmp_policy:
61 <<: *api_info
62 name: test_cp_snmp_policy
63 enabled: true
64 snmp_port: 161
65 sys_contact: "[email protected]"
66 sys_location: "Lab-DC1"
67 register: snmp_policy_res
68
69 - name: Create Thermal policy
70 cisco.intersight.intersight_thermal_policy:
71 <<: *api_info
72 name: test_cp_thermal_policy
73 fan_control_mode: Balanced
74 register: thermal_policy_res
75
76 # -- Check Mode --
77
78 - name: Create chassis profile - check-mode
79 cisco.intersight.intersight_chassis_profile:
80 <<: *api_info
81 name: test_cp_basic
82 description: "Basic chassis profile"
83 tags:
84 - Key: "Environment"
85 Value: "Test"
86 check_mode: true
87 register: creation_check_mode_res
88
89 - name: Verify profile was not created - check-mode
90 ansible.builtin.assert:
91 that:
92 - creation_check_mode_res is changed
93 - creation_check_mode_res.api_response == {}
94
95 # -- Create --
96
97 - name: Create chassis profile
98 cisco.intersight.intersight_chassis_profile:
99 <<: *api_info
100 name: test_cp_basic
101 description: "Basic chassis profile"
102 tags:
103 - Key: "Environment"
104 Value: "Test"
105 register: creation_res
106
107 - name: Verify profile creation
108 ansible.builtin.assert:
109 that:
110 - creation_res is changed
111 - creation_res.api_response.Name == 'test_cp_basic'
112 - creation_res.api_response.Moid is defined
113
114 # -- Idempotency --
115
116 - name: Create chassis profile (idempotency)
117 cisco.intersight.intersight_chassis_profile:
118 <<: *api_info
119 name: test_cp_basic
120 description: "Basic chassis profile"
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 # -- Info Module --
132
133 - name: Fetch chassis profile info by name
134 cisco.intersight.intersight_chassis_profile_info:
135 <<: *api_info
136 name: test_cp_basic
137 register: info_res
138
139 - name: Verify info response
140 ansible.builtin.assert:
141 that:
142 - info_res.api_response | length == 1
143 - info_res.api_response[0].Name == 'test_cp_basic'
144
145 # -- Single Policy --
146
147 - name: Create profile with one Power policy
148 cisco.intersight.intersight_chassis_profile:
149 <<: *api_info
150 name: test_cp_with_policies
151 description: "Profile with single policy"
152 power_policy: test_cp_power_policy
153 register: single_policy_res
154
155 - name: Verify single-policy profile
156 ansible.builtin.assert:
157 that:
158 - single_policy_res is changed
159 - single_policy_res.api_response.Name == 'test_cp_with_policies'
160 - single_policy_res.api_response.PolicyBucket | length == 1
161
162 - name: Single-policy profile (idempotency)
163 cisco.intersight.intersight_chassis_profile:
164 <<: *api_info
165 name: test_cp_with_policies
166 description: "Profile with single policy"
167 power_policy: test_cp_power_policy
168 register: single_policy_idempotent_res
169
170 - name: Verify single-policy idempotency
171 ansible.builtin.assert:
172 that:
173 - not single_policy_idempotent_res.changed
174
175 # -- Policy Swap --
176
177 - name: Swap Power policy to a different one
178 cisco.intersight.intersight_chassis_profile:
179 <<: *api_info
180 name: test_cp_with_policies
181 description: "Profile with single policy"
182 power_policy: test_cp_power_policy_2
183 register: swap_policy_res
184
185 - name: Verify Power policy swap triggered change
186 ansible.builtin.assert:
187 that:
188 - swap_policy_res is changed
189 - swap_policy_res.api_response.PolicyBucket | length == 1
190
191 # -- Remove All Policies --
192
193 - name: Remove all policies from profile
194 cisco.intersight.intersight_chassis_profile:
195 <<: *api_info
196 name: test_cp_with_policies
197 description: "Profile with single policy"
198 register: remove_all_res
199
200 - name: Verify policy removal triggered change
201 ansible.builtin.assert:
202 that:
203 - remove_all_res is changed
204
205 # -- Multiple Policies --
206
207 - name: Create profile with multiple policies (Power + SNMP + Thermal)
208 cisco.intersight.intersight_chassis_profile:
209 <<: *api_info
210 name: test_cp_multi_policy
211 description: "Profile with multiple policies"
212 power_policy: test_cp_power_policy
213 snmp_policy: test_cp_snmp_policy
214 thermal_policy: test_cp_thermal_policy
215 register: multi_create_res
216
217 - name: Verify multi-policy profile creation
218 ansible.builtin.assert:
219 that:
220 - multi_create_res is changed
221 - multi_create_res.api_response.PolicyBucket | length == 3
222
223 - name: Multi-policy profile (idempotency)
224 cisco.intersight.intersight_chassis_profile:
225 <<: *api_info
226 name: test_cp_multi_policy
227 description: "Profile with multiple policies"
228 power_policy: test_cp_power_policy
229 snmp_policy: test_cp_snmp_policy
230 thermal_policy: test_cp_thermal_policy
231 register: multi_idempotent_res
232
233 - name: Verify multi-policy idempotency
234 ansible.builtin.assert:
235 that:
236 - not multi_idempotent_res.changed
237
238 # -- Remove One Policy --
239
240 - name: Remove SNMP policy (keep Power + Thermal)
241 cisco.intersight.intersight_chassis_profile:
242 <<: *api_info
243 name: test_cp_multi_policy
244 description: "Profile with multiple policies"
245 power_policy: test_cp_power_policy
246 thermal_policy: test_cp_thermal_policy
247 register: remove_one_res
248
249 - name: Verify policy count after removing SNMP
250 ansible.builtin.assert:
251 that:
252 - remove_one_res is changed
253
254 - name: After removing SNMP (idempotency)
255 cisco.intersight.intersight_chassis_profile:
256 <<: *api_info
257 name: test_cp_multi_policy
258 description: "Profile with multiple policies"
259 power_policy: test_cp_power_policy
260 thermal_policy: test_cp_thermal_policy
261 register: remove_one_idempotent_res
262
263 - name: Verify post-removal idempotency
264 ansible.builtin.assert:
265 that:
266 - not remove_one_idempotent_res.changed
267
268 # -- Strip All Policies --
269
270 - name: Strip all policies from multi-policy profile
271 cisco.intersight.intersight_chassis_profile:
272 <<: *api_info
273 name: test_cp_multi_policy
274 description: "Profile with multiple policies"
275 register: strip_all_res
276
277 - name: Verify all policies removed
278 ansible.builtin.assert:
279 that:
280 - strip_all_res is changed
281
282 # -- Info Module (list all) --
283
284 - name: Fetch all chassis profiles in the organization
285 cisco.intersight.intersight_chassis_profile_info:
286 <<: *api_info
287 register: all_info_res
288
289 - name: Verify at least 3 profiles exist
290 ansible.builtin.assert:
291 that:
292 - all_info_res.api_response | length >= 3
293
294 # -- Delete --
295
296 - name: Delete basic profile
297 cisco.intersight.intersight_chassis_profile:
298 <<: *api_info
299 name: test_cp_basic
300 state: absent
301 register: delete_basic_res
302
303 - name: Verify basic deletion
304 ansible.builtin.assert:
305 that:
306 - delete_basic_res is changed
307
308 - name: Delete basic profile again (idempotency)
309 cisco.intersight.intersight_chassis_profile:
310 <<: *api_info
311 name: test_cp_basic
312 state: absent
313 register: delete_basic_idempotent_res
314
315 - name: Verify delete idempotency
316 ansible.builtin.assert:
317 that:
318 - not delete_basic_idempotent_res.changed
319
320 always:
321 - name: Cleanup - remove chassis profiles
322 cisco.intersight.intersight_chassis_profile:
323 <<: *api_info
324 name: "{{ item }}"
325 state: absent
326 loop:
327 - test_cp_basic
328 - test_cp_with_policies
329 - test_cp_multi_policy
330 ignore_errors: true
331
332 - name: Cleanup - remove Power policies
333 cisco.intersight.intersight_power_policy:
334 <<: *api_info
335 name: "{{ item }}"
336 state: absent
337 loop:
338 - test_cp_power_policy
339 - test_cp_power_policy_2
340 ignore_errors: true
341
342 - name: Cleanup - remove SNMP policy
343 cisco.intersight.intersight_snmp_policy:
344 <<: *api_info
345 name: test_cp_snmp_policy
346 state: absent
347 ignore_errors: true
348
349 - name: Cleanup - remove Thermal policy
350 cisco.intersight.intersight_thermal_policy:
351 <<: *api_info
352 name: test_cp_thermal_policy
353 state: absent
354 ignore_errors: true