Skip to content

Commit

Permalink
Updated unit test with test failure msg
Browse files Browse the repository at this point in the history
  • Loading branch information
geetanjalimanegslab committed Feb 27, 2025
1 parent 0281799 commit 76544e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
19 changes: 8 additions & 11 deletions anta/tests/routing/ospf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test(self) -> None:
f"Instance: {instance} VRF: {vrf} Interface: {interface[0]} - Incorrect adjacency state - Expected: Full Actual: {interface[1]}"
)

# If OSPF neighbors are not configured on device, test fails.
# If OSPF neighbors are not configured on device, test skipped.
if no_neighbor:
self.result.is_skipped("No OSPF neighbor detected")

Expand Down Expand Up @@ -112,7 +112,7 @@ def test(self) -> None:
no_neighbor = False
interfaces.extend([neighbor["routerId"] for neighbor in neighbors if neighbor["adjacencyState"] == "full"])

# If OSPF neighbors are not configured on device, test fails.
# If OSPF neighbors are not configured on device, test skipped.
if no_neighbor:
self.result.is_skipped("No OSPF neighbor detected")
return
Expand All @@ -123,7 +123,7 @@ def test(self) -> None:


class VerifyOSPFMaxLSA(AntaTest):
"""Verifies LSAs present in the OSPF link state database did not cross the maximum LSA Threshold.
"""Verifies all OSPF instances did not cross the maximum LSA threshold.
Expected Results
----------------
Expand Down Expand Up @@ -153,13 +153,10 @@ def test(self) -> None:
self.result.is_skipped("OSPF not configured")
return

exceeded_instances = []
for vrf_data in command_output.values():
for instance, instance_data in vrf_data.get("instList", {}).items():
max_lsa = instance_data.get("maxLsaInformation", {}).get("maxLsa")
max_lsa_threshold = instance_data.get("maxLsaInformation", {}).get("maxLsaThreshold")
num_lsa = instance_data.get("lsaInformation", {}).get("numLsa")
if num_lsa > max_lsa * (max_lsa_threshold / 100):
exceeded_instances.append(instance)
if exceeded_instances:
self.result.is_failure(f"Following OSPF Instances crossed the maximum LSA threshold - {', '.join(exceeded_instances)}")
max_lsa = instance_data["maxLsaInformation"]["maxLsa"]
max_lsa_threshold = instance_data["maxLsaInformation"]["maxLsaThreshold"]
num_lsa = get_value(instance_data, "lsaInformation.numLsa")
if num_lsa > (max_lsa_threshold := round(max_lsa * (max_lsa_threshold / 100))):
self.result.is_failure(f"Instance: {instance} - Crossed the maximum LSA threshold - Expected: < {max_lsa_threshold} Actual: {num_lsa}")
3 changes: 1 addition & 2 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,12 @@ anta.tests.routing.isis:
nexthop: 1.1.1.1
anta.tests.routing.ospf:
- VerifyOSPFMaxLSA:
# Verifies LSAs present in the OSPF link state database did not cross the maximum LSA Threshold.
# Verifies all OSPF instances did not cross the maximum LSA threshold.
- VerifyOSPFNeighborCount:
# Verifies the number of OSPF neighbors in FULL state is the one we expect.
number: 3
- VerifyOSPFNeighborState:
# Verifies all OSPF neighbors are in FULL state.

anta.tests.security:
- VerifyAPIHttpStatus:
# Verifies if eAPI HTTP server is disabled globally.
Expand Down
5 changes: 4 additions & 1 deletion tests/units/anta_tests/routing/test_ospf.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@
"inputs": None,
"expected": {
"result": "failure",
"messages": ["Following OSPF Instances crossed the maximum LSA threshold - 1, 10"],
"messages": [
"Instance: 1 - Crossed the maximum LSA threshold - Expected: < 9000 Actual: 11500",
"Instance: 10 - Crossed the maximum LSA threshold - Expected: < 750 Actual: 1500",
],
},
},
{
Expand Down

0 comments on commit 76544e2

Please sign in to comment.