Debian Codegraph @

ansible_collections/cisco/mso/tests/integration/targets/ndo_macsec_policy/tasks/main.yml

raw symbols SCIP
1 # Test code for the MSO modules
2 # Copyright: (c) 2024, Anvitha Jain (@anvjain) <[email protected]>
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 - name: Test that we have an ACI MultiSite host, username and password
7 ansible.builtin.fail:
8 msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.'
9 when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
10
11 # CLEAN ENVIRONMENT
12 - name: Set vars
13 ansible.builtin.set_fact:
14 mso_info: &mso_info
15 host: '{{ mso_hostname }}'
16 username: '{{ mso_username }}'
17 password: '{{ mso_password }}'
18 validate_certs: '{{ mso_validate_certs | default(false) }}'
19 use_ssl: '{{ mso_use_ssl | default(true) }}'
20 use_proxy: '{{ mso_use_proxy | default(true) }}'
21 output_level: '{{ mso_output_level | default("debug") }}'
22
23 # QUERY VERSION
24 - name: Query MSO version
25 cisco.mso.mso_version:
26 <<: *mso_info
27 state: query
28 register: version
29
30
31 - name: Execute tasks only for MSO version >= 4.3
32 when: version.current.version is version('4.3', '>=')
33 block:
34 - name: Remove fabric template
35 cisco.mso.ndo_template: &template_absent
36 <<: *mso_info
37 name: ansible_fabric_policy_template
38 type: fabric_policy
39 state: absent
40
41 - name: Create a fabric template
42 cisco.mso.ndo_template:
43 <<: *template_absent
44 state: present
45
46 # CREATE
47
48 # MACsec policy interface_type fabric
49 - name: Create a MACsec policy of interface_type 'fabric' (check mode)
50 cisco.mso.ndo_macsec_policy: &add_macsec_policy
51 <<: *mso_info
52 template: ansible_fabric_policy_template
53 macsec_policy: ansible_macsec_policy
54 state: present
55 check_mode: true
56 register: cm_add_macsec_policy
57
58 - name: Create a MACsec policy of interface_type 'fabric'
59 cisco.mso.ndo_macsec_policy:
60 <<: *add_macsec_policy
61 register: nm_add_macsec_policy
62
63 - name: Create MACsec policy again
64 cisco.mso.ndo_macsec_policy:
65 <<: *add_macsec_policy
66 register: nm_add_macsec_policy_again
67
68 - name: Assert that the MACsec policy was created
69 assert:
70 that:
71 - cm_add_macsec_policy is changed
72 - cm_add_macsec_policy.previous == nm_add_macsec_policy.previous == {}
73 - cm_add_macsec_policy.current.name == cm_add_macsec_policy.proposed.name == 'ansible_macsec_policy'
74 - cm_add_macsec_policy.current.type == cm_add_macsec_policy.proposed.type == 'fabric'
75 - nm_add_macsec_policy is changed
76 - nm_add_macsec_policy.current.name == 'ansible_macsec_policy'
77 - nm_add_macsec_policy.current.type == 'fabric'
78 - nm_add_macsec_policy.current.description == ''
79 - nm_add_macsec_policy.current.adminState == 'enabled'
80 - nm_add_macsec_policy.current.macsecParams.cipherSuite == '256GcmAesXpn'
81 - nm_add_macsec_policy.current.macsecParams.sakExpiryTime == 0
82 - nm_add_macsec_policy.current.macsecParams.securityPol == 'shouldSecure'
83 - nm_add_macsec_policy.current.macsecParams.windowSize == 0
84 - nm_add_macsec_policy.current.uuid is defined
85 - nm_add_macsec_policy_again is not changed
86 - nm_add_macsec_policy_again.previous.name == nm_add_macsec_policy_again.current.name == 'ansible_macsec_policy'
87 - nm_add_macsec_policy_again.previous.type == nm_add_macsec_policy_again.current.type == 'fabric'
88 - nm_add_macsec_policy_again.previous.description == nm_add_macsec_policy_again.current.description == ''
89 - nm_add_macsec_policy_again.previous.uuid is defined
90 - nm_add_macsec_policy_again.current.uuid is defined
91 - nm_add_macsec_policy_again.previous.macsecParams.cipherSuite == nm_add_macsec_policy_again.current.macsecParams.cipherSuite == '256GcmAesXpn'
92 - nm_add_macsec_policy_again.previous.macsecParams.sakExpiryTime == nm_add_macsec_policy_again.current.macsecParams.sakExpiryTime == 0
93 - nm_add_macsec_policy_again.previous.macsecParams.securityPol == nm_add_macsec_policy_again.current.macsecParams.securityPol == 'shouldSecure'
94 - nm_add_macsec_policy_again.previous.macsecParams.windowSize == nm_add_macsec_policy_again.current.macsecParams.windowSize == 0
95
96 # MACsec policy interface_type access
97 - name: Create a MACsec policy of interface_type 'access'
98 cisco.mso.ndo_macsec_policy: &add_macsec_policy_access
99 <<: *mso_info
100 template: ansible_fabric_policy_template
101 macsec_policy: ansible_macsec_policy_access
102 interface_type: access
103 state: present
104 register: add_macsec_policy_access
105
106 - name: Assert that the MACsec policy was created
107 assert:
108 that:
109 - add_macsec_policy_access is changed
110 - add_macsec_policy_access.previous == {}
111 - add_macsec_policy_access.current.name == 'ansible_macsec_policy_access'
112 - add_macsec_policy_access.current.type == 'access'
113 - add_macsec_policy_access.current.description == ''
114 - add_macsec_policy_access.current.adminState == 'enabled'
115 - add_macsec_policy_access.current.macsecParams.cipherSuite == '256GcmAesXpn'
116 - add_macsec_policy_access.current.macsecParams.sakExpiryTime == 0
117 - add_macsec_policy_access.current.macsecParams.securityPol == 'shouldSecure'
118 - add_macsec_policy_access.current.macsecParams.windowSize == 64
119 - add_macsec_policy_access.current.macsecParams.confOffSet == 'offset0'
120 - add_macsec_policy_access.current.macsecParams.keyServerPrio == 16
121 - add_macsec_policy_access.current.uuid is defined
122
123 # UPDATE
124
125 # Only one macsec_keys can be added during creation
126 - name: Create another MACsec policy of interface_type 'access'
127 cisco.mso.ndo_macsec_policy: &add_macsec_policy_2
128 <<: *mso_info
129 template: ansible_fabric_policy_template
130 macsec_policy: ansible_macsec_policy_2
131 description: 'Ansible MACsec Policy description'
132 admin_state: 'enabled'
133 cipher_suite: '256_gcm_aes'
134 window_size: 105
135 security_policy: 'should_secure'
136 sak_expiry_time: 99
137 confidentiality_offset: 50
138 key_server_priority: 11
139 interface_type: access
140 macsec_keys:
141 - key_name: abc12
142 psk: 'AA111111111111111111111111111111111111111111111111111111111111aa'
143 start_time: '2029-12-11 11:12:13'
144 end_time: '2030-12-11 11:12:13'
145 - key_name: ABC
146 psk: 'AAabcdabcdabcdabcdabcdabcdabcdab11111111111111111111111111111aaa'
147 state: present
148 register: nm_add_macsec_policy_2
149
150 - name: Update the MACsec policy of interface_type 'access' (check mode)
151 cisco.mso.ndo_macsec_policy: &update_macsec_policy
152 <<: *add_macsec_policy_2
153 description: 'Updated description'
154 admin_state: 'disabled'
155 cipher_suite: '128_gcm_aes'
156 window_size: 110
157 security_policy: 'must_secure'
158 sak_expiry_time: 100
159 confidentiality_offset: 30
160 key_server_priority: 10
161 macsec_keys:
162 - key_name: abc12
163 psk: 'AAabcdabcdabcdabcdabcdabcdabcdab'
164 start_time: '2029-12-11 11:12:13'
165 - key_name: ABC
166 psk: 'AAabcdabcdabcdabcdabcdabcdabcdab'
167 - key_name: aaa11
168 psk: 'AAabcdabcdabcdabcdabcdabcdabcdab'
169 start_time: '2025-10-10 10:12:13'
170 end_time: '2026-10-10 10:12:13'
171 state: present
172 check_mode: true
173 register: cm_update_macsec_policy
174
175 - name: Update the MACsec policy of interface_type 'access'
176 cisco.mso.ndo_macsec_policy:
177 <<: *update_macsec_policy
178 register: nm_update_macsec_policy
179
180 # Idempotence for update cannot be checked as the psk is encrypted and the encrypted value changes every time
181 - name: Update MACsec policy of interface_type 'access' again
182 cisco.mso.ndo_macsec_policy:
183 <<: *update_macsec_policy
184 register: nm_update_macsec_policy_again
185
186 - name: Assert that the MACsec policy was updated
187 assert:
188 that:
189 - cm_update_macsec_policy is changed
190 - cm_update_macsec_policy.previous.description == 'Ansible MACsec Policy description'
191 - cm_update_macsec_policy.previous.adminState == 'enabled'
192 - cm_update_macsec_policy.previous.macsecParams.cipherSuite == '256GcmAes'
193 - cm_update_macsec_policy.previous.macsecParams.windowSize == 105
194 - cm_update_macsec_policy.previous.macsecParams.securityPol == 'shouldSecure'
195 - cm_update_macsec_policy.previous.macsecParams.sakExpiryTime == 99
196 - cm_update_macsec_policy.previous.macsecParams.confOffSet == 'offset50'
197 - cm_update_macsec_policy.previous.macsecParams.keyServerPrio == 11
198 - cm_update_macsec_policy.current.description == cm_update_macsec_policy.proposed.description == 'Updated description'
199 - cm_update_macsec_policy.current.adminState == cm_update_macsec_policy.proposed.adminState == 'disabled'
200 - cm_update_macsec_policy.current.macsecParams.cipherSuite == cm_update_macsec_policy.proposed.macsecParams.cipherSuite == '128GcmAes'
201 - cm_update_macsec_policy.current.macsecParams.windowSize == cm_update_macsec_policy.proposed.macsecParams.windowSize == 110
202 - cm_update_macsec_policy.current.macsecParams.securityPol == cm_update_macsec_policy.proposed.macsecParams.securityPol == 'mustSecure'
203 - cm_update_macsec_policy.current.macsecParams.sakExpiryTime == cm_update_macsec_policy.proposed.macsecParams.sakExpiryTime == 100
204 - cm_update_macsec_policy.current.macsecParams.confOffSet == cm_update_macsec_policy.proposed.macsecParams.confOffSet == 'offset30'
205 - cm_update_macsec_policy.current.macsecParams.keyServerPrio == cm_update_macsec_policy.proposed.macsecParams.keyServerPrio == 10
206 - nm_update_macsec_policy is changed
207 - nm_update_macsec_policy.previous.description == 'Ansible MACsec Policy description'
208 - nm_update_macsec_policy.previous.adminState == 'enabled'
209 - nm_update_macsec_policy.previous.macsecParams.cipherSuite == '256GcmAes'
210 - nm_update_macsec_policy.previous.macsecParams.windowSize == 105
211 - nm_update_macsec_policy.previous.macsecParams.securityPol == 'shouldSecure'
212 - nm_update_macsec_policy.previous.macsecParams.sakExpiryTime == 99
213 - nm_update_macsec_policy.previous.macsecParams.confOffSet == 'offset50'
214 - nm_update_macsec_policy.previous.macsecParams.keyServerPrio == 11
215 - nm_update_macsec_policy.previous.macsecKeys | length == 2
216 - nm_update_macsec_policy.current.description =='Updated description'
217 - nm_update_macsec_policy.current.adminState == 'disabled'
218 - nm_update_macsec_policy.current.macsecParams.cipherSuite == '128GcmAes'
219 - nm_update_macsec_policy.current.macsecParams.windowSize == 110
220 - nm_update_macsec_policy.current.macsecParams.securityPol == 'mustSecure'
221 - nm_update_macsec_policy.current.macsecParams.sakExpiryTime == 100
222 - nm_update_macsec_policy.current.macsecParams.confOffSet == 'offset30'
223 - nm_update_macsec_policy.current.macsecParams.keyServerPrio == 10
224 - nm_update_macsec_policy.current.macsecKeys | length == 3
225 - nm_update_macsec_policy.current.uuid is defined
226 - nm_update_macsec_policy_again is changed
227 - nm_update_macsec_policy_again.previous.name == cm_update_macsec_policy.current.name == nm_update_macsec_policy.current.name == 'ansible_macsec_policy_2'
228 - nm_update_macsec_policy_again.previous.type == cm_update_macsec_policy.current.type == nm_update_macsec_policy.current.type == 'access'
229 - nm_update_macsec_policy_again.previous.description == cm_update_macsec_policy.current.description == nm_update_macsec_policy.current.description == 'Updated description'
230 - nm_update_macsec_policy_again.current.uuid is defined
231 - nm_update_macsec_policy_again.previous.uuid is defined
232
233 - name: Update the MACsec policy name
234 cisco.mso.ndo_macsec_policy:
235 <<: *mso_info
236 template: ansible_fabric_policy_template
237 macsec_policy_uuid: '{{ nm_add_macsec_policy_again.current.uuid }}'
238 macsec_policy: ansible_macsec_policy_changed
239 state: present
240 register: nm_update_macsec_policy_uuid
241
242 - name: Assert that the MACsec policy name was updated
243 assert:
244 that:
245 - nm_update_macsec_policy_uuid is changed
246 - nm_update_macsec_policy_uuid.previous.name == 'ansible_macsec_policy'
247 - nm_update_macsec_policy_uuid.current.name == 'ansible_macsec_policy_changed'
248 - nm_update_macsec_policy_uuid.current.type == nm_update_macsec_policy_uuid.current.type == 'fabric'
249 - nm_update_macsec_policy_uuid.current.description == nm_update_macsec_policy_uuid.current.description == ''
250 - nm_update_macsec_policy_uuid.current.adminState == nm_update_macsec_policy_uuid.current.adminState == 'enabled'
251 - nm_update_macsec_policy_uuid.current.macsecParams.cipherSuite == nm_update_macsec_policy_uuid.current.macsecParams.cipherSuite == '256GcmAesXpn'
252 - nm_update_macsec_policy_uuid.current.macsecParams.sakExpiryTime == nm_update_macsec_policy_uuid.current.macsecParams.sakExpiryTime == 0
253 - nm_update_macsec_policy_uuid.current.macsecParams.securityPol == nm_update_macsec_policy_uuid.current.macsecParams.securityPol == 'shouldSecure'
254 - nm_update_macsec_policy_uuid.current.macsecParams.windowSize == nm_update_macsec_policy_uuid.current.macsecParams.windowSize == 0
255 - nm_update_macsec_policy_uuid.previous.uuid == nm_update_macsec_policy_uuid.current.uuid
256 - nm_update_macsec_policy_uuid.current.uuid is defined
257
258 - name: Update the MACsec policy by removing the macsec_keys
259 cisco.mso.ndo_macsec_policy:
260 <<: *update_macsec_policy
261 macsec_keys: []
262 state: present
263 register: rm_update_macsec_policy_key
264
265 - name: Assert that the MACsec policy was updated by removing the macsec_keys
266 assert:
267 that:
268 - rm_update_macsec_policy_key is changed
269 - rm_update_macsec_policy_key.previous.macsecKeys | length == 3
270 - rm_update_macsec_policy_key.current.macsecKeys is not defined
271
272 # QUERY
273 - name: Query a MACsec policy with name
274 cisco.mso.ndo_macsec_policy:
275 <<: *mso_info
276 template: ansible_fabric_policy_template
277 macsec_policy: ansible_macsec_policy_changed
278 state: query
279 register: query_one
280
281 - name: Query all MACsec policies in a template
282 cisco.mso.ndo_macsec_policy:
283 <<: *mso_info
284 template: ansible_fabric_policy_template
285 state: query
286 register: query_all
287
288 - name: Assert that the MACsec policy was queried
289 assert:
290 that:
291 - query_one is not changed
292 - query_one.current.name == 'ansible_macsec_policy_changed'
293 - query_one.current.type == 'fabric'
294 - query_one.current.description == ''
295 - query_all is not changed
296 - query_all.current | length >= 2
297
298 - name: Query a MACsec policy with UUID
299 cisco.mso.ndo_macsec_policy:
300 <<: *mso_info
301 template: ansible_fabric_policy_template
302 macsec_policy_uuid: '{{ nm_update_macsec_policy_uuid.current.uuid }}'
303 state: query
304 register: query_uuid
305
306 - name: Assert that the MACsec policy was queried with macsec_policy UUID
307 assert:
308 that:
309 - query_uuid is not changed
310 - query_uuid.current.name == 'ansible_macsec_policy_changed'
311 - query_uuid.current.type == 'fabric'
312 - query_uuid.current.description == ''
313
314 # ERROR
315 - name: Update the interface_type of exisiting MACsec policy
316 cisco.mso.ndo_macsec_policy:
317 <<: *mso_info
318 template: ansible_fabric_policy_template
319 macsec_policy: ansible_macsec_policy_changed
320 interface_type: access
321 state: present
322 ignore_errors: true
323 register: nm_update_macsec_policy_type
324
325 - name: Assert that the MACsec policy interface_type cannot be updated
326 assert:
327 that:
328 - nm_update_macsec_policy_type is failed
329 - nm_update_macsec_policy_type.msg == 'Type cannot be changed for an existing MACsec Policy.'
330
331 - name: Validate MACsec policy with invalide time format
332 cisco.mso.ndo_macsec_policy:
333 <<: *mso_info
334 template: ansible_fabric_policy_template
335 macsec_policy: ansible_macsec_policy_2
336 description: 'Ansible MACsec Policy description'
337 interface_type: access
338 macsec_keys:
339 - key_name: abc12
340 psk: 'AA111111111111111111111111111111111111111111111111111111111111aa'
341 start_time: 'wrong-time 11:12:13'
342 end_time: '2030-12-11 11:12:13'
343 state: present
344 ignore_errors: true
345 register: validate_invalid_time
346
347 - name: Set error message for invalid time
348 ansible.builtin.set_fact:
349 error_message_invalid_time: "ERROR: The time must be in 'YYYY-MM-DD HH:MM:SS' format."
350
351 - name: Assert that the MACsec policy interface_type cannot be updated
352 assert:
353 that:
354 - validate_invalid_time is failed
355 - validate_invalid_time.msg == error_message_invalid_time
356
357 # DELETE
358 - name: Delete a MACsec policy with name (check mode)
359 cisco.mso.ndo_macsec_policy: &delete_macsec_policy
360 <<: *mso_info
361 template: ansible_fabric_policy_template
362 macsec_policy: ansible_macsec_policy_2
363 state: absent
364 check_mode: true
365 register: cm_delete_macsec_policy
366
367 - name: Delete a MACsec policy with name
368 cisco.mso.ndo_macsec_policy:
369 <<: *delete_macsec_policy
370 register: nm_delete_macsec_policy
371
372 - name: Delete a MACsec policy with name again
373 cisco.mso.ndo_macsec_policy:
374 <<: *delete_macsec_policy
375 register: nm_delete_macsec_policy_again
376
377 - name: Assert that the MACsec policy was deleted
378 assert:
379 that:
380 - cm_delete_macsec_policy is changed
381 - nm_delete_macsec_policy is changed
382 - nm_delete_macsec_policy_again is not changed
383 - nm_delete_macsec_policy.previous.name == 'ansible_macsec_policy_2'
384 - nm_delete_macsec_policy.current == {}
385 - nm_delete_macsec_policy_again.current == nm_delete_macsec_policy_again.previous == {}
386
387 - name: Delete a MACsec policy with UUID
388 cisco.mso.ndo_macsec_policy:
389 <<: *mso_info
390 template: ansible_fabric_policy_template
391 macsec_policy_uuid: '{{ nm_update_macsec_policy_uuid.current.uuid }}'
392 state: absent
393 register: delete_macsec_policy_uuid
394
395 - name: Assert that the MACsec policy was deleted using UUID
396 assert:
397 that:
398 - delete_macsec_policy_uuid is changed
399 - delete_macsec_policy_uuid.previous.name == 'ansible_macsec_policy_changed'
400 - delete_macsec_policy_uuid.current == {}
401
402 # CLEANUP
403 - name: Remove fabric template
404 cisco.mso.ndo_template:
405 <<: *template_absent