Debian Codegraph @

ansible_collections/cisco/intersight/tests/integration/targets/intersight_rest_api/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
11
12 # Fetch Organization MOID
13 - name: Get organization details using REST API
14 cisco.intersight.intersight_rest_api:
15 <<: *api_info
16 resource_path: /organization/Organizations
17 query_params:
18 $filter: "Name eq '{{ organization }}'"
19 register: org_result
20
21 - name: Set organization MOID fact
22 ansible.builtin.set_fact:
23 organization_moid: "{{ org_result.api_response.Moid }}"
24
25 - name: Verify organization was found
26 ansible.builtin.assert:
27 that:
28 - org_result.api_response.Name == organization
29 - organization_moid is defined
30 - organization_moid | length > 0
31
32 # Cleanup
33 - name: Clean up test thermal policy using REST API
34 cisco.intersight.intersight_rest_api:
35 <<: *api_info
36 resource_path: "/thermal/Policies"
37 query_params:
38 $filter: "Name eq '{{ test_thermal_policy_name }}'"
39 state: absent
40
41 - name: Clean up test multicast policy using REST API
42 cisco.intersight.intersight_rest_api:
43 <<: *api_info
44 resource_path: "/fabric/MulticastPolicies"
45 query_params:
46 $filter: "Name eq '{{ test_multicast_policy_name }}'"
47 state: absent
48
49 # Thermal Policy Tests
50 - name: Create thermal policy using REST API - check mode
51 cisco.intersight.intersight_rest_api:
52 <<: *api_info
53 resource_path: "/thermal/Policies"
54 update_method: post
55 api_body: |
56 {
57 "Organization": {
58 "ObjectType": "organization.Organization",
59 "Moid": "{{ organization_moid }}"
60 },
61 "Name": "{{ test_thermal_policy_name }}",
62 "FanControlMode": "Balanced",
63 "Tags": [
64 {
65 "Key": "Test",
66 "Value": "RestAPI"
67 },
68 {
69 "Key": "Environment",
70 "Value": "CI"
71 }
72 ]
73 }
74 check_mode: true
75 register: thermal_create_check
76
77 - name: Verify thermal policy was not created in check mode
78 ansible.builtin.assert:
79 that:
80 - thermal_create_check is changed
81 - thermal_create_check.api_response == {}
82
83 - name: Create thermal policy using REST API
84 cisco.intersight.intersight_rest_api:
85 <<: *api_info
86 resource_path: "/thermal/Policies"
87 update_method: post
88 api_body: |
89 {
90 "Organization": {
91 "ObjectType": "organization.Organization",
92 "Moid": "{{ organization_moid }}"
93 },
94 "Name": "{{ test_thermal_policy_name }}",
95 "FanControlMode": "Balanced",
96 "Tags": [
97 {
98 "Key": "Test",
99 "Value": "RestAPI"
100 },
101 {
102 "Key": "Environment",
103 "Value": "CI"
104 }
105 ]
106 }
107 register: thermal_create
108
109 - name: Verify thermal policy was created via REST API
110 ansible.builtin.assert:
111 that:
112 - thermal_create is changed
113 - thermal_create.api_response.Name == test_thermal_policy_name
114 - thermal_create.api_response.FanControlMode == "Balanced"
115
116 - name: Verify thermal policy creation using dedicated info module
117 cisco.intersight.intersight_thermal_policy_info:
118 <<: *api_info
119 name: "{{ test_thermal_policy_name }}"
120 register: thermal_info_verify
121
122 - name: Assert thermal policy was created correctly using info module
123 ansible.builtin.assert:
124 that:
125 - thermal_info_verify.api_response | length == 1
126 - thermal_info_verify.api_response[0].Name == test_thermal_policy_name
127 - thermal_info_verify.api_response[0].FanControlMode == "Balanced"
128
129 - name: Get thermal policy using REST API with query filter
130 cisco.intersight.intersight_rest_api:
131 <<: *api_info
132 resource_path: "/thermal/Policies"
133 query_params:
134 $filter: "Name eq '{{ test_thermal_policy_name }}'"
135 register: thermal_get
136
137 - name: Verify thermal policy GET operation
138 ansible.builtin.assert:
139 that:
140 - thermal_get is not changed
141 - thermal_get.api_response.Name == test_thermal_policy_name
142 - thermal_get.api_response.FanControlMode == "Balanced"
143
144 - name: Create thermal policy using REST API - idempotency check
145 cisco.intersight.intersight_rest_api:
146 <<: *api_info
147 resource_path: "/thermal/Policies"
148 query_params:
149 $filter: "Name eq '{{ test_thermal_policy_name }}'"
150 update_method: post
151 api_body: |
152 {
153 "Organization": {
154 "ObjectType": "organization.Organization",
155 "Moid": "{{ organization_moid }}"
156 },
157 "Name": "{{ test_thermal_policy_name }}",
158 "FanControlMode": "Balanced",
159 "Tags": [
160 {
161 "Key": "Test",
162 "Value": "RestAPI"
163 },
164 {
165 "Key": "Environment",
166 "Value": "CI"
167 }
168 ]
169 }
170 register: thermal_create_idem
171
172 - name: Verify thermal policy creation is idempotent
173 ansible.builtin.assert:
174 that:
175 - thermal_create_idem is not changed
176
177 - name: Update thermal policy using REST API
178 cisco.intersight.intersight_rest_api:
179 <<: *api_info
180 resource_path: "/thermal/Policies"
181 query_params:
182 $filter: "Name eq '{{ test_thermal_policy_name }}'"
183 update_method: post
184 api_body: |
185 {
186 "Organization": {
187 "ObjectType": "organization.Organization",
188 "Moid": "{{ organization_moid }}"
189 },
190 "Name": "{{ test_thermal_policy_name }}",
191 "FanControlMode": "HighPower",
192 "Tags": [
193 {
194 "Key": "Test",
195 "Value": "RestAPI"
196 },
197 {
198 "Key": "Environment",
199 "Value": "CI"
200 }
201 ]
202 }
203 register: thermal_update
204
205 - name: Verify thermal policy was updated via REST API
206 ansible.builtin.assert:
207 that:
208 - thermal_update is changed
209 - thermal_update.api_response.FanControlMode == "HighPower"
210
211 - name: Verify thermal policy update using dedicated info module
212 cisco.intersight.intersight_thermal_policy_info:
213 <<: *api_info
214 name: "{{ test_thermal_policy_name }}"
215 register: thermal_info_update
216
217 - name: Assert thermal policy was updated correctly
218 ansible.builtin.assert:
219 that:
220 - thermal_info_update.api_response[0].FanControlMode == "HighPower"
221
222 # Multicast Policy Tests
223 - name: Create multicast policy using REST API
224 cisco.intersight.intersight_rest_api:
225 <<: *api_info
226 resource_path: "/fabric/MulticastPolicies"
227 update_method: post
228 api_body: |
229 {
230 "Organization": {
231 "ObjectType": "organization.Organization",
232 "Moid": "{{ organization_moid }}"
233 },
234 "Name": "{{ test_multicast_policy_name }}",
235 "QuerierState": "Disabled",
236 "SnoopingState": "Enabled",
237 "SrcIpProxy": "Enabled",
238 "Tags": [
239 {
240 "Key": "Test",
241 "Value": "RestAPI"
242 }
243 ]
244 }
245 register: multicast_create
246
247 - name: Verify multicast policy was created via REST API
248 ansible.builtin.assert:
249 that:
250 - multicast_create is changed
251 - multicast_create.api_response.Name == test_multicast_policy_name
252 - multicast_create.api_response.QuerierState == "Disabled"
253 - multicast_create.api_response.SnoopingState == "Enabled"
254
255 - name: Verify multicast policy creation using dedicated info module
256 cisco.intersight.intersight_multicast_policy_info:
257 <<: *api_info
258 name: "{{ test_multicast_policy_name }}"
259 register: multicast_info_verify
260
261 - name: Assert multicast policy was created correctly using info module
262 ansible.builtin.assert:
263 that:
264 - multicast_info_verify.api_response | length == 1
265 - multicast_info_verify.api_response[0].Name == test_multicast_policy_name
266 - multicast_info_verify.api_response[0].QuerierState == "Disabled"
267 - multicast_info_verify.api_response[0].SnoopingState == "Enabled"
268
269 - name: Update multicast policy using REST API (enable querier)
270 cisco.intersight.intersight_rest_api:
271 <<: *api_info
272 resource_path: "/fabric/MulticastPolicies"
273 query_params:
274 $filter: "Name eq '{{ test_multicast_policy_name }}'"
275 update_method: post
276 api_body: |
277 {
278 "Organization": {
279 "ObjectType": "organization.Organization",
280 "Moid": "{{ organization_moid }}"
281 },
282 "Name": "{{ test_multicast_policy_name }}",
283 "QuerierState": "Enabled",
284 "QuerierIpAddress": "192.168.1.10",
285 "QuerierIpAddressPeer": "192.168.1.11",
286 "SnoopingState": "Enabled",
287 "SrcIpProxy": "Enabled",
288 "Tags": [
289 {
290 "Key": "Test",
291 "Value": "RestAPI"
292 }
293 ]
294 }
295 register: multicast_update
296
297 - name: Verify multicast policy was updated via REST API
298 ansible.builtin.assert:
299 that:
300 - multicast_update is changed
301 - multicast_update.api_response.QuerierState == "Enabled"
302 - multicast_update.api_response.QuerierIpAddress == "192.168.1.10"
303
304 - name: Verify multicast policy update using dedicated info module
305 cisco.intersight.intersight_multicast_policy_info:
306 <<: *api_info
307 name: "{{ test_multicast_policy_name }}"
308 register: multicast_info_update
309
310 - name: Assert multicast policy was updated correctly
311 ansible.builtin.assert:
312 that:
313 - multicast_info_update.api_response[0].QuerierState == "Enabled"
314 - multicast_info_update.api_response[0].QuerierIpAddress == "192.168.1.10"
315
316 # Error Handling Test
317 - name: Test invalid resource path (should fail gracefully)
318 cisco.intersight.intersight_rest_api:
319 <<: *api_info
320 resource_path: "/invalid/ResourcePath"
321 query_params:
322 $filter: "Name eq 'non-existent'"
323 register: invalid_path_result
324 failed_when:
325 - invalid_path_result is failed
326 - not "'Operation not supported. Check if the API path and method are valid' in invalid_path_result.msg"
327
328 always:
329 # Cleanup
330 - name: Delete thermal policy using REST API
331 cisco.intersight.intersight_rest_api:
332 <<: *api_info
333 resource_path: "/thermal/Policies"
334 query_params:
335 $filter: "Name eq '{{ test_thermal_policy_name }}'"
336 state: absent
337 failed_when: false
338
339 - name: Delete multicast policy using REST API
340 cisco.intersight.intersight_rest_api:
341 <<: *api_info
342 resource_path: "/fabric/MulticastPolicies"
343 query_params:
344 $filter: "Name eq '{{ test_multicast_policy_name }}'"
345 state: absent
346 failed_when: false