Skip to content

Commit

Permalink
feat(anta.tests): update VerifyReachability
Browse files Browse the repository at this point in the history
  • Loading branch information
mtache committed Nov 26, 2024
1 parent b88cbab commit 85994d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
11 changes: 2 additions & 9 deletions anta/input_models/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,8 @@ class Host(BaseModel):
"""Enable do not fragment bit in IP header. Defaults to False."""

def __str__(self) -> str:
"""Return a human-readable string representation of the Host for reporting.
Examples
--------
Host 10.1.1.1 (src: 10.2.2.2, vrf: mgmt, size: 100B, repeat: 2)
"""
df_status = ", df-bit: enabled" if self.df_bit else ""
return f"Host {self.destination} (src: {self.source}, vrf: {self.vrf}, size: {self.size}B, repeat: {self.repeat}{df_status})"
"""Return a human-readable string representation of the Host for reporting."""
return f"Host {self.destination} in VRF {self.vrf}"


class LLDPNeighbor(BaseModel):
Expand Down
5 changes: 1 addition & 4 deletions anta/tests/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ def render(self, template: AntaTemplate) -> list[AntaCommand]:
@AntaTest.anta_test
def test(self) -> None:
"""Main test function for VerifyReachability."""
self.result.is_success()

for command, host in zip(self.instance_commands, self.inputs.hosts):
host_result = self.result.add(description=str(host), inputs=host)
host_result.is_success()
if f"{host.repeat} received" not in command.json_output["messages"][0]:
host_result.is_failure()
self.result.is_failure(f"Unreachable {host}")
host_result.is_failure(f"Unreachable {host}")


class VerifyLLDPNeighbors(AntaTest):
Expand Down
34 changes: 17 additions & 17 deletions tests/units/anta_tests/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
{
"result": "success",
"messages": [],
"description": "Host 10.0.0.1 (src: 10.0.0.5, vrf: default, size: 100B, repeat: 2)",
"description": "Host 10.0.0.1 in VRF default",
"inputs": {"destination": "10.0.0.1", "source": "10.0.0.5", "vrf": "default", "repeat": 2, "size": 100, "df_bit": False},
},
{
"description": "Host 10.0.0.2 (src: 10.0.0.5, vrf: default, size: 100B, repeat: 2)",
"description": "Host 10.0.0.2 in VRF default",
"inputs": {
"destination": "10.0.0.2",
"df_bit": False,
Expand Down Expand Up @@ -106,11 +106,11 @@
{
"result": "success",
"messages": [],
"description": "Host 10.0.0.1 (src: Management0, vrf: default, size: 100B, repeat: 2)",
"description": "Host 10.0.0.1 in VRF default",
"inputs": {"destination": "10.0.0.1", "source": "Management0", "vrf": "default", "repeat": 2, "size": 100, "df_bit": False},
},
{
"description": "Host 10.0.0.2 (src: Management0, vrf: default, size: 100B, repeat: 2)",
"description": "Host 10.0.0.2 in VRF default",
"inputs": {
"destination": "10.0.0.2",
"df_bit": False,
Expand Down Expand Up @@ -147,7 +147,7 @@
"result": "success",
"atomic_results": [
{
"description": "Host 10.0.0.1 (src: Management0, vrf: default, size: 100B, repeat: 1)",
"description": "Host 10.0.0.1 in VRF default",
"inputs": {
"destination": "10.0.0.1",
"df_bit": False,
Expand Down Expand Up @@ -186,7 +186,7 @@
"result": "success",
"atomic_results": [
{
"description": "Host 10.0.0.1 (src: Management0, vrf: default, size: 1500B, repeat: 5, df-bit: enabled)",
"description": "Host 10.0.0.1 in VRF default",
"inputs": {
"destination": "10.0.0.1",
"df_bit": True,
Expand Down Expand Up @@ -235,10 +235,10 @@
],
"expected": {
"result": "failure",
"messages": ["Unreachable Host 10.0.0.11 (src: 10.0.0.5, vrf: default, size: 100B, repeat: 2)"],
"messages": ["Unreachable Host 10.0.0.11 in VRF default"],
"atomic_results": [
{
"description": "Host 10.0.0.11 (src: 10.0.0.5, vrf: default, size: 100B, repeat: 2)",
"description": "Host 10.0.0.11 in VRF default",
"inputs": {
"destination": "10.0.0.11",
"df_bit": False,
Expand All @@ -247,11 +247,11 @@
"source": "10.0.0.5",
"vrf": "default",
},
"messages": [],
"messages": ["Unreachable Host 10.0.0.11 in VRF default"],
"result": "failure",
},
{
"description": "Host 10.0.0.2 (src: 10.0.0.5, vrf: default, size: 100B, repeat: 2)",
"description": "Host 10.0.0.2 in VRF default",
"inputs": {
"destination": "10.0.0.2",
"df_bit": False,
Expand Down Expand Up @@ -300,10 +300,10 @@
],
"expected": {
"result": "failure",
"messages": ["Unreachable Host 10.0.0.11 (src: Management0, vrf: default, size: 100B, repeat: 2)"],
"messages": ["Unreachable Host 10.0.0.11 in VRF default"],
"atomic_results": [
{
"description": "Host 10.0.0.11 (src: Management0, vrf: default, size: 100B, repeat: 2)",
"description": "Host 10.0.0.11 in VRF default",
"inputs": {
"destination": "10.0.0.11",
"df_bit": False,
Expand All @@ -312,11 +312,11 @@
"source": "Management0",
"vrf": "default",
},
"messages": [],
"messages": ["Unreachable Host 10.0.0.11 in VRF default"],
"result": "failure",
},
{
"description": "Host 10.0.0.2 (src: Management0, vrf: default, size: 100B, repeat: 2)",
"description": "Host 10.0.0.2 in VRF default",
"inputs": {
"destination": "10.0.0.2",
"df_bit": False,
Expand Down Expand Up @@ -353,10 +353,10 @@
],
"expected": {
"result": "failure",
"messages": ["Unreachable Host 10.0.0.1 (src: Management0, vrf: default, size: 1501B, repeat: 5, df-bit: enabled)"],
"messages": ["Unreachable Host 10.0.0.1 in VRF default"],
"atomic_results": [
{
"description": "Host 10.0.0.1 (src: Management0, vrf: default, size: 1501B, repeat: 5, df-bit: enabled)",
"description": "Host 10.0.0.1 in VRF default",
"inputs": {
"destination": "10.0.0.1",
"df_bit": True,
Expand All @@ -365,7 +365,7 @@
"source": "Management0",
"vrf": "default",
},
"messages": [],
"messages": ["Unreachable Host 10.0.0.1 in VRF default"],
"result": "failure",
},
],
Expand Down

0 comments on commit 85994d4

Please sign in to comment.