From cff8770db5c32ac85eff164d0103ee5cee9c9a6d Mon Sep 17 00:00:00 2001 From: VitthalMagadum Date: Thu, 26 Sep 2024 01:09:30 -0400 Subject: [PATCH] issue_782 Handling review comments: updated failure msg, unit tests --- anta/tests/stp.py | 6 +-- tests/units/anta_tests/test_stp.py | 74 ++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/anta/tests/stp.py b/anta/tests/stp.py index 556a995c4..3208f0c40 100644 --- a/anta/tests/stp.py +++ b/anta/tests/stp.py @@ -303,7 +303,7 @@ def test(self) -> None: # Verify the STP topology(s). if not stp_topologies: - self.result.is_failure("None of STP topology is configured.") + self.result.is_failure("STP is not configured.") return # Verifies the number of changes across all interfaces @@ -317,8 +317,6 @@ def test(self) -> None: failures["topologies"][topology] = interfaces if failures["topologies"]: - self.result.is_failure( - f"The following Spanning Tree Protocol (STP) topology(s) are not configured or number of changes not within the threshold:{failures}" - ) + self.result.is_failure(f"The following STP topologies are not configured or number of changes not within the threshold:\n{failures}") else: self.result.is_success() diff --git a/tests/units/anta_tests/test_stp.py b/tests/units/anta_tests/test_stp.py index b4daf0380..37422108b 100644 --- a/tests/units/anta_tests/test_stp.py +++ b/tests/units/anta_tests/test_stp.py @@ -374,6 +374,74 @@ "inputs": {"threshold": 10}, "expected": {"result": "success"}, }, + { + "name": "success-rapid-pvst", + "test": VerifyStpTopologyChanges, + "eos_data": [ + { + "unmappedVlans": [], + "topologies": { + "NoStp": { + "vlans": [4094, 4093, 1006], + "interfaces": { + "PeerEthernet2": {"state": "forwarding", "numChanges": 1, "lastChange": 1727151356.1330667}, + }, + }, + "Vl1": {"vlans": [1], "interfaces": {"Port-Channel5": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0615358}}}, + "Vl10": { + "vlans": [10], + "interfaces": { + "Cpu": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0673406}, + "Vxlan1": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0677001}, + "Port-Channel5": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0728855}, + "Ethernet3": {"state": "forwarding", "numChanges": 3, "lastChange": 1727326730.255137}, + }, + }, + "Vl1198": { + "vlans": [1198], + "interfaces": { + "Cpu": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.074386}, + "Vxlan1": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0743902}, + "Port-Channel5": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0743942}, + }, + }, + "Vl1199": { + "vlans": [1199], + "interfaces": { + "Cpu": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0744}, + "Vxlan1": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.07453}, + "Port-Channel5": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.074535}, + }, + }, + "Vl20": { + "vlans": [20], + "interfaces": { + "Cpu": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.073489}, + "Vxlan1": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0743747}, + "Port-Channel5": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0743794}, + "Ethernet3": {"state": "forwarding", "numChanges": 3, "lastChange": 1727326730.2551405}, + }, + }, + "Vl3009": { + "vlans": [3009], + "interfaces": { + "Cpu": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.074541}, + "Port-Channel5": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0745454}, + }, + }, + "Vl3019": { + "vlans": [3019], + "interfaces": { + "Cpu": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0745502}, + "Port-Channel5": {"state": "forwarding", "numChanges": 1, "lastChange": 1727326710.0745537}, + }, + }, + }, + }, + ], + "inputs": {"threshold": 10}, + "expected": {"result": "success"}, + }, { "name": "failure-unstable-topology", "test": VerifyStpTopologyChanges, @@ -394,8 +462,8 @@ "expected": { "result": "failure", "messages": [ - "The following Spanning Tree Protocol (STP) topology(s) are not configured or number of changes" - " not within the threshold:{'topologies': {'Cist': {'Cpu': {'Number of changes': 15}, 'Port-Channel5': {'Number of changes': 15}}}}" + "The following STP topologies are not configured or number of changes not within the threshold:\n" + "{'topologies': {'Cist': {'Cpu': {'Number of changes': 15}, 'Port-Channel5': {'Number of changes': 15}}}}" ], }, }, @@ -416,6 +484,6 @@ }, ], "inputs": {"threshold": 10}, - "expected": {"result": "failure", "messages": ["None of STP topology is configured."]}, + "expected": {"result": "failure", "messages": ["STP is not configured."]}, }, ]