Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-baillargeon committed Jan 21, 2025
1 parent af18537 commit a15cc3d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions anta/input_models/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
16 changes: 9 additions & 7 deletions anta/tests/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand All @@ -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:
Expand All @@ -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}")
2 changes: 1 addition & 1 deletion examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/units/anta_tests/test_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
},
},
Expand Down

0 comments on commit a15cc3d

Please sign in to comment.