Skip to content

Commit

Permalink
issue_821 Handling review comments: updated the failure msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
VitthalMagadum committed Oct 9, 2024
1 parent 61cd6d2 commit 47a8646
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
12 changes: 6 additions & 6 deletions anta/tests/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pydantic import BaseModel

from anta.custom_types import PositiveInteger
from anta.custom_types import Hostname, PositiveInteger
from anta.models import AntaCommand, AntaTest
from anta.tools import get_value

Expand Down Expand Up @@ -256,9 +256,9 @@ class VerifySnmpLogging(AntaTest):
anta.tests.snmp:
- VerifySnmpLogging:
hosts:
- 192.168.1.100
- hostname: 192.168.1.100
vrf: default
- 192.168.1.101
- hostname: 192.168.1.103
vrf: MGMT
```
"""
Expand All @@ -277,8 +277,8 @@ class Input(AntaTest.Input):
class SNMPHost(BaseModel):
"""Model for a SNMP Host."""

hostname: IPv4Address
"""IPv4 address of the SNMP notification host."""
hostname: IPv4Address | Hostname
"""IPv4 address or hostname of the SNMP notification host."""
vrf: str = "default"
"""Optional VRF for SNMP Hosts. If not provided, it defaults to `default`."""

Expand All @@ -305,7 +305,7 @@ def test(self) -> None:
failures += f"SNMP host '{hostname }' is not configured.\n"
continue
if actual_vrf != vrf:
failures += f"SNMP host '{hostname }' is not correctly configured in specified vrf '{vrf}'.\n"
failures += f"For SNMP host '{hostname }', expected '{vrf}' as vrf but found '{actual_vrf}' instead.\n"

# Check if there are any failures.
if not failures:
Expand Down
19 changes: 16 additions & 3 deletions tests/units/anta_tests/test_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,21 @@
{
"name": "success",
"test": VerifySnmpLogging,
"eos_data": [{"logging": {"loggingEnabled": True, "hosts": {"192.168.1.100": {"port": 162, "vrf": ""}, "192.168.1.101": {"port": 162, "vrf": "MGMT"}}}}],
"inputs": {"hosts": [{"hostname": "192.168.1.100", "vrf": "default"}, {"hostname": "192.168.1.101", "vrf": "MGMT"}]},
"eos_data": [
{
"logging": {
"loggingEnabled": True,
"hosts": {
"192.168.1.100": {"port": 162, "vrf": ""},
"192.168.1.101": {"port": 162, "vrf": "MGMT"},
"snmp-server-01": {"port": 162, "vrf": "MGMT"},
},
}
}
],
"inputs": {
"hosts": [{"hostname": "192.168.1.100", "vrf": "default"}, {"hostname": "192.168.1.101", "vrf": "MGMT"}, {"hostname": "snmp-server-01", "vrf": "MGMT"}]
},
"expected": {"result": "success"},
},
{
Expand All @@ -173,7 +186,7 @@
"inputs": {"hosts": [{"hostname": "192.168.1.100", "vrf": "default"}, {"hostname": "192.168.1.101", "vrf": "MGMT"}]},
"expected": {
"result": "failure",
"messages": ["SNMP host '192.168.1.100' is not correctly configured in specified vrf 'default'.\nSNMP host '192.168.1.101' is not configured."],
"messages": ["For SNMP host '192.168.1.100', expected 'default' as vrf but found 'MGMT' instead.\nSNMP host '192.168.1.101' is not configured."],
},
},
]

0 comments on commit 47a8646

Please sign in to comment.