Debian Codegraph @

ansible_collections/cisco/mso/tests/integration/targets/mso_rest/tasks/json_inline.yml

raw
1 # Test code for the MSO modules
2 # Copyright: (c) 2020, Anvitha Jain (@anvitha-jain) <[email protected]>
3 #
4
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 - name: Test that we have an ACI MultiSite host, username and password
8 ansible.builtin.fail:
9 msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.'
10 when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
11
12
13 # CLEAN ENVIRONMENT
14 - name: Set vars
15 ansible.builtin.set_fact:
16 mso_info: &mso_info
17 host: '{{ mso_hostname }}'
18 username: '{{ mso_username }}'
19 password: '{{ mso_password }}'
20 validate_certs: '{{ mso_validate_certs | default(false) }}'
21 use_ssl: '{{ mso_use_ssl | default(true) }}'
22 use_proxy: '{{ mso_use_proxy | default(true) }}'
23 output_level: '{{ mso_output_level | default("debug") }}'
24
25 - name: Query MSO version
26 cisco.mso.mso_version:
27 <<: *mso_info
28 state: query
29 register: version
30
31 - name: Remove EXT_EPGs Providers from DHCP Relay Policy
32 cisco.mso.mso_dhcp_relay_policy_provider:
33 <<: *mso_info
34 dhcp_relay_policy: ansible_dhcp_relay_1
35 tenant: ansible_test
36 schema: '{{ mso_schema | default("ansible_test") }}'
37 template: Template 1
38 external_endpoint_group: "{{ item }}"
39 state: absent
40 ignore_errors: true
41 loop:
42 - EXT_EPG_1
43 - EXT_EPG_2
44
45 - name: Remove EXT_EPGs Providers from DHCP Relay Policy
46 cisco.mso.mso_dhcp_relay_policy_provider:
47 <<: *mso_info
48 dhcp_relay_policy: ansible_dhcp_relay_1
49 tenant: ansible_test
50 schema: '{{ mso_schema | default("ansible_test") }}'
51 template: Template 1
52 endpoint_group: "{{ item }}"
53 application_profile: "ANP_1"
54 state: absent
55 ignore_errors: true
56 loop:
57 - EPG_1
58 - EPG_2
59
60 - name: Stop consuming DHCP Policy
61 cisco.mso.mso_schema_template_bd:
62 <<: *mso_info
63 schema: '{{ mso_schema | default("ansible_test") }}'
64 template: Template 1
65 bd: CLIENT_BD
66 vrf:
67 name: VRF1
68 state: absent
69 ignore_errors: true
70
71 - name: Remove DHCP Relay Policies
72 cisco.mso.mso_dhcp_relay_policy:
73 <<: *mso_info
74 dhcp_relay_policy: '{{ item }}'
75 state: absent
76 ignore_errors: true
77 loop:
78 - ansible_dhcp_relay_1
79 - ansible_dhcp_relay_2
80
81 - name: Remove DHCP Option Policies
82 cisco.mso.mso_dhcp_option_policy:
83 <<: *mso_info
84 dhcp_option_policy: '{{ item }}'
85 state: absent
86 ignore_errors: true
87 loop:
88 - ansible_dhcp_option_1
89 - ansible_dhcp_option_2
90
91 - name: Remove schemas
92 cisco.mso.mso_schema:
93 <<: *mso_info
94 schema: '{{ item }}'
95 state: absent
96 ignore_errors: true
97 loop:
98 - '{{ mso_schema | default("ansible_test") }}_2'
99 - '{{ mso_schema | default("ansible_test") }}'
100
101 - name: Remove tenant ansible_test
102 cisco.mso.mso_tenant:
103 <<: *mso_info
104 tenant: ansible_test
105 state: absent
106 ignore_errors: true
107
108 # QUERY SCHEMAS
109 - name: Query schema
110 cisco.mso.mso_rest:
111 <<: *mso_info
112 path: /mso/api/v1/schemas
113 method: get
114 register: query_all_schema
115
116 - name: Verify query_all_schema in json_inline
117 ansible.builtin.assert:
118 that:
119 - query_all_schema is not changed
120
121 # QUERY A USER
122 - name: Query our user
123 cisco.mso.mso_user:
124 <<: *mso_info
125 state: query
126 user: '{{ mso_username }}'
127 check_mode: true
128 register: query_user_id
129
130 - name: Verify query_user_id
131 ansible.builtin.assert:
132 that:
133 - query_user_id is not changed
134 - query_user_id.current.username == '{{ mso_username }}'
135
136 # ADD tenant
137 - name: Add tenant
138 cisco.mso.mso_rest:
139 <<: *mso_info
140 path: /api/v1/tenants
141 method: post
142 content:
143 {
144 "displayName": "ansible_test",
145 "name": "ansible_test",
146 "description": "",
147 "siteAssociations": [],
148 "userAssociations": [{
149 "userId": "{{ query_user_id.current.id }}"
150 }],
151 "_updateVersion": 0,
152 }
153 register: add_tenant
154
155 - name: Verify add_tenant in json_inline
156 ansible.builtin.assert:
157 that:
158 - add_tenant is changed
159 - add_tenant.jsondata.displayName == 'ansible_test'
160
161 # ADD schema
162 - name: Add schema
163 cisco.mso.mso_rest:
164 <<: *mso_info
165 path: /mso/api/v1/schemas
166 method: post
167 content:
168 {
169 "displayName": "{{ mso_schema | default('ansible_test') }}",
170 "templates": [{
171 "name": "Template_1",
172 "tenantId": "{{ add_tenant.jsondata.id }}",
173 "displayName": "Template_1",
174 "templateSubType": [],
175 "templateType": "stretched-template",
176 "anps": [],
177 "contracts": [],
178 "vrfs": [],
179 "bds": [],
180 "filters": [],
181 "externalEpgs": [],
182 "serviceGraphs": [],
183 "intersiteL3outs": []
184 }],
185 "sites": [],
186 "_updateVersion": 0
187 }
188 register: add_schema
189
190 - name: Verify add_schema in json_inline
191 ansible.builtin.assert:
192 that:
193 - add_schema is changed
194 - add_schema.jsondata.displayName == 'ansible_test'
195
196 # PUT schema
197 - name: Put schema
198 cisco.mso.mso_rest:
199 <<: *mso_info
200 port: 443
201 path: "/mso/api/v1/schemas/{{ add_schema.jsondata.id }}"
202 method: put
203 content:
204 {
205 "displayName": "ansible_test_2",
206 "templates": [{
207 "name": "Template_1",
208 "tenantId": "{{ add_tenant.jsondata.id }}",
209 "displayName": "Template_1",
210 "templateSubType": [],
211 "templateType": "stretched-template",
212 "anps": [],
213 "contracts": [],
214 "vrfs": [],
215 "bds": [],
216 "filters": [],
217 "externalEpgs": [],
218 "serviceGraphs": [],
219 "intersiteL3outs": []
220 }],
221 "sites": [],
222 "_updateVersion": 0
223 }
224 register: put_schema
225
226 - name: Verify put_schema in json_inline
227 ansible.builtin.assert:
228 that:
229 - put_schema is changed
230 - put_schema.jsondata.displayName == 'ansible_test_2'
231
232 # PATCH schema
233 - name: Patch schema
234 cisco.mso.mso_rest:
235 <<: *mso_info
236 path: "/mso/api/v1/schemas/{{ add_schema.jsondata.id }}"
237 method: patch
238 content:
239 [
240 {
241 "op": "add",
242 "path": "/templates/Template_1/anps/-",
243 "value": { "name": "AP2", "displayName": "AP2", "epgs": [] },
244 "_updateVersion": 0
245 }
246 ]
247 register: patch_schema
248
249 - name: Verify patch_schema in json_inline
250 ansible.builtin.assert:
251 that:
252 - patch_schema is changed
253
254 - name: Verify patch_schema in json_inline
255 ansible.builtin.assert:
256 that:
257 - patch_schema.jsondata.templates[0].anps[0].displayName == 'AP2'
258 # MSO 3.3 PATCH does not return anything anymore.
259 when: version.current.version is version('3.3', '<')
260
261 # DELETE the schema
262 - name: Delete the schema
263 cisco.mso.mso_rest:
264 <<: *mso_info
265 path: "/mso/api/v1/schemas/{{ add_schema.jsondata.id }}"
266 method: delete
267 register: delete_schema
268
269 - name: Verify delete_schema in json_inline
270 ansible.builtin.assert:
271 that:
272 - delete_schema is changed
273 - delete_schema.jsondata == None
274
275 # DELETE TENANT
276 - name: Delete the tenant
277 cisco.mso.mso_rest:
278 <<: *mso_info
279 path: "/mso/api/v1/tenants/{{ add_tenant.jsondata.id }}"
280 method: delete
281 register: delete_tenant
282
283 - name: Verify delete_tenant in json_inline
284 ansible.builtin.assert:
285 that:
286 - delete_tenant is changed
287 - delete_tenant.jsondata == None