Debian Codegraph @

ansible_collections/cisco/intersight/tests/integration/targets/intersight_snmp_policy/tasks/tests.yml

raw symbols SCIP
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 organization: "{{ organization }}"
11
12 - name: Make sure Env is clean
13 cisco.intersight.intersight_snmp_policy:
14 <<: *api_info
15 name: "{{ item }}"
16 state: absent
17 loop:
18 - test_snmp_policy_disabled
19 - test_snmp_policy_v2_only
20 - test_snmp_policy_v3_only
21 - test_snmp_policy_mixed
22 - test_snmp_policy_with_users
23 - test_snmp_policy_with_traps
24 - test_validation_fail
25 - test_validation_success
26
27 - name: Create disabled SNMP policy - check-mode
28 cisco.intersight.intersight_snmp_policy:
29 <<: *api_info
30 name: test_snmp_policy_disabled
31 description: "Test disabled SNMP policy"
32 enabled: false
33 tags:
34 - Key: Site
35 Value: Test
36 check_mode: true
37 register: disabled_creation_check_mode
38
39 - name: Verify disabled SNMP policy was not created - check-mode
40 ansible.builtin.assert:
41 that:
42 - disabled_creation_check_mode is changed
43 - disabled_creation_check_mode.api_response == {}
44
45 - name: Create disabled SNMP policy
46 cisco.intersight.intersight_snmp_policy:
47 <<: *api_info
48 name: test_snmp_policy_disabled
49 description: "Test disabled SNMP policy"
50 enabled: false
51 tags:
52 - Key: Site
53 Value: Test
54 register: disabled_creation
55
56 - name: Fetch info after disabled SNMP policy creation
57 cisco.intersight.intersight_snmp_policy_info:
58 <<: *api_info
59 name: test_snmp_policy_disabled
60 register: disabled_info
61
62 - name: Verify disabled SNMP policy creation
63 ansible.builtin.assert:
64 that:
65 - disabled_creation.changed
66 - disabled_info.api_response[0].Name == 'test_snmp_policy_disabled'
67 - disabled_info.api_response[0].Enabled == false
68
69 - name: Create disabled SNMP policy (idempotency check)
70 cisco.intersight.intersight_snmp_policy:
71 <<: *api_info
72 name: test_snmp_policy_disabled
73 description: "Test disabled SNMP policy"
74 enabled: false
75 tags:
76 - Key: Site
77 Value: Test
78 register: disabled_creation_ide
79
80 - name: Verify disabled SNMP policy creation (idempotency check)
81 ansible.builtin.assert:
82 that:
83 - not disabled_creation_ide.changed
84
85 - name: Create SNMPv2 only SNMP policy
86 cisco.intersight.intersight_snmp_policy:
87 <<: *api_info
88 name: test_snmp_policy_v2_only
89 description: "Test SNMPv2 only policy"
90 enabled: true
91 v2c_enabled: true
92 v3_enabled: false
93 snmp_port: 161
94 sys_contact: "[email protected]"
95 sys_location: "Test Location"
96 community_access: "Limited"
97 access_community_string: "public"
98 trap_community: "trapcomm"
99 register: v2_only_creation
100
101 - name: Fetch info after SNMPv2 only policy creation
102 cisco.intersight.intersight_snmp_policy_info:
103 <<: *api_info
104 name: test_snmp_policy_v2_only
105 register: v2_only_info
106
107 - name: Verify SNMPv2 only policy creation
108 ansible.builtin.assert:
109 that:
110 - v2_only_creation.changed
111 - v2_only_info.api_response[0].Name == 'test_snmp_policy_v2_only'
112 - v2_only_info.api_response[0].Enabled == true
113 - v2_only_info.api_response[0].V2Enabled == true
114 - v2_only_info.api_response[0].V3Enabled == false
115 - v2_only_info.api_response[0].CommunityAccess == "Limited"
116 - v2_only_info.api_response[0].AccessCommunityString == "public"
117 - v2_only_info.api_response[0].TrapCommunity == "trapcomm"
118
119 - name: Create SNMPv3 only SNMP policy
120 cisco.intersight.intersight_snmp_policy:
121 <<: *api_info
122 name: test_snmp_policy_v3_only
123 description: "Test SNMPv3 only policy"
124 enabled: true
125 v2c_enabled: false
126 v3_enabled: true
127 snmp_port: 162
128 sys_contact: "[email protected]"
129 sys_location: "Test Location"
130 community_access: "Disabled"
131 engine_input_id: "test-engine-id"
132 snmp_users:
133 - name: "testuser"
134 security_level: "AuthPriv"
135 auth_password: "testauth123"
136 privacy_password: "testpriv123"
137 register: v3_only_creation
138
139 - name: Fetch info after SNMPv3 only policy creation
140 cisco.intersight.intersight_snmp_policy_info:
141 <<: *api_info
142 name: test_snmp_policy_v3_only
143 register: v3_only_info
144
145 - name: Verify SNMPv3 only policy creation
146 ansible.builtin.assert:
147 that:
148 - v3_only_creation.changed
149 - v3_only_info.api_response[0].Name == 'test_snmp_policy_v3_only'
150 - v3_only_info.api_response[0].Enabled == true
151 - v3_only_info.api_response[0].V2Enabled == false
152 - v3_only_info.api_response[0].V3Enabled == true
153 - v3_only_info.api_response[0].CommunityAccess == "Disabled"
154 - v3_only_info.api_response[0].EngineId == "test-engine-id"
155 - v3_only_info.api_response[0].SnmpUsers | length == 1
156 - v3_only_info.api_response[0].SnmpUsers[0].Name == "testuser"
157 - v3_only_info.api_response[0].SnmpUsers[0].SecurityLevel == "AuthPriv"
158 - v3_only_info.api_response[0].SnmpUsers[0].AuthType == "SHA"
159 - v3_only_info.api_response[0].SnmpUsers[0].PrivacyType == "AES"
160
161 - name: Create mixed SNMP policy
162 cisco.intersight.intersight_snmp_policy:
163 <<: *api_info
164 name: test_snmp_policy_mixed
165 description: "Test mixed SNMPv2 and SNMPv3 policy"
166 enabled: true
167 v2c_enabled: true
168 v3_enabled: true
169 snmp_port: 161
170 sys_contact: "[email protected]"
171 sys_location: "Test Location"
172 community_access: "Full"
173 access_community_string: "public"
174 trap_community: "trapcomm"
175 engine_input_id: "mixed-engine-id"
176 snmp_users:
177 - name: "mixeduser"
178 security_level: "AuthNoPriv"
179 auth_password: "mixedauth123"
180 register: mixed_creation
181
182 - name: Fetch info after mixed policy creation
183 cisco.intersight.intersight_snmp_policy_info:
184 <<: *api_info
185 name: test_snmp_policy_mixed
186 register: mixed_info
187
188 - name: Verify mixed policy creation
189 ansible.builtin.assert:
190 that:
191 - mixed_creation.changed
192 - mixed_info.api_response[0].Name == 'test_snmp_policy_mixed'
193 - mixed_info.api_response[0].Enabled == true
194 - mixed_info.api_response[0].V2Enabled == true
195 - mixed_info.api_response[0].V3Enabled == true
196 - mixed_info.api_response[0].CommunityAccess == "Full"
197 - mixed_info.api_response[0].AccessCommunityString == "public"
198 - mixed_info.api_response[0].TrapCommunity == "trapcomm"
199 - mixed_info.api_response[0].EngineId == "mixed-engine-id"
200 - mixed_info.api_response[0].SnmpUsers | length == 1
201 - mixed_info.api_response[0].SnmpUsers[0].Name == "mixeduser"
202 - mixed_info.api_response[0].SnmpUsers[0].SecurityLevel == "AuthNoPriv"
203 - mixed_info.api_response[0].SnmpUsers[0].AuthType == "SHA"
204
205 - name: Create SNMP policy with multiple users
206 cisco.intersight.intersight_snmp_policy:
207 <<: *api_info
208 name: test_snmp_policy_with_users
209 description: "Test SNMP policy with multiple users"
210 enabled: true
211 v2c_enabled: false
212 v3_enabled: true
213 snmp_port: 161
214 sys_contact: "[email protected]"
215 sys_location: "Test Location"
216 community_access: "Disabled"
217 engine_input_id: "users-engine-id"
218 snmp_users:
219 - name: "admin"
220 security_level: "AuthPriv"
221 auth_password: "adminauth123"
222 privacy_password: "adminpriv123"
223 - name: "readonly"
224 security_level: "AuthNoPriv"
225 auth_password: "readonlyauth123"
226 register: users_creation
227
228 - name: Fetch info after users policy creation
229 cisco.intersight.intersight_snmp_policy_info:
230 <<: *api_info
231 name: test_snmp_policy_with_users
232 register: users_info
233
234 - name: Verify users policy creation
235 ansible.builtin.assert:
236 that:
237 - users_creation.changed
238 - users_info.api_response[0].Name == 'test_snmp_policy_with_users'
239 - users_info.api_response[0].SnmpUsers | length == 2
240 - users_info.api_response[0].SnmpUsers[0].Name == "admin"
241 - users_info.api_response[0].SnmpUsers[0].SecurityLevel == "AuthPriv"
242 - users_info.api_response[0].SnmpUsers[0].AuthType == "SHA"
243 - users_info.api_response[0].SnmpUsers[0].PrivacyType == "AES"
244 - users_info.api_response[0].SnmpUsers[1].Name == "readonly"
245 - users_info.api_response[0].SnmpUsers[1].SecurityLevel == "AuthNoPriv"
246 - users_info.api_response[0].SnmpUsers[1].AuthType == "SHA"
247
248 - name: Create SNMP policy with traps
249 cisco.intersight.intersight_snmp_policy:
250 <<: *api_info
251 name: test_snmp_policy_with_traps
252 description: "Test SNMP policy with traps"
253 enabled: true
254 v2c_enabled: true
255 v3_enabled: true
256 snmp_port: 161
257 sys_contact: "[email protected]"
258 sys_location: "Test Location"
259 community_access: "Full"
260 access_community_string: "public"
261 trap_community: "trapcomm"
262 engine_input_id: "traps-engine-id"
263 snmp_users:
264 - name: "trapuser"
265 security_level: "AuthPriv"
266 auth_password: "trapauth123"
267 privacy_password: "trappriv123"
268 snmp_traps:
269 - enabled: true
270 version: "V2"
271 community: "trapcomm"
272 type: "Trap"
273 destination: "192.168.1.100"
274 port: 162
275 - enabled: true
276 version: "V2"
277 community: "trapcomm"
278 type: "Inform"
279 destination: "192.168.1.101"
280 port: 162
281 - enabled: true
282 version: "V3"
283 user: "trapuser"
284 type: "Trap"
285 destination: "192.168.1.102"
286 port: 163
287 - enabled: false
288 version: "V2"
289 community: "trapcomm"
290 type: "Trap"
291 destination: "192.168.1.103"
292 port: 162
293 register: traps_creation
294
295 - name: Fetch info after traps policy creation
296 cisco.intersight.intersight_snmp_policy_info:
297 <<: *api_info
298 name: test_snmp_policy_with_traps
299 register: traps_info
300
301 - name: Verify traps policy creation
302 ansible.builtin.assert:
303 that:
304 - traps_creation.changed
305 - traps_info.api_response[0].Name == 'test_snmp_policy_with_traps'
306 - traps_info.api_response[0].SnmpTraps | length == 4
307 - traps_info.api_response[0].SnmpTraps[0].Enabled == true
308 - traps_info.api_response[0].SnmpTraps[0].Version == "V2"
309 - traps_info.api_response[0].SnmpTraps[0].Community == "trapcomm"
310 - traps_info.api_response[0].SnmpTraps[0].Type == "Trap"
311 - traps_info.api_response[0].SnmpTraps[0].Destination == "192.168.1.100"
312 - traps_info.api_response[0].SnmpTraps[1].Type == "Inform"
313 - traps_info.api_response[0].SnmpTraps[2].Version == "V3"
314 - traps_info.api_response[0].SnmpTraps[2].User == "trapuser"
315 - traps_info.api_response[0].SnmpTraps[2].Type == "Trap"
316 - traps_info.api_response[0].SnmpTraps[3].Enabled == false
317
318 - name: Modify existing SNMP policy
319 cisco.intersight.intersight_snmp_policy:
320 <<: *api_info
321 name: test_snmp_policy_disabled
322 description: "Modified disabled SNMP policy"
323 enabled: true
324 v2c_enabled: true
325 v3_enabled: false
326 snmp_port: 161
327 sys_contact: "[email protected]"
328 sys_location: "Modified Location"
329 community_access: "Limited"
330 access_community_string: "modified"
331 register: modified_policy
332
333 - name: Fetch info after policy modification
334 cisco.intersight.intersight_snmp_policy_info:
335 <<: *api_info
336 name: test_snmp_policy_disabled
337 register: modified_info
338
339 - name: Verify policy modification
340 ansible.builtin.assert:
341 that:
342 - modified_policy.changed
343 - modified_info.api_response[0].Name == 'test_snmp_policy_disabled'
344 - modified_info.api_response[0].Enabled == true
345 - modified_info.api_response[0].V2Enabled == true
346 - modified_info.api_response[0].SysContact == "[email protected]"
347 - modified_info.api_response[0].SysLocation == "Modified Location"
348 - modified_info.api_response[0].AccessCommunityString == "modified"
349
350 - name: Fetch all SNMP policies under selected organization
351 cisco.intersight.intersight_snmp_policy_info:
352 <<: *api_info
353 register: all_policies_info
354
355 - name: Check that there are SNMP policies under this organization
356 ansible.builtin.assert:
357 that:
358 - all_policies_info.api_response | length >= 5
359
360 - name: Test validation - Both v2c and v3 disabled (should fail)
361 cisco.intersight.intersight_snmp_policy:
362 <<: *api_info
363 name: test_validation_fail
364 enabled: true
365 v2c_enabled: false
366 v3_enabled: false
367 sys_contact: "[email protected]"
368 sys_location: "Test Location"
369 register: validation_fail_1
370 failed_when:
371 - "'At least one of v2c_enabled or v3_enabled must be true when SNMP is enabled' not in validation_fail_1.msg"
372 - not validation_fail_1.failed
373
374 - name: Test validation - Missing sys_contact (should fail)
375 cisco.intersight.intersight_snmp_policy:
376 <<: *api_info
377 name: test_validation_fail
378 enabled: true
379 v2c_enabled: true
380 v3_enabled: true
381 sys_location: "Test Location"
382 register: validation_fail_2
383 failed_when:
384 - "'sys_contact and sys_location are required when SNMP is enabled' not in validation_fail_2.msg"
385 - not validation_fail_2.failed
386
387 - name: Test validation - Missing sys_location (should fail)
388 cisco.intersight.intersight_snmp_policy:
389 <<: *api_info
390 name: test_validation_fail
391 enabled: true
392 v2c_enabled: true
393 v3_enabled: true
394 sys_contact: "[email protected]"
395 register: validation_fail_3
396 failed_when:
397 - "'sys_contact and sys_location are required when SNMP is enabled' not in validation_fail_3.msg"
398 - not validation_fail_3.failed
399
400 - name: Test validation - SNMP users without v3_enabled (should fail)
401 cisco.intersight.intersight_snmp_policy:
402 <<: *api_info
403 name: test_validation_fail
404 enabled: true
405 v2c_enabled: true
406 v3_enabled: false
407 sys_contact: "[email protected]"
408 sys_location: "Test Location"
409 snmp_users:
410 - name: "testuser"
411 security_level: "AuthNoPriv"
412 auth_password: "testauth123"
413 register: validation_fail_4
414 failed_when:
415 - "'snmp_users cannot be specified when v3_enabled is false' not in validation_fail_4.msg"
416 - not validation_fail_4.failed
417
418 - name: Test validation - V3-only with non-disabled community access (should fail)
419 cisco.intersight.intersight_snmp_policy:
420 <<: *api_info
421 name: test_validation_fail
422 enabled: true
423 v2c_enabled: false
424 v3_enabled: true
425 sys_contact: "[email protected]"
426 sys_location: "Test Location"
427 community_access: "Full"
428 register: validation_fail_5
429 failed_when:
430 - "'community_access must be' not in validation_fail_5.msg"
431 - "'Disabled' not in validation_fail_5.msg"
432 - not validation_fail_5.failed
433
434 - name: Test validation - AuthPriv user missing privacy_password (should fail)
435 cisco.intersight.intersight_snmp_policy:
436 <<: *api_info
437 name: test_validation_fail
438 enabled: true
439 v2c_enabled: true
440 v3_enabled: true
441 sys_contact: "[email protected]"
442 sys_location: "Test Location"
443 snmp_users:
444 - name: "testuser"
445 security_level: "AuthPriv"
446 auth_password: "testauth123"
447 register: validation_fail_6
448 failed_when:
449 - "'privacy_password is required for security_level' not in validation_fail_6.msg"
450 - not validation_fail_6.failed
451
452 - name: Test validation - V2 trap without v2c_enabled (should fail)
453 cisco.intersight.intersight_snmp_policy:
454 <<: *api_info
455 name: test_validation_fail
456 enabled: true
457 v2c_enabled: false
458 v3_enabled: true
459 sys_contact: "[email protected]"
460 sys_location: "Test Location"
461 snmp_traps:
462 - enabled: true
463 version: "V2"
464 type: "Trap"
465 destination: "192.168.1.100"
466 port: 162
467 register: validation_fail_7
468 failed_when:
469 - "'V2' not in validation_fail_7.msg"
470 - "'v2c_enabled is false' not in validation_fail_7.msg"
471 - not validation_fail_7.failed
472
473 - name: Test validation - V3 trap without v3_enabled (should fail)
474 cisco.intersight.intersight_snmp_policy:
475 <<: *api_info
476 name: test_validation_fail
477 enabled: true
478 v2c_enabled: true
479 v3_enabled: false
480 sys_contact: "[email protected]"
481 sys_location: "Test Location"
482 snmp_traps:
483 - enabled: true
484 version: "V3"
485 user: "testuser"
486 type: "Trap"
487 destination: "192.168.1.100"
488 port: 162
489 register: validation_fail_8
490 failed_when:
491 - "'V3' not in validation_fail_8.msg"
492 - "'v3_enabled is false' not in validation_fail_8.msg"
493 - not validation_fail_8.failed
494
495 - name: Test validation - V2 trap missing community (should fail)
496 cisco.intersight.intersight_snmp_policy:
497 <<: *api_info
498 name: test_validation_fail
499 enabled: true
500 v2c_enabled: true
501 v3_enabled: true
502 sys_contact: "[email protected]"
503 sys_location: "Test Location"
504 snmp_traps:
505 - enabled: true
506 version: "V2"
507 type: "Trap"
508 destination: "192.168.1.100"
509 port: 162
510 register: validation_fail_9
511 failed_when:
512 - "'community is required for SNMP trap version' not in validation_fail_9.msg"
513 - not validation_fail_9.failed
514
515 - name: Test validation - V3 trap missing user (should fail)
516 cisco.intersight.intersight_snmp_policy:
517 <<: *api_info
518 name: test_validation_fail
519 enabled: true
520 v2c_enabled: true
521 v3_enabled: true
522 sys_contact: "[email protected]"
523 sys_location: "Test Location"
524 snmp_traps:
525 - enabled: true
526 version: "V3"
527 type: "Trap"
528 destination: "192.168.1.100"
529 port: 162
530 register: validation_fail_10
531 failed_when:
532 - "'user is required for SNMP trap version' not in validation_fail_10.msg"
533 - not validation_fail_10.failed
534
535 - name: Test validation - V3 trap with Inform type (should fail)
536 cisco.intersight.intersight_snmp_policy:
537 <<: *api_info
538 name: test_validation_fail
539 enabled: true
540 v2c_enabled: true
541 v3_enabled: true
542 sys_contact: "[email protected]"
543 sys_location: "Test Location"
544 snmp_users:
545 - name: "testuser"
546 security_level: "AuthPriv"
547 auth_password: "testauth123"
548 privacy_password: "testpriv123"
549 snmp_traps:
550 - enabled: true
551 version: "V3"
552 user: "testuser"
553 type: "Inform"
554 destination: "192.168.1.100"
555 port: 162
556 register: validation_fail_11
557 failed_when:
558 - "'V3' not in validation_fail_11.msg"
559 - "'Inform' not in validation_fail_11.msg"
560 - "'Trap' not in validation_fail_11.msg"
561 - not validation_fail_11.failed
562
563 - name: Test validation - Valid mixed SNMPv2 and SNMPv3 configuration (should succeed)
564 cisco.intersight.intersight_snmp_policy:
565 <<: *api_info
566 name: test_validation_success
567 enabled: true
568 v2c_enabled: true
569 v3_enabled: true
570 sys_contact: "[email protected]"
571 sys_location: "Test Location"
572 community_access: "Full"
573 access_community_string: "public"
574 trap_community: "trapcomm"
575 engine_input_id: "mixed-validation-id"
576 snmp_users:
577 - name: "validuser"
578 security_level: "AuthPriv"
579 auth_password: "validauth123"
580 privacy_password: "validpriv123"
581 snmp_traps:
582 - enabled: true
583 version: "V2"
584 community: "trapcomm"
585 type: "Inform"
586 destination: "192.168.1.100"
587 port: 162
588 - enabled: true
589 version: "V3"
590 user: "validuser"
591 type: "Trap"
592 destination: "192.168.1.101"
593 port: 162
594 register: validation_success_1
595
596 - name: Verify validation success for mixed configuration
597 ansible.builtin.assert:
598 that:
599 - validation_success_1.changed
600 - not validation_success_1.failed
601
602 always:
603 - name: Remove all test SNMP policies
604 cisco.intersight.intersight_snmp_policy:
605 <<: *api_info
606 name: "{{ item }}"
607 state: absent
608 loop:
609 - test_snmp_policy_disabled
610 - test_snmp_policy_v2_only
611 - test_snmp_policy_v3_only
612 - test_snmp_policy_mixed
613 - test_snmp_policy_with_users
614 - test_snmp_policy_with_traps
615 - test_validation_fail
616 - test_validation_success