Debian Codegraph @

tests/units/anta_tests/test_snmp.py

raw symbols SCIP
1 # Copyright (c) 2023-2026 Arista Networks, Inc.
2 # Use of this source code is governed by the Apache License 2.0
3 # that can be found in the LICENSE file.
4 """Tests for anta.tests.snmp.py."""
5
6 from __future__ import annotations
7
8 import sys
9 from typing import TYPE_CHECKING, Any
10
11 from anta.models import AntaTest
12 from anta.result_manager.models import AntaTestStatus
13 from anta.tests.snmp import (
14 VerifySnmpContact,
15 VerifySnmpErrorCounters,
16 VerifySnmpGroup,
17 VerifySnmpHostLogging,
18 VerifySnmpIPv4Acl,
19 VerifySnmpIPv6Acl,
20 VerifySnmpLocation,
21 VerifySnmpNotificationHost,
22 VerifySnmpPDUCounters,
23 VerifySnmpSourceInterface,
24 VerifySnmpStatus,
25 VerifySnmpUser,
26 )
27 from tests.units.anta_tests import test
28
29 if TYPE_CHECKING:
30 from tests.units.anta_tests import AntaUnitTestData
31
32 DATA: AntaUnitTestData = {
33 (VerifySnmpStatus, "success"): {
34 "eos_data": [{"vrfs": {"snmpVrfs": ["MGMT", "default"]}, "enabled": True}],
35 "inputs": {"vrf": "MGMT"},
36 "expected": {"result": AntaTestStatus.SUCCESS},
37 },
38 (VerifySnmpStatus, "failure-wrong-vrf"): {
39 "eos_data": [{"vrfs": {"snmpVrfs": ["default"]}, "enabled": True}],
40 "inputs": {"vrf": "MGMT"},
41 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["VRF: MGMT - SNMP agent disabled"]},
42 },
43 (VerifySnmpStatus, "failure-disabled"): {
44 "eos_data": [{"vrfs": {"snmpVrfs": ["default"]}, "enabled": False}],
45 "inputs": {"vrf": "default"},
46 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["VRF: default - SNMP agent disabled"]},
47 },
48 (VerifySnmpIPv4Acl, "success"): {
49 "eos_data": [{"ipAclList": {"aclList": [{"type": "Ip4Acl", "name": "ACL_IPV4_SNMP", "configuredVrfs": ["MGMT"], "activeVrfs": ["MGMT"]}]}}],
50 "inputs": {"number": 1, "vrf": "MGMT"},
51 "expected": {"result": AntaTestStatus.SUCCESS},
52 },
53 (VerifySnmpIPv4Acl, "failure-wrong-number"): {
54 "eos_data": [{"ipAclList": {"aclList": []}}],
55 "inputs": {"number": 1, "vrf": "MGMT"},
56 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["VRF: MGMT - Incorrect SNMP IPv4 ACL(s) - Expected: 1 Actual: 0"]},
57 },
58 (VerifySnmpIPv4Acl, "failure-wrong-vrf"): {
59 "eos_data": [{"ipAclList": {"aclList": [{"type": "Ip4Acl", "name": "ACL_IPV4_SNMP", "configuredVrfs": ["default"], "activeVrfs": ["default"]}]}}],
60 "inputs": {"number": 1, "vrf": "MGMT"},
61 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["VRF: MGMT - Following SNMP IPv4 ACL(s) not configured or active: ACL_IPV4_SNMP"]},
62 },
63 (VerifySnmpIPv6Acl, "success"): {
64 "eos_data": [{"ipv6AclList": {"aclList": [{"type": "Ip6Acl", "name": "ACL_IPV6_SNMP", "configuredVrfs": ["MGMT"], "activeVrfs": ["MGMT"]}]}}],
65 "inputs": {"number": 1, "vrf": "MGMT"},
66 "expected": {"result": AntaTestStatus.SUCCESS},
67 },
68 (VerifySnmpIPv6Acl, "failure-wrong-number"): {
69 "eos_data": [{"ipv6AclList": {"aclList": []}}],
70 "inputs": {"number": 1, "vrf": "MGMT"},
71 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["VRF: MGMT - Incorrect SNMP IPv6 ACL(s) - Expected: 1 Actual: 0"]},
72 },
73 (VerifySnmpIPv6Acl, "failure-wrong-vrf"): {
74 "eos_data": [{"ipv6AclList": {"aclList": [{"type": "Ip6Acl", "name": "ACL_IPV6_SNMP", "configuredVrfs": ["default"], "activeVrfs": ["default"]}]}}],
75 "inputs": {"number": 1, "vrf": "MGMT"},
76 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["VRF: MGMT - Following SNMP IPv6 ACL(s) not configured or active: ACL_IPV6_SNMP"]},
77 },
78 (VerifySnmpLocation, "success"): {
79 "eos_data": [{"location": {"location": "New York"}}],
80 "inputs": {"location": "New York"},
81 "expected": {"result": AntaTestStatus.SUCCESS},
82 },
83 (VerifySnmpLocation, "failure-incorrect-location"): {
84 "eos_data": [{"location": {"location": "Europe"}}],
85 "inputs": {"location": "New York"},
86 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Incorrect SNMP location - Expected: New York Actual: Europe"]},
87 },
88 (VerifySnmpLocation, "failure-details-not-configured"): {
89 "eos_data": [{"location": {"location": ""}}],
90 "inputs": {"location": "New York"},
91 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["SNMP location is not configured"]},
92 },
93 (VerifySnmpContact, "success"): {
94 "eos_data": [{"contact": {"contact": "[email protected]"}}],
95 "inputs": {"contact": "[email protected]"},
96 "expected": {"result": AntaTestStatus.SUCCESS},
97 },
98 (VerifySnmpContact, "failure-incorrect-contact"): {
99 "eos_data": [{"contact": {"contact": "[email protected]"}}],
100 "inputs": {"contact": "[email protected]"},
101 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Incorrect SNMP contact - Expected: [email protected] Actual: [email protected]"]},
102 },
103 (VerifySnmpContact, "failure-details-not-configured"): {
104 "eos_data": [{"contact": {"contact": ""}}],
105 "inputs": {"contact": "[email protected]"},
106 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["SNMP contact is not configured"]},
107 },
108 (VerifySnmpPDUCounters, "success"): {
109 "eos_data": [{"counters": {"inGetPdus": 3, "inGetNextPdus": 2, "inSetPdus": 3, "outGetResponsePdus": 3, "outTrapPdus": 9}}],
110 "inputs": {},
111 "expected": {"result": AntaTestStatus.SUCCESS},
112 },
113 (VerifySnmpPDUCounters, "success-specific-pdus"): {
114 "eos_data": [{"counters": {"inGetPdus": 3, "inGetNextPdus": 0, "inSetPdus": 0, "outGetResponsePdus": 0, "outTrapPdus": 9}}],
115 "inputs": {"pdus": ["inGetPdus", "outTrapPdus"]},
116 "expected": {"result": AntaTestStatus.SUCCESS},
117 },
118 (VerifySnmpPDUCounters, "failure-counters-not-found"): {
119 "eos_data": [{"counters": {}}],
120 "inputs": {},
121 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["SNMP counters not found"]},
122 },
123 (VerifySnmpPDUCounters, "failure-incorrect-counters"): {
124 "eos_data": [{"counters": {"inGetPdus": 0, "inGetNextPdus": 2, "inSetPdus": 0, "outGetResponsePdus": 3, "outTrapPdus": 9}}],
125 "inputs": {},
126 "expected": {
127 "result": AntaTestStatus.FAILURE,
128 "messages": ["The following SNMP PDU counters are not found or have zero PDU counters: inGetPdus, inSetPdus"],
129 },
130 },
131 (VerifySnmpPDUCounters, "failure-pdu-not-found"): {
132 "eos_data": [{"counters": {"inGetNextPdus": 0, "inSetPdus": 0, "outGetResponsePdus": 0}}],
133 "inputs": {"pdus": ["inGetPdus", "outTrapPdus"]},
134 "expected": {
135 "result": AntaTestStatus.FAILURE,
136 "messages": ["The following SNMP PDU counters are not found or have zero PDU counters: inGetPdus, outTrapPdus"],
137 },
138 },
139 (VerifySnmpErrorCounters, "success"): {
140 "eos_data": [
141 {
142 "counters": {
143 "inVersionErrs": 0,
144 "inBadCommunityNames": 0,
145 "inBadCommunityUses": 0,
146 "inParseErrs": 0,
147 "outTooBigErrs": 0,
148 "outNoSuchNameErrs": 0,
149 "outBadValueErrs": 0,
150 "outGeneralErrs": 0,
151 }
152 }
153 ],
154 "inputs": {},
155 "expected": {"result": AntaTestStatus.SUCCESS},
156 },
157 (VerifySnmpErrorCounters, "success-specific-counters"): {
158 "eos_data": [
159 {
160 "counters": {
161 "inVersionErrs": 0,
162 "inBadCommunityNames": 0,
163 "inBadCommunityUses": 0,
164 "inParseErrs": 0,
165 "outTooBigErrs": 5,
166 "outNoSuchNameErrs": 0,
167 "outBadValueErrs": 10,
168 "outGeneralErrs": 1,
169 }
170 }
171 ],
172 "inputs": {"error_counters": ["inVersionErrs", "inParseErrs"]},
173 "expected": {"result": AntaTestStatus.SUCCESS},
174 },
175 (VerifySnmpErrorCounters, "failure-counters-not-found"): {
176 "eos_data": [{"counters": {}}],
177 "inputs": {},
178 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["SNMP counters not found"]},
179 },
180 (VerifySnmpErrorCounters, "failure-incorrect-counters"): {
181 "eos_data": [
182 {
183 "counters": {
184 "inVersionErrs": 1,
185 "inBadCommunityNames": 0,
186 "inBadCommunityUses": 0,
187 "inParseErrs": 2,
188 "outTooBigErrs": 0,
189 "outNoSuchNameErrs": 0,
190 "outBadValueErrs": 2,
191 "outGeneralErrs": 0,
192 }
193 }
194 ],
195 "inputs": {},
196 "expected": {
197 "result": AntaTestStatus.FAILURE,
198 "messages": ["The following SNMP error counters are not found or have non-zero error counters: inParseErrs, inVersionErrs, outBadValueErrs"],
199 },
200 },
201 (VerifySnmpHostLogging, "success"): {
202 "eos_data": [
203 {
204 "logging": {
205 "loggingEnabled": True,
206 "hosts": {
207 "192.168.1.100": {"port": 162, "vrf": ""},
208 "192.168.1.101": {"port": 162, "vrf": "MGMT"},
209 "snmp-server-01": {"port": 162, "vrf": "default"},
210 },
211 }
212 }
213 ],
214 "inputs": {
215 "hosts": [
216 {"hostname": "192.168.1.100", "vrf": "default"},
217 {"hostname": "192.168.1.101", "vrf": "MGMT"},
218 {"hostname": "snmp-server-01", "vrf": "default"},
219 ]
220 },
221 "expected": {"result": AntaTestStatus.SUCCESS},
222 },
223 (VerifySnmpHostLogging, "failure-logging-disabled"): {
224 "eos_data": [{"logging": {"loggingEnabled": False}}],
225 "inputs": {"hosts": [{"hostname": "192.168.1.100", "vrf": "default"}, {"hostname": "192.168.1.101", "vrf": "MGMT"}]},
226 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["SNMP logging is disabled"]},
227 },
228 (VerifySnmpHostLogging, "failure-mismatch-vrf"): {
229 "eos_data": [{"logging": {"loggingEnabled": True, "hosts": {"192.168.1.100": {"port": 162, "vrf": "MGMT"}, "192.168.1.101": {"port": 162, "vrf": "Test"}}}}],
230 "inputs": {"hosts": [{"hostname": "192.168.1.100", "vrf": "default"}, {"hostname": "192.168.1.101", "vrf": "MGMT"}]},
231 "expected": {
232 "result": AntaTestStatus.FAILURE,
233 "messages": ["Host: 192.168.1.100 VRF: default - Incorrect VRF - Actual: MGMT", "Host: 192.168.1.101 VRF: MGMT - Incorrect VRF - Actual: Test"],
234 },
235 },
236 (VerifySnmpHostLogging, "failure-host-not-configured"): {
237 "eos_data": [{"logging": {"loggingEnabled": True, "hosts": {"192.168.1.100": {"port": 162, "vrf": "MGMT"}, "192.168.1.103": {"port": 162, "vrf": "Test"}}}}],
238 "inputs": {"hosts": [{"hostname": "192.168.1.101", "vrf": "default"}, {"hostname": "192.168.1.102", "vrf": "MGMT"}]},
239 "expected": {
240 "result": AntaTestStatus.FAILURE,
241 "messages": ["Host: 192.168.1.101 VRF: default - Not configured", "Host: 192.168.1.102 VRF: MGMT - Not configured"],
242 },
243 },
244 (VerifySnmpUser, "success"): {
245 "eos_data": [
246 {
247 "usersByVersion": {
248 "v1": {"users": {"Test1": {"groupName": "TestGroup1"}}},
249 "v2c": {"users": {"Test2": {"groupName": "TestGroup2"}}},
250 "v3": {
251 "users": {
252 "Test3": {"groupName": "TestGroup3", "v3Params": {"authType": "SHA-384", "privType": "AES-128"}},
253 "Test4": {"groupName": "TestGroup3", "v3Params": {"authType": "SHA-512", "privType": "AES-192"}},
254 }
255 },
256 }
257 }
258 ],
259 "inputs": {
260 "snmp_users": [
261 {"username": "Test1", "group_name": "TestGroup1", "version": "v1"},
262 {"username": "Test2", "group_name": "TestGroup2", "version": "v2c"},
263 {"username": "Test3", "group_name": "TestGroup3", "version": "v3", "auth_type": "SHA-384", "priv_type": "AES-128"},
264 {"username": "Test4", "group_name": "TestGroup3", "version": "v3", "auth_type": "SHA-512", "priv_type": "AES-192"},
265 ]
266 },
267 "expected": {"result": AntaTestStatus.SUCCESS},
268 },
269 (VerifySnmpUser, "failure-not-configured"): {
270 "eos_data": [{"usersByVersion": {"v3": {"users": {"Test3": {"groupName": "TestGroup3", "v3Params": {"authType": "SHA-384", "privType": "AES-128"}}}}}}],
271 "inputs": {
272 "snmp_users": [
273 {"username": "Test1", "group_name": "TestGroup1", "version": "v1"},
274 {"username": "Test2", "group_name": "TestGroup2", "version": "v2c"},
275 {"username": "Test3", "group_name": "TestGroup3", "version": "v3", "auth_type": "SHA-384", "priv_type": "AES-128"},
276 {"username": "Test4", "group_name": "TestGroup3", "version": "v3", "auth_type": "SHA-512", "priv_type": "AES-192"},
277 ]
278 },
279 "expected": {
280 "result": AntaTestStatus.FAILURE,
281 "messages": [
282 "User: Test1 Group: TestGroup1 Version: v1 - Not found",
283 "User: Test2 Group: TestGroup2 Version: v2c - Not found",
284 "User: Test4 Group: TestGroup3 Version: v3 - Not found",
285 ],
286 },
287 },
288 (VerifySnmpUser, "failure-incorrect-group"): {
289 "eos_data": [
290 {"usersByVersion": {"v1": {"users": {"Test1": {"groupName": "TestGroup2"}}}, "v2c": {"users": {"Test2": {"groupName": "TestGroup1"}}}, "v3": {}}}
291 ],
292 "inputs": {
293 "snmp_users": [{"username": "Test1", "group_name": "TestGroup1", "version": "v1"}, {"username": "Test2", "group_name": "TestGroup2", "version": "v2c"}]
294 },
295 "expected": {
296 "result": AntaTestStatus.FAILURE,
297 "messages": [
298 "User: Test1 Group: TestGroup1 Version: v1 - Incorrect user group - Actual: TestGroup2",
299 "User: Test2 Group: TestGroup2 Version: v2c - Incorrect user group - Actual: TestGroup1",
300 ],
301 },
302 },
303 (VerifySnmpUser, "failure-incorrect-auth-encryption"): {
304 "eos_data": [
305 {
306 "usersByVersion": {
307 "v1": {"users": {"Test1": {"groupName": "TestGroup1"}}},
308 "v2c": {"users": {"Test2": {"groupName": "TestGroup2"}}},
309 "v3": {
310 "users": {
311 "Test3": {"groupName": "TestGroup3", "v3Params": {"authType": "SHA-512", "privType": "AES-192"}},
312 "Test4": {"groupName": "TestGroup4", "v3Params": {"authType": "SHA-384", "privType": "AES-128"}},
313 }
314 },
315 }
316 }
317 ],
318 "inputs": {
319 "snmp_users": [
320 {"username": "Test1", "group_name": "TestGroup1", "version": "v1"},
321 {"username": "Test2", "group_name": "TestGroup2", "version": "v2c"},
322 {"username": "Test3", "group_name": "TestGroup3", "version": "v3", "auth_type": "SHA-384", "priv_type": "AES-128"},
323 {"username": "Test4", "group_name": "TestGroup4", "version": "v3", "auth_type": "SHA-512", "priv_type": "AES-192"},
324 ]
325 },
326 "expected": {
327 "result": AntaTestStatus.FAILURE,
328 "messages": [
329 "User: Test3 Group: TestGroup3 Version: v3 - Incorrect authentication type - Expected: SHA-384 Actual: SHA-512",
330 "User: Test3 Group: TestGroup3 Version: v3 - Incorrect privacy type - Expected: AES-128 Actual: AES-192",
331 "User: Test4 Group: TestGroup4 Version: v3 - Incorrect authentication type - Expected: SHA-512 Actual: SHA-384",
332 "User: Test4 Group: TestGroup4 Version: v3 - Incorrect privacy type - Expected: AES-192 Actual: AES-128",
333 ],
334 },
335 },
336 (VerifySnmpNotificationHost, "success"): {
337 "eos_data": [
338 {
339 "hosts": [
340 {
341 "hostname": "192.168.1.100",
342 "port": 162,
343 "vrf": "",
344 "notificationType": "trap",
345 "protocolVersion": "v3",
346 "v3Params": {"user": "public", "securityLevel": "authNoPriv"},
347 },
348 {
349 "hostname": "192.168.1.101",
350 "port": 162,
351 "vrf": "MGMT",
352 "notificationType": "trap",
353 "protocolVersion": "v2c",
354 "v1v2cParams": {"communityString": "public"},
355 },
356 ]
357 }
358 ],
359 "inputs": {
360 "notification_hosts": [
361 {"hostname": "192.168.1.100", "vrf": "default", "notification_type": "trap", "version": "v3", "udp_port": 162, "user": "public"},
362 {"hostname": "192.168.1.101", "vrf": "MGMT", "notification_type": "trap", "version": "v2c", "udp_port": 162, "community_string": "public"},
363 ]
364 },
365 "expected": {"result": AntaTestStatus.SUCCESS},
366 },
367 (VerifySnmpNotificationHost, "failure-not-configured"): {
368 "eos_data": [{"hosts": []}],
369 "inputs": {
370 "notification_hosts": [
371 {"hostname": "192.168.1.100", "vrf": "default", "notification_type": "trap", "version": "v3", "udp_port": 162, "user": "public"},
372 {"hostname": "192.168.1.101", "vrf": "default", "notification_type": "trap", "version": "v2c", "udp_port": 162, "community_string": "public"},
373 ]
374 },
375 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["No SNMP host is configured"]},
376 },
377 (VerifySnmpNotificationHost, "failure-details-host-not-found"): {
378 "eos_data": [
379 {
380 "hosts": [
381 {
382 "hostname": "192.168.1.100",
383 "port": 162,
384 "vrf": "",
385 "notificationType": "trap",
386 "protocolVersion": "v3",
387 "v3Params": {"user": "public", "securityLevel": "authNoPriv"},
388 }
389 ]
390 }
391 ],
392 "inputs": {
393 "notification_hosts": [
394 {"hostname": "192.168.1.100", "vrf": "default", "notification_type": "trap", "version": "v3", "udp_port": 162, "user": "public"},
395 {"hostname": "192.168.1.101", "vrf": "default", "notification_type": "trap", "version": "v2c", "udp_port": 162, "community_string": "public"},
396 ]
397 },
398 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Host: 192.168.1.101 VRF: default Version: v2c - Not configured"]},
399 },
400 (VerifySnmpNotificationHost, "failure-incorrect-notification-type"): {
401 "eos_data": [
402 {
403 "hosts": [
404 {
405 "hostname": "192.168.1.100",
406 "port": 162,
407 "vrf": "",
408 "notificationType": "trap",
409 "protocolVersion": "v3",
410 "v3Params": {"user": "public", "securityLevel": "authNoPriv"},
411 },
412 {
413 "hostname": "192.168.1.101",
414 "port": 162,
415 "vrf": "",
416 "notificationType": "inform",
417 "protocolVersion": "v2c",
418 "v1v2cParams": {"communityString": "public"},
419 },
420 ]
421 }
422 ],
423 "inputs": {
424 "notification_hosts": [
425 {"hostname": "192.168.1.100", "vrf": "default", "notification_type": "inform", "version": "v3", "udp_port": 162, "user": "public"},
426 {"hostname": "192.168.1.101", "vrf": "default", "notification_type": "trap", "version": "v2c", "udp_port": 162, "community_string": "public"},
427 ]
428 },
429 "expected": {
430 "result": AntaTestStatus.FAILURE,
431 "messages": [
432 "Host: 192.168.1.100 VRF: default - Incorrect notification type - Expected: inform Actual: trap",
433 "Host: 192.168.1.101 VRF: default - Incorrect notification type - Expected: trap Actual: inform",
434 ],
435 },
436 },
437 (VerifySnmpNotificationHost, "failure-incorrect-udp-port"): {
438 "eos_data": [
439 {
440 "hosts": [
441 {
442 "hostname": "192.168.1.100",
443 "port": 163,
444 "vrf": "",
445 "notificationType": "trap",
446 "protocolVersion": "v3",
447 "v3Params": {"user": "public", "securityLevel": "authNoPriv"},
448 },
449 {
450 "hostname": "192.168.1.101",
451 "port": 164,
452 "vrf": "",
453 "notificationType": "trap",
454 "protocolVersion": "v2c",
455 "v1v2cParams": {"communityString": "public"},
456 },
457 ]
458 }
459 ],
460 "inputs": {
461 "notification_hosts": [
462 {"hostname": "192.168.1.100", "vrf": "default", "notification_type": "trap", "version": "v3", "udp_port": 162, "user": "public"},
463 {"hostname": "192.168.1.101", "vrf": "default", "notification_type": "trap", "version": "v2c", "udp_port": 162, "community_string": "public"},
464 ]
465 },
466 "expected": {
467 "result": AntaTestStatus.FAILURE,
468 "messages": [
469 "Host: 192.168.1.100 VRF: default - Incorrect UDP port - Expected: 162 Actual: 163",
470 "Host: 192.168.1.101 VRF: default - Incorrect UDP port - Expected: 162 Actual: 164",
471 ],
472 },
473 },
474 (VerifySnmpNotificationHost, "failure-incorrect-community-string-version-v1-v2c"): {
475 "eos_data": [
476 {
477 "hosts": [
478 {
479 "hostname": "192.168.1.100",
480 "port": 162,
481 "vrf": "",
482 "notificationType": "trap",
483 "protocolVersion": "v1",
484 "v1v2cParams": {"communityString": "private"},
485 },
486 {
487 "hostname": "192.168.1.101",
488 "port": 162,
489 "vrf": "",
490 "notificationType": "trap",
491 "protocolVersion": "v2c",
492 "v1v2cParams": {"communityString": "private"},
493 },
494 ]
495 }
496 ],
497 "inputs": {
498 "notification_hosts": [
499 {"hostname": "192.168.1.100", "vrf": "default", "notification_type": "trap", "version": "v1", "udp_port": 162, "community_string": "public"},
500 {"hostname": "192.168.1.101", "vrf": "default", "notification_type": "trap", "version": "v2c", "udp_port": 162, "community_string": "public"},
501 ]
502 },
503 "expected": {
504 "result": AntaTestStatus.FAILURE,
505 "messages": [
506 "Host: 192.168.1.100 VRF: default Version: v1 - Incorrect community string - Expected: public Actual: private",
507 "Host: 192.168.1.101 VRF: default Version: v2c - Incorrect community string - Expected: public Actual: private",
508 ],
509 },
510 },
511 (VerifySnmpNotificationHost, "failure-incorrect-user-for-version-v3"): {
512 "eos_data": [
513 {
514 "hosts": [
515 {
516 "hostname": "192.168.1.100",
517 "port": 162,
518 "vrf": "",
519 "notificationType": "trap",
520 "protocolVersion": "v3",
521 "v3Params": {"user": "private", "securityLevel": "authNoPriv"},
522 }
523 ]
524 }
525 ],
526 "inputs": {
527 "notification_hosts": [{"hostname": "192.168.1.100", "vrf": "default", "notification_type": "trap", "version": "v3", "udp_port": 162, "user": "public"}]
528 },
529 "expected": {
530 "result": AntaTestStatus.FAILURE,
531 "messages": ["Host: 192.168.1.100 VRF: default Version: v3 - Incorrect user - Expected: public Actual: private"],
532 },
533 },
534 (VerifySnmpSourceInterface, "success"): {
535 "eos_data": [{"srcIntf": {"sourceInterfaces": {"default": "Ethernet1", "MGMT": "Management0"}}}],
536 "inputs": {"interfaces": [{"interface": "Ethernet1", "vrf": "default"}, {"interface": "Management0", "vrf": "MGMT"}]},
537 "expected": {"result": AntaTestStatus.SUCCESS},
538 },
539 (VerifySnmpSourceInterface, "failure-not-configured"): {
540 "eos_data": [{"srcIntf": {}}],
541 "inputs": {"interfaces": [{"interface": "Ethernet1", "vrf": "default"}, {"interface": "Management0", "vrf": "MGMT"}]},
542 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["SNMP source interface(s) not configured"]},
543 },
544 (VerifySnmpSourceInterface, "failure-incorrect-interfaces"): {
545 "eos_data": [{"srcIntf": {"sourceInterfaces": {"default": "Management0"}}}],
546 "inputs": {"interfaces": [{"interface": "Ethernet1", "vrf": "default"}, {"interface": "Management0", "vrf": "MGMT"}]},
547 "expected": {
548 "result": AntaTestStatus.FAILURE,
549 "messages": [
550 "Source Interface: Ethernet1 VRF: default - Incorrect source interface - Actual: Management0",
551 "Source Interface: Management0 VRF: MGMT - Not configured",
552 ],
553 },
554 },
555 (VerifySnmpGroup, "success"): {
556 "eos_data": [
557 {
558 "groups": {
559 "Group1": {
560 "versions": {
561 "v1": {
562 "secModel": "v1",
563 "readView": "group_read_1",
564 "readViewConfig": True,
565 "writeView": "group_write_1",
566 "writeViewConfig": True,
567 "notifyView": "group_notify_1",
568 "notifyViewConfig": True,
569 }
570 }
571 },
572 "Group2": {
573 "versions": {
574 "v2c": {
575 "secModel": "v2c",
576 "readView": "group_read_2",
577 "readViewConfig": True,
578 "writeView": "group_write_2",
579 "writeViewConfig": True,
580 "notifyView": "group_notify_2",
581 "notifyViewConfig": True,
582 }
583 }
584 },
585 "Group3": {
586 "versions": {
587 "v3": {
588 "secModel": "v3Auth",
589 "readView": "group_read_3",
590 "readViewConfig": True,
591 "writeView": "group_write_3",
592 "writeViewConfig": True,
593 "notifyView": "group_notify_3",
594 "notifyViewConfig": True,
595 }
596 }
597 },
598 }
599 }
600 ],
601 "inputs": {
602 "snmp_groups": [
603 {"group_name": "Group1", "version": "v1", "read_view": "group_read_1", "write_view": "group_write_1", "notify_view": "group_notify_1"},
604 {"group_name": "Group2", "version": "v2c", "read_view": "group_read_2", "write_view": "group_write_2", "notify_view": "group_notify_2"},
605 {
606 "group_name": "Group3",
607 "version": "v3",
608 "read_view": "group_read_3",
609 "write_view": "group_write_3",
610 "notify_view": "group_notify_3",
611 "authentication": "auth",
612 },
613 ]
614 },
615 "expected": {"result": AntaTestStatus.SUCCESS},
616 },
617 (VerifySnmpGroup, "failure-incorrect-view"): {
618 "eos_data": [
619 {
620 "groups": {
621 "Group1": {
622 "versions": {
623 "v1": {
624 "secModel": "v1",
625 "readView": "group_read",
626 "readViewConfig": True,
627 "writeView": "group_write",
628 "writeViewConfig": True,
629 "notifyView": "group_notify",
630 "notifyViewConfig": True,
631 }
632 }
633 },
634 "Group2": {
635 "versions": {
636 "v2c": {
637 "secModel": "v2c",
638 "readView": "group_read",
639 "readViewConfig": True,
640 "writeView": "group_write",
641 "writeViewConfig": True,
642 "notifyView": "group_notify",
643 "notifyViewConfig": True,
644 }
645 }
646 },
647 "Group3": {
648 "versions": {
649 "v3": {
650 "secModel": "v3NoAuth",
651 "readView": "group_read",
652 "readViewConfig": True,
653 "writeView": "group_write",
654 "writeViewConfig": True,
655 "notifyView": "group_notify",
656 "notifyViewConfig": True,
657 }
658 }
659 },
660 }
661 }
662 ],
663 "inputs": {
664 "snmp_groups": [
665 {"group_name": "Group1", "version": "v1", "read_view": "group_read_1", "write_view": "group_write_1", "notify_view": "group_notify_1"},
666 {"group_name": "Group2", "version": "v2c", "read_view": "group_read_2", "notify_view": "group_notify_2"},
667 {
668 "group_name": "Group3",
669 "version": "v3",
670 "read_view": "group_read_3",
671 "write_view": "group_write_3",
672 "notify_view": "group_notify_3",
673 "authentication": "noauth",
674 },
675 ]
676 },
677 "expected": {
678 "result": AntaTestStatus.FAILURE,
679 "messages": [
680 "Group: Group1 Version: v1 - Incorrect Read view - Expected: group_read_1 Actual: group_read",
681 "Group: Group1 Version: v1 - Incorrect Write view - Expected: group_write_1 Actual: group_write",
682 "Group: Group1 Version: v1 - Incorrect Notify view - Expected: group_notify_1 Actual: group_notify",
683 "Group: Group2 Version: v2c - Incorrect Read view - Expected: group_read_2 Actual: group_read",
684 "Group: Group2 Version: v2c - Incorrect Notify view - Expected: group_notify_2 Actual: group_notify",
685 "Group: Group3 Version: v3 - Incorrect Read view - Expected: group_read_3 Actual: group_read",
686 "Group: Group3 Version: v3 - Incorrect Write view - Expected: group_write_3 Actual: group_write",
687 "Group: Group3 Version: v3 - Incorrect Notify view - Expected: group_notify_3 Actual: group_notify",
688 ],
689 },
690 },
691 (VerifySnmpGroup, "failure-view-config-not-found"): {
692 "eos_data": [
693 {
694 "groups": {
695 "Group1": {
696 "versions": {
697 "v1": {
698 "secModel": "v1",
699 "readView": "group_read",
700 "readViewConfig": False,
701 "writeView": "group_write",
702 "writeViewConfig": False,
703 "notifyView": "group_notify",
704 "notifyViewConfig": False,
705 }
706 }
707 },
708 "Group2": {
709 "versions": {
710 "v2c": {
711 "secModel": "v2c",
712 "readView": "group_read",
713 "readViewConfig": False,
714 "writeView": "group_write",
715 "writeViewConfig": False,
716 "notifyView": "group_notify",
717 "notifyViewConfig": False,
718 }
719 }
720 },
721 "Group3": {
722 "versions": {
723 "v3": {
724 "secModel": "v3Priv",
725 "readView": "group_read",
726 "readViewConfig": False,
727 "writeView": "group_write",
728 "writeViewConfig": False,
729 "notifyView": "group_notify",
730 "notifyViewConfig": False,
731 }
732 }
733 },
734 }
735 }
736 ],
737 "inputs": {
738 "snmp_groups": [
739 {"group_name": "Group1", "version": "v1", "read_view": "group_read", "write_view": "group_write", "notify_view": "group_notify"},
740 {"group_name": "Group2", "version": "v2c", "read_view": "group_read", "write_view": "group_write", "notify_view": "group_notify"},
741 {"group_name": "Group3", "version": "v3", "write_view": "group_write", "notify_view": "group_notify", "authentication": "priv"},
742 ]
743 },
744 "expected": {
745 "result": AntaTestStatus.FAILURE,
746 "messages": [
747 "Group: Group1 Version: v1 Read View: group_read - Not configured",
748 "Group: Group1 Version: v1 Write View: group_write - Not configured",
749 "Group: Group1 Version: v1 Notify View: group_notify - Not configured",
750 "Group: Group2 Version: v2c Read View: group_read - Not configured",
751 "Group: Group2 Version: v2c Write View: group_write - Not configured",
752 "Group: Group2 Version: v2c Notify View: group_notify - Not configured",
753 "Group: Group3 Version: v3 Write View: group_write - Not configured",
754 "Group: Group3 Version: v3 Notify View: group_notify - Not configured",
755 ],
756 },
757 },
758 (VerifySnmpGroup, "failure-group-version-not-configured"): {
759 "eos_data": [{"groups": {"Group1": {"versions": {"v1": {}}}, "Group2": {"versions": {"v2c": {}}}, "Group3": {"versions": {"v3": {}}}}}],
760 "inputs": {
761 "snmp_groups": [
762 {"group_name": "Group1", "version": "v1", "read_view": "group_read_1", "write_view": "group_write_1"},
763 {"group_name": "Group2", "version": "v2c", "read_view": "group_read_2", "write_view": "group_write_2", "notify_view": "group_notify_2"},
764 {
765 "group_name": "Group3",
766 "version": "v3",
767 "read_view": "group_read_3",
768 "write_view": "group_write_3",
769 "notify_view": "group_notify_3",
770 "authentication": "auth",
771 },
772 ]
773 },
774 "expected": {
775 "result": AntaTestStatus.FAILURE,
776 "messages": ["Group: Group1 Version: v1 - Not configured", "Group: Group2 Version: v2c - Not configured", "Group: Group3 Version: v3 - Not configured"],
777 },
778 },
779 (VerifySnmpGroup, "failure-incorrect-v3-auth-model"): {
780 "eos_data": [
781 {
782 "groups": {
783 "Group3": {
784 "versions": {
785 "v3": {
786 "secModel": "v3Auth",
787 "readView": "group_read",
788 "readViewConfig": True,
789 "writeView": "group_write",
790 "writeViewConfig": True,
791 "notifyView": "group_notify",
792 "notifyViewConfig": True,
793 }
794 }
795 }
796 }
797 }
798 ],
799 "inputs": {
800 "snmp_groups": [
801 {
802 "group_name": "Group3",
803 "version": "v3",
804 "read_view": "group_read",
805 "write_view": "group_write",
806 "notify_view": "group_notify",
807 "authentication": "priv",
808 }
809 ]
810 },
811 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Group: Group3 Version: v3 - Incorrect security model - Expected: v3Priv Actual: v3Auth"]},
812 },
813 (VerifySnmpGroup, "failure-view-not-configured"): {
814 "eos_data": [
815 {
816 "groups": {
817 "Group3": {"versions": {"v3": {"secModel": "v3NoAuth", "readView": "group_read", "readViewConfig": True, "writeView": "", "notifyView": ""}}}
818 }
819 }
820 ],
821 "inputs": {"snmp_groups": [{"group_name": "Group3", "version": "v3", "read_view": "group_read", "write_view": "group_write", "authentication": "noauth"}]},
822 "expected": {"result": AntaTestStatus.FAILURE, "messages": ["Group: Group3 Version: v3 View: write - Not configured"]},
823 },
824 }