Debian Codegraph @

ansible_collections/cisco/intersight/tests/integration/targets/intersight_organization/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 # --- Setup: Create prerequisite Resource Group ---
12 - name: Create test Resource Group for org assignment
13 cisco.intersight.intersight_resource_group:
14 <<: *api_info
15 name: test_rg_for_org
16 description: "Resource group for organization tests"
17 qualifier: all
18 register: setup_rg
19
20 # --- Cleanup environment ---
21 - name: Make sure Env is clean
22 cisco.intersight.intersight_organization:
23 <<: *api_info
24 name: "{{ item }}"
25 state: absent
26 loop:
27 - test_org
28 - test_org_shared
29
30 # --- Basic Organization tests (share_resources: false) ---
31 - name: Create Organization - check-mode
32 cisco.intersight.intersight_organization:
33 <<: *api_info
34 name: test_org
35 description: "Test organization"
36 resource_groups:
37 - test_rg_for_org
38 check_mode: true
39 register: create_check_mode
40
41 - name: Verify check-mode did not create resource
42 ansible.builtin.assert:
43 that:
44 - create_check_mode is changed
45 - create_check_mode.api_response == {}
46
47 - name: Create Organization with Resource Group
48 cisco.intersight.intersight_organization:
49 <<: *api_info
50 name: test_org
51 description: "Test organization"
52 resource_groups:
53 - test_rg_for_org
54 register: create_result
55
56 - name: Fetch info after creation
57 cisco.intersight.intersight_organization_info:
58 <<: *api_info
59 name: test_org
60 register: create_info
61
62 - name: Verify creation
63 ansible.builtin.assert:
64 that:
65 - create_result.changed
66 - create_info.api_response[0].Name == 'test_org'
67 - create_info.api_response[0].Description == 'Test organization'
68 - create_info.api_response[0].ResourceGroups | length == 1
69 - create_info.api_response[0].ResourceGroups[0].Moid == setup_rg.api_response.Moid
70
71 - name: Verify response alignment
72 ansible.builtin.assert:
73 that:
74 - create_result.api_response.Name == create_info.api_response[0].Name
75 - create_result.api_response.Moid == create_info.api_response[0].Moid
76 - create_result.api_response.ResourceGroups | length == 1
77
78 - name: Create Organization with Resource Group (idempotency)
79 cisco.intersight.intersight_organization:
80 <<: *api_info
81 name: test_org
82 description: "Test organization"
83 resource_groups:
84 - test_rg_for_org
85 register: create_idempotent
86
87 - name: Verify idempotency
88 ansible.builtin.assert:
89 that:
90 - not create_idempotent.changed
91
92 - name: Update Organization description
93 cisco.intersight.intersight_organization:
94 <<: *api_info
95 name: test_org
96 description: "Updated description"
97 resource_groups:
98 - test_rg_for_org
99 register: update_result
100
101 - name: Fetch info after update
102 cisco.intersight.intersight_organization_info:
103 <<: *api_info
104 name: test_org
105 register: update_info
106
107 - name: Verify update
108 ansible.builtin.assert:
109 that:
110 - update_result.changed
111 - update_info.api_response[0].Description == 'Updated description'
112
113 # --- Shared Organization tests (share_resources: true) ---
114 - name: Create second Organization for sharing tests
115 cisco.intersight.intersight_organization:
116 <<: *api_info
117 name: test_org_shared
118 description: "Organization to share with"
119 register: shared_org_result
120
121 - name: Update Organization to share resources
122 cisco.intersight.intersight_organization:
123 <<: *api_info
124 name: test_org
125 description: "Updated description"
126 share_resources: true
127 shared_orgs:
128 - test_org_shared
129 register: share_result
130
131 - name: Verify sharing was configured
132 ansible.builtin.assert:
133 that:
134 - share_result.changed
135
136 - name: Update Organization to share resources (idempotency)
137 cisco.intersight.intersight_organization:
138 <<: *api_info
139 name: test_org
140 description: "Updated description"
141 share_resources: true
142 shared_orgs:
143 - test_org_shared
144 register: share_idempotent
145
146 - name: Verify sharing idempotency
147 ansible.builtin.assert:
148 that:
149 - not share_idempotent.changed
150
151 - name: Switch back to non-shared mode
152 cisco.intersight.intersight_organization:
153 <<: *api_info
154 name: test_org
155 description: "Updated description"
156 resource_groups:
157 - test_rg_for_org
158 register: unshare_result
159
160 - name: Fetch info after switch to non-shared
161 cisco.intersight.intersight_organization_info:
162 <<: *api_info
163 name: test_org
164 register: unshare_info
165
166 - name: Verify switch to non-shared restored resource groups
167 ansible.builtin.assert:
168 that:
169 - unshare_result.changed
170 - unshare_info.api_response[0].ResourceGroups | length == 1
171 - unshare_info.api_response[0].ResourceGroups[0].Moid == setup_rg.api_response.Moid
172
173 # --- Fetch all Organizations ---
174 - name: Fetch all Organizations
175 cisco.intersight.intersight_organization_info:
176 <<: *api_info
177 register: all_orgs_info
178
179 - name: Verify at least one Organization exists
180 ansible.builtin.assert:
181 that:
182 - all_orgs_info.api_response | length >= 1
183
184 # --- Deletion tests ---
185 - name: Delete Organization
186 cisco.intersight.intersight_organization:
187 <<: *api_info
188 name: test_org
189 state: absent
190 register: delete_result
191
192 - name: Verify deletion
193 ansible.builtin.assert:
194 that:
195 - delete_result.changed
196
197 - name: Delete Organization again (idempotency)
198 cisco.intersight.intersight_organization:
199 <<: *api_info
200 name: test_org
201 state: absent
202 register: delete_idempotent
203
204 - name: Verify delete idempotency
205 ansible.builtin.assert:
206 that:
207 - not delete_idempotent.changed
208
209 # --- Validation tests ---
210 - name: Test validation - share_resources with resource_groups (should fail)
211 cisco.intersight.intersight_organization:
212 <<: *api_info
213 name: test_org_validation
214 share_resources: true
215 shared_orgs:
216 - test_org_shared
217 resource_groups:
218 - test_rg_for_org
219 register: validation_fail
220 failed_when:
221 - validation_fail.failed == false
222
223 always:
224 - name: Remove all test Organizations
225 cisco.intersight.intersight_organization:
226 <<: *api_info
227 name: "{{ item }}"
228 state: absent
229 loop:
230 - test_org
231 - test_org_shared
232
233 - name: Remove test Resource Group
234 cisco.intersight.intersight_resource_group:
235 <<: *api_info
236 name: test_rg_for_org
237 state: absent