summaryrefslogtreecommitdiffstats
path: root/tests/units/anta_tests/test_snmp.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-15 20:30:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-15 20:30:44 +0000
commit4a398db99d88dd17dabc408fb2b58c610792bc1e (patch)
treee5404d6d19a4d67a9428b3d10f886717b9756352 /tests/units/anta_tests/test_snmp.py
parentAdding upstream version 1.0.0. (diff)
downloadanta-upstream.tar.xz
anta-upstream.zip
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/units/anta_tests/test_snmp.py')
-rw-r--r--tests/units/anta_tests/test_snmp.py199
1 files changed, 197 insertions, 2 deletions
diff --git a/tests/units/anta_tests/test_snmp.py b/tests/units/anta_tests/test_snmp.py
index b4d3152..e7d8da8 100644
--- a/tests/units/anta_tests/test_snmp.py
+++ b/tests/units/anta_tests/test_snmp.py
@@ -7,8 +7,16 @@ from __future__ import annotations
from typing import Any
-from anta.tests.snmp import VerifySnmpContact, VerifySnmpIPv4Acl, VerifySnmpIPv6Acl, VerifySnmpLocation, VerifySnmpStatus
-from tests.lib.anta import test # noqa: F401; pylint: disable=W0611
+from anta.tests.snmp import (
+ VerifySnmpContact,
+ VerifySnmpErrorCounters,
+ VerifySnmpIPv4Acl,
+ VerifySnmpIPv6Acl,
+ VerifySnmpLocation,
+ VerifySnmpPDUCounters,
+ VerifySnmpStatus,
+)
+from tests.units.anta_tests import test
DATA: list[dict[str, Any]] = [
{
@@ -100,6 +108,20 @@ DATA: list[dict[str, Any]] = [
},
},
{
+ "name": "failure-details-not-configured",
+ "test": VerifySnmpLocation,
+ "eos_data": [
+ {
+ "location": {"location": ""},
+ }
+ ],
+ "inputs": {"location": "New York"},
+ "expected": {
+ "result": "failure",
+ "messages": ["SNMP location is not configured."],
+ },
+ },
+ {
"name": "success",
"test": VerifySnmpContact,
"eos_data": [
@@ -124,4 +146,177 @@ DATA: list[dict[str, Any]] = [
"messages": ["Expected `Bob@example.com` as the contact, but found `Jon@example.com` instead."],
},
},
+ {
+ "name": "failure-details-not-configured",
+ "test": VerifySnmpContact,
+ "eos_data": [
+ {
+ "contact": {"contact": ""},
+ }
+ ],
+ "inputs": {"contact": "Bob@example.com"},
+ "expected": {
+ "result": "failure",
+ "messages": ["SNMP contact is not configured."],
+ },
+ },
+ {
+ "name": "success",
+ "test": VerifySnmpPDUCounters,
+ "eos_data": [
+ {
+ "counters": {
+ "inGetPdus": 3,
+ "inGetNextPdus": 2,
+ "inSetPdus": 3,
+ "outGetResponsePdus": 3,
+ "outTrapPdus": 9,
+ },
+ }
+ ],
+ "inputs": {},
+ "expected": {"result": "success"},
+ },
+ {
+ "name": "success-specific-pdus",
+ "test": VerifySnmpPDUCounters,
+ "eos_data": [
+ {
+ "counters": {
+ "inGetPdus": 3,
+ "inGetNextPdus": 0,
+ "inSetPdus": 0,
+ "outGetResponsePdus": 0,
+ "outTrapPdus": 9,
+ },
+ }
+ ],
+ "inputs": {"pdus": ["inGetPdus", "outTrapPdus"]},
+ "expected": {"result": "success"},
+ },
+ {
+ "name": "failure-counters-not-found",
+ "test": VerifySnmpPDUCounters,
+ "eos_data": [
+ {
+ "counters": {},
+ }
+ ],
+ "inputs": {},
+ "expected": {"result": "failure", "messages": ["SNMP counters not found."]},
+ },
+ {
+ "name": "failure-incorrect-counters",
+ "test": VerifySnmpPDUCounters,
+ "eos_data": [
+ {
+ "counters": {
+ "inGetPdus": 0,
+ "inGetNextPdus": 2,
+ "inSetPdus": 0,
+ "outGetResponsePdus": 3,
+ "outTrapPdus": 9,
+ },
+ }
+ ],
+ "inputs": {},
+ "expected": {
+ "result": "failure",
+ "messages": ["The following SNMP PDU counters are not found or have zero PDU counters:\n{'inGetPdus': 0, 'inSetPdus': 0}"],
+ },
+ },
+ {
+ "name": "failure-pdu-not-found",
+ "test": VerifySnmpPDUCounters,
+ "eos_data": [
+ {
+ "counters": {
+ "inGetNextPdus": 0,
+ "inSetPdus": 0,
+ "outGetResponsePdus": 0,
+ },
+ }
+ ],
+ "inputs": {"pdus": ["inGetPdus", "outTrapPdus"]},
+ "expected": {
+ "result": "failure",
+ "messages": ["The following SNMP PDU counters are not found or have zero PDU counters:\n{'inGetPdus': 'Not Found', 'outTrapPdus': 'Not Found'}"],
+ },
+ },
+ {
+ "name": "success",
+ "test": VerifySnmpErrorCounters,
+ "eos_data": [
+ {
+ "counters": {
+ "inVersionErrs": 0,
+ "inBadCommunityNames": 0,
+ "inBadCommunityUses": 0,
+ "inParseErrs": 0,
+ "outTooBigErrs": 0,
+ "outNoSuchNameErrs": 0,
+ "outBadValueErrs": 0,
+ "outGeneralErrs": 0,
+ },
+ }
+ ],
+ "inputs": {},
+ "expected": {"result": "success"},
+ },
+ {
+ "name": "success-specific-counters",
+ "test": VerifySnmpErrorCounters,
+ "eos_data": [
+ {
+ "counters": {
+ "inVersionErrs": 0,
+ "inBadCommunityNames": 0,
+ "inBadCommunityUses": 0,
+ "inParseErrs": 0,
+ "outTooBigErrs": 5,
+ "outNoSuchNameErrs": 0,
+ "outBadValueErrs": 10,
+ "outGeneralErrs": 1,
+ },
+ }
+ ],
+ "inputs": {"error_counters": ["inVersionErrs", "inParseErrs"]},
+ "expected": {"result": "success"},
+ },
+ {
+ "name": "failure-counters-not-found",
+ "test": VerifySnmpErrorCounters,
+ "eos_data": [
+ {
+ "counters": {},
+ }
+ ],
+ "inputs": {},
+ "expected": {"result": "failure", "messages": ["SNMP counters not found."]},
+ },
+ {
+ "name": "failure-incorrect-counters",
+ "test": VerifySnmpErrorCounters,
+ "eos_data": [
+ {
+ "counters": {
+ "inVersionErrs": 1,
+ "inBadCommunityNames": 0,
+ "inBadCommunityUses": 0,
+ "inParseErrs": 2,
+ "outTooBigErrs": 0,
+ "outNoSuchNameErrs": 0,
+ "outBadValueErrs": 2,
+ "outGeneralErrs": 0,
+ },
+ }
+ ],
+ "inputs": {},
+ "expected": {
+ "result": "failure",
+ "messages": [
+ "The following SNMP error counters are not found or have non-zero error counters:\n{'inVersionErrs': 1, 'inParseErrs': 2, 'outBadValueErrs': 2}"
+ ],
+ },
+ },
]