Skip to content

Commit

Permalink
Added negative testing in VerifyReachability
Browse files Browse the repository at this point in the history
  • Loading branch information
vitthalmagadum committed Feb 21, 2025
1 parent 7c9bef4 commit 986944b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
10 changes: 6 additions & 4 deletions anta/input_models/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ class Host(BaseModel):
source: IPv4Address | IPv6Address | Interface
"""Source address IP or egress interface to use."""
vrf: str = "default"
"""VRF context. Defaults to `default`."""
"""VRF context."""
repeat: int = 2
"""Number of ping repetition. Defaults to 2."""
"""Number of ping repetition."""
size: int = 100
"""Specify datagram size. Defaults to 100."""
"""Specify datagram size."""
df_bit: bool = False
"""Enable do not fragment bit in IP header. Defaults to False."""
"""Enable do not fragment bit in IP header."""
expected_unreachable: bool = False
"""Indicates whether the expected network should be unreachable."""

def __str__(self) -> str:
"""Return a human-readable string representation of the Host for reporting.
Expand Down
8 changes: 7 additions & 1 deletion anta/tests/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class VerifyReachability(AntaTest):
vrf: default
df_bit: True
size: 100
expected_unreachable: true
```
"""

Expand Down Expand Up @@ -89,9 +90,14 @@ def test(self) -> None:
self.result.is_success()

for command, host in zip(self.instance_commands, self.inputs.hosts):
if f"{host.repeat} received" not in command.json_output["messages"][0]:
# Verifies the network is reachable
if not host.expected_unreachable and f"{host.repeat} received" not in command.json_output["messages"][0]:
self.result.is_failure(f"{host} - Unreachable")

# Verifies the network is unreachable.
if host.expected_unreachable and "0 received" not in command.json_output["messages"][0]:
self.result.is_failure(f"{host} - Network is expected to be unreachable but found reachable.")


class VerifyLLDPNeighbors(AntaTest):
"""Verifies the connection status of the specified LLDP (Link Layer Discovery Protocol) neighbors.
Expand Down
1 change: 1 addition & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ anta.tests.connectivity:
vrf: default
df_bit: True
size: 100
expected_unreachable: true
anta.tests.cvx:
- VerifyActiveCVXConnections:
# Verifies the number of active CVX Connections.
Expand Down
38 changes: 38 additions & 0 deletions tests/units/anta_tests/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@
],
"expected": {"result": "success"},
},
{
"name": "success-expected-unreachable",
"test": VerifyReachability,
"eos_data": [
{
"messages": [
"""PING 10.0.0.1 (10.0.0.1) from 10.0.0.5 : 72(100) bytes of data.
--- 10.0.0.1 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 10ms
""",
],
},
],
"inputs": {"hosts": [{"destination": "10.0.0.1", "source": "10.0.0.5", "expected_unreachable": True}]},
"expected": {"result": "success"},
},
{
"name": "success-ipv6",
"test": VerifyReachability,
Expand Down Expand Up @@ -268,6 +285,27 @@
],
"expected": {"result": "failure", "messages": ["Host: 10.0.0.1 Source: Management0 VRF: default - Unreachable"]},
},
{
"name": "failure-expected-unreachable",
"test": VerifyReachability,
"eos_data": [
{
"messages": [
"""PING 10.0.0.1 (10.0.0.1) from 10.0.0.5 : 72(100) bytes of data.
80 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.247 ms
80 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.072 ms
--- 10.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.072/0.159/0.247/0.088 ms, ipg/ewma 0.370/0.225 ms
""",
],
},
],
"inputs": {"hosts": [{"destination": "10.0.0.1", "source": "10.0.0.5", "expected_unreachable": True}]},
"expected": {"result": "failure", "messages": ["Host: 10.0.0.1 Source: 10.0.0.5 VRF: default - Network is expected to be unreachable but found reachable."]},
},
{
"name": "success",
"test": VerifyLLDPNeighbors,
Expand Down

0 comments on commit 986944b

Please sign in to comment.