From a15cc3ddb945a214159c1d3d3179390f481ef7eb Mon Sep 17 00:00:00 2001 From: Carl Baillargeon Date: Mon, 20 Jan 2025 19:36:22 -0500 Subject: [PATCH] Minor fixes --- anta/input_models/snmp.py | 8 ++++---- anta/tests/snmp.py | 16 +++++++++------- examples/tests.yaml | 2 +- tests/units/anta_tests/test_snmp.py | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/anta/input_models/snmp.py b/anta/input_models/snmp.py index cd21220d2..d408d9311 100644 --- a/anta/input_models/snmp.py +++ b/anta/input_models/snmp.py @@ -60,15 +60,15 @@ class SnmpSourceInterface(BaseModel): """Model for a SNMP source-interface.""" interface: Interface - """Source-interface to use as source IP address of log messages.""" + """Interface to use as the source IP address of SNMP messages.""" vrf: str = "default" - """The VRF name to verify the SNMP agent in. Defaults to `default`.""" + """VRF of the source interface.""" def __str__(self) -> str: """Return a human-readable string representation of the SnmpSourceInterface for reporting. Examples -------- - - VRF: default, Source Interface: Ethernet1 + - Source Interface: Ethernet1 VRF: default """ - return f"VRF: {self.vrf}, Source Interface: {self.interface}" + return f"Source Interface: {self.interface} VRF: {self.vrf}" diff --git a/anta/tests/snmp.py b/anta/tests/snmp.py index 864cba0e7..84c5470e6 100644 --- a/anta/tests/snmp.py +++ b/anta/tests/snmp.py @@ -492,16 +492,18 @@ def test(self) -> None: class VerifySnmpSourceInterface(AntaTest): - """Verifies SNMP source-interface for a specified VRF. + """Verifies SNMP source interfaces. This test performs the following checks: - 1. Verifies that the SNMP source-interface(s) configured for the specified VRF. + 1. Verifies that source interface(s) are configured for SNMP. + 2. For each specified source interface: + - Interface is configured in the specified VRF. Expected Results ---------------- - * Success: The test will pass if the provided SNMP source-interface(s) is configured in the specified VRF. - * Failure: The test will fail if the provided SNMP source-interface(s) is NOT configured in the specified VRF. + * Success: The test will pass if the provided SNMP source interface(s) are configured in their specified VRF. + * Failure: The test will fail if any of the provided SNMP source interface(s) are NOT configured in their specified VRF. Examples -------- @@ -523,7 +525,7 @@ class Input(AntaTest.Input): """Input model for the VerifySnmpSourceInterface test.""" interfaces: list[SnmpSourceInterface] - """List of source interfaces""" + """List of source interfaces.""" @AntaTest.anta_test def test(self) -> None: @@ -536,8 +538,8 @@ def test(self) -> None: return for interface_details in self.inputs.interfaces: - # If the source-interface is not configured, or if it does not match the expected value, the test fails. + # If the source interface is not configured, or if it does not match the expected value, the test fails. if not (actual_interface := interface_output.get(interface_details.vrf)): self.result.is_failure(f"{interface_details} - Not configured") elif actual_interface != interface_details.interface: - self.result.is_failure(f"{interface_details} - Incorrect source interface Actual: {actual_interface}") + self.result.is_failure(f"{interface_details} - Incorrect source interface - Actual: {actual_interface}") diff --git a/examples/tests.yaml b/examples/tests.yaml index 913247ca1..6c64f5d9f 100644 --- a/examples/tests.yaml +++ b/examples/tests.yaml @@ -794,7 +794,7 @@ anta.tests.snmp: - outTrapPdus - inGetNextPdus - VerifySnmpSourceInterface: - # Verifies SNMP source-interface for a specified VRF. + # Verifies SNMP source interfaces. interfaces: - interface: Ethernet1 vrf: default diff --git a/tests/units/anta_tests/test_snmp.py b/tests/units/anta_tests/test_snmp.py index bcec2a911..fc30ad6ce 100644 --- a/tests/units/anta_tests/test_snmp.py +++ b/tests/units/anta_tests/test_snmp.py @@ -575,8 +575,8 @@ "expected": { "result": "failure", "messages": [ - "VRF: default, Source Interface: Ethernet1 - Incorrect source interface Actual: Management0", - "VRF: MGMT, Source Interface: Management0 - Not configured", + "Source Interface: Ethernet1 VRF: default - Incorrect source interface - Actual: Management0", + "Source Interface: Management0 VRF: MGMT - Not configured", ], }, },