8000 feat(anta.tests): Added negative testing in VerifyReachability test by vitthalmagadum · Pull Request #1053 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(anta.tests): Added negative testing in VerifyReachability test #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."""
reachable: bool = True
"""Indicates whether the destination should be reachable."""

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

Expand Down Expand Up @@ -89,9 +91,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 host.reachable 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 not host.reachable and f"{host.repeat} received" in command.json_output["messages"][0]:
self.result.is_failure(f"{host} - Destination 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
2 changes: 2 additions & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ anta.tests.connectivity:
vrf: MGMT
df_bit: True
size: 100
reachable: true
- source: Management0
destination: 8.8.8.8
vrf: MGMT
Expand All @@ -140,6 +141,7 @@ anta.tests.connectivity:
vrf: default
df_bit: True
size: 100
reachable: false
anta.tests.cvx:
- VerifyActiveCVXConnections:
# Verifies the number of active CVX Connections.
Expand Down
41 changes: 41 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", "reachable": False}]},
"expected": {"result": "success"},
},
{
"name": "success-ipv6",
"test": VerifyReachability,
Expand Down Expand Up @@ -268,6 +285,30 @@
],
"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", "reachable": False}]},
"expected": {
"result": "failure",
"messages": ["Host: 10.0.0.1 Source: 10.0.0.5 VRF: default - Destination is expected to be unreachable but found reachable."],
},
},
{
"name": "success",
"test": VerifyLLDPNeighbors,
Expand Down
Loading
0