Debian Codegraph @

ansible_collections/cisco/mso/tests/integration/targets/mso_rest/tasks/json_string.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 schemas
32 cisco.mso.mso_schema:
33 <<: *mso_info
34 schema: '{{ item }}'
35 state: absent
36 loop:
37 - '{{ mso_schema | default("ansible_test") }}_2'
38 - '{{ mso_schema | default("ansible_test") }}'
39
40 - name: Remove tenant ansible_test
41 cisco.mso.mso_tenant:
42 <<: *mso_info
43 tenant: ansible_test
44 state: absent
45
46 # QUERY SCHEMAS
47 - name: Query schema
48 cisco.mso.mso_rest:
49 <<: *mso_info
50 path: /mso/api/v1/schemas
51 method: get
52 register: query_all_schema
53
54 - name: Verify query_all_schema
55 ansible.builtin.assert:
56 that:
57 - query_all_schema is not changed
58
59 # QUERY A USER
60 - name: Query our user
61 cisco.mso.mso_user:
62 <<: *mso_info
63 state: query
64 user: '{{ mso_username }}'
65 check_mode: true
66 register: query_user_id
67
68 - name: Verify query_user_id
69 ansible.builtin.assert:
70 that:
71 - query_user_id is not changed
72 - query_user_id.current.username == '{{ mso_username }}'
73
74 # ADD tenant
75 - name: Add tenant
76 cisco.mso.mso_rest:
77 <<: *mso_info
78 path: /api/v1/tenants
79 method: post
80 content:
81 {
82 "displayName": "ansible_test",
83 "name": "ansible_test",
84 "description": "",
85 "siteAssociations": [],
86 "userAssociations": [{
87 "userId": "{{ query_user_id.current.id }}"
88 }],
89 "_updateVersion": 0,
90 }
91 register: add_tenant
92
93 - name: Verify add_tenant in json_string
94 ansible.builtin.assert:
95 that:
96 - add_tenant is changed
97 - add_tenant.jsondata.displayName == 'ansible_test'
98
99 # ADD schema
100 - name: Add schema
101 cisco.mso.mso_rest:
102 <<: *mso_info
103 path: /mso/api/v1/schemas
104 method: post
105 content: |
106 {
107 "displayName": "{{ mso_schema | default('ansible_test') }}",
108 "templates": [{
109 "name": "Template_1",
110 "tenantId": "{{ add_tenant.jsondata.id }}",
111 "displayName": "Template_1",
112 "templateSubType": [],
113 "templateType": "stretched-template",
114 "anps": [],
115 "contracts": [],
116 "vrfs": [],
117 "bds": [],
118 "filters": [],
119 "externalEpgs": [],
120 "serviceGraphs": [],
121 "intersiteL3outs": []
122 }],
123 "sites": [],
124 "_updateVersion": 0
125 }
126 register: add_schema
127
128 - name: Verify add_schema in json_string
129 ansible.builtin.assert:
130 that:
131 - add_schema is changed
132 - add_schema.jsondata.displayName == 'ansible_test'
133
134 # PUT schema
135 - name: Put schema
136 cisco.mso.mso_rest:
137 <<: *mso_info
138 path: "/mso/api/v1/schemas/{{ add_schema.jsondata.id }}"
139 method: put
140 content: |
141 {
142 "displayName": "ansible_test_2",
143 "templates": [{
144 "name": "Template_1",
145 "tenantId": "{{ add_tenant.jsondata.id }}",
146 "displayName": "Template_1",
147 "templateSubType": [],
148 "templateType": "stretched-template",
149 "anps": [],
150 "contracts": [],
151 "vrfs": [],
152 "bds": [],
153 "filters": [],
154 "externalEpgs": [],
155 "serviceGraphs": [],
156 "intersiteL3outs": []
157 }],
158 "sites": [],
159 "_updateVersion": 0
160 }
161 register: put_schema
162
163 - name: Verify put_schema in json_string
164 ansible.builtin.assert:
165 that:
166 - put_schema is changed
167 - put_schema.jsondata.displayName == 'ansible_test_2'
168
169 # PATCH schema
170 - name: Patch schema
171 cisco.mso.mso_rest:
172 <<: *mso_info
173 path: "/mso/api/v1/schemas/{{ add_schema.jsondata.id }}"
174 method: patch
175 content: |
176 [
177 {
178 "op": "add",
179 "path": "/templates/Template_1/anps/-",
180 "value": { "name": "AP2", "displayName": "AP2", "epgs": [] },
181 "_updateVersion": 0
182 }
183 ]
184 register: patch_schema
185
186 - name: Verify patch_schema in json_string
187 ansible.builtin.assert:
188 that:
189 - patch_schema is changed
190
191 - name: Verify patch_schema in json_string
192 ansible.builtin.assert:
193 that:
194 - patch_schema.jsondata.templates[0].anps[0].displayName == 'AP2'
195 # MSO 3.3 PATCH does not return anything anymore.
196 when: version.current.version is version('3.3', '<')
197
198 # DELETE the schema
199 - name: Delete the schema
200 cisco.mso.mso_rest:
201 <<: *mso_info
202 path: "/mso/api/v1/schemas/{{ add_schema.jsondata.id }}"
203 method: delete
204 register: delete_schema
205
206 - name: Verify delete_schema in json_string
207 ansible.builtin.assert:
208 that:
209 - delete_schema is changed
210 - delete_schema.jsondata == None
211
212 # DELETE TENANT
213 - name: Delete the tenant
214 cisco.mso.mso_rest:
215 <<: *mso_info
216 path: "/mso/api/v1/tenants/{{ add_tenant.jsondata.id }}"
217 method: delete
218 register: delete_tenant
219
220 - name: Verify delete_tenant in json_string
221 ansible.builtin.assert:
222 that:
223 - delete_tenant is changed
224 - delete_tenant.jsondata == None