Skip to content

Commit

Permalink
Addressed review comments: updated unit tests, updated strict check f…
Browse files Browse the repository at this point in the history
…ailure msg
  • Loading branch information
vitthalmagadum committed Jan 22, 2025
1 parent c873c25 commit eaf1a2d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion anta/input_models/routing/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class IPv4Routes(BaseModel):
nexthops: list[IPv4Address] | None = None
"""A list of the next-hop IP addresses for the route. Required field in the `VerifyIPv4RouteNextHops` test."""
strict: bool = False
"""If True, requires exact matching of provided nexthop(s). Defaults to False.
"""If True, requires exact matching of provided nexthop(s).
Can be enabled in `VerifyIPv4RouteNextHops` test."""

Expand Down
3 changes: 2 additions & 1 deletion anta/tests/routing/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class VerifyIPv4RouteNextHops(AntaTest):
route_entries:
- prefix: 10.10.0.1/32
vrf: default
strict: False
nexthops:
- 10.100.0.8
- 10.100.0.10
Expand Down Expand Up @@ -340,7 +341,7 @@ def test(self) -> None:

if entry.strict and expected_nexthops != actual_nexthops:
exp_nexthops = ", ".join([str(nexthop) for nexthop in entry.nexthops])
self.result.is_failure(f"{entry} - Exact nexthop not listed - Expected: {exp_nexthops} Actual: {', '.join(actual_nexthops)}")
self.result.is_failure(f"{entry} - List of next-hops not matching - Expected: {exp_nexthops} - Actual: {', '.join(actual_nexthops)}")
continue

for nexthop in entry.nexthops:
Expand Down
1 change: 1 addition & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ anta.tests.routing.generic:
route_entries:
- prefix: 10.10.0.1/32
vrf: default
strict: False
nexthops:
- 10.100.0.8
- 10.100.0.10
Expand Down
9 changes: 5 additions & 4 deletions tests/units/anta_tests/routing/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@
"MGMT": {
"routes": {
"10.100.0.128/31": {
"vias": [{"nexthopAddr": "10.100.0.8", "interface": "Ethernet1"}, {"nexthopAddr": "10.100.0.10", "interface": "Ethernet2"}],
"vias": [{"nexthopAddr": "10.100.0.8", "interface": "Ethernet1"}, {"nexthopAddr": "10.100.0.11", "interface": "Ethernet2"}],
}
}
},
Expand All @@ -457,14 +457,15 @@
"inputs": {
"route_entries": [
{"prefix": "10.10.0.1/32", "vrf": "default", "strict": True, "nexthops": ["10.100.0.8", "10.100.0.10", "10.100.0.11"]},
{"prefix": "10.100.0.128/31", "vrf": "MGMT", "strict": True, "nexthops": ["10.100.0.8", "10.100.0.10", "10.100.0.11"]},
{"prefix": "10.100.0.128/31", "vrf": "MGMT", "strict": True, "nexthops": ["10.100.0.8", "10.100.0.10"]},
]
},
"expected": {
"result": "failure",
"messages": [
"Prefix: 10.10.0.1/32 VRF: default - Exact nexthop not listed - Expected: 10.100.0.8, 10.100.0.10, 10.100.0.11 Actual: 10.100.0.10, 10.100.0.8",
"Prefix: 10.100.0.128/31 VRF: MGMT - Exact nexthop not listed - Expected: 10.100.0.8, 10.100.0.10, 10.100.0.11 Actual: 10.100.0.10, 10.100.0.8",
"Prefix: 10.10.0.1/32 VRF: default - List of next-hops not matching - Expected: 10.100.0.8, 10.100.0.10, 10.100.0.11 - "
"Actual: 10.100.0.10, 10.100.0.8",
"Prefix: 10.100.0.128/31 VRF: MGMT - List of next-hops not matching - Expected: 10.100.0.8, 10.100.0.10 - Actual: 10.100.0.11, 10.100.0.8",
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/units/input_models/routing/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestVerifyRouteEntryInput:
@pytest.mark.parametrize(
("route_entries"),
[
pytest.param([{"prefix": "10.10.0.1/32", "vrf": "default", "nexthops": ["10.100.0.8", "10.100.0.10"]}], id="valid"),
pytest.param([{"prefix": "10.10.0.1/32", "vrf": "default", "strict": True, "nexthops": ["10.100.0.8", "10.100.0.10"]}], id="valid"),
],
)
def test_valid(self, route_entries: list[IPv4Routes]) -> None:
Expand Down

0 comments on commit eaf1a2d

Please sign in to comment.