From 6b6d8e1089942a8e5e3ca8aadadbe384745c9cf2 Mon Sep 17 00:00:00 2001 From: vitthalmagadum <122079046+vitthalmagadum@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:19:07 +0530 Subject: [PATCH] refactor(anta.tests): Updated failure msgs to avoid use of `;` (#936) * Updated failure msgs: VerifyReachability, VerifyInterfacesStatus, VerifyNTPAssociations, VerifyDNSServers, VerifyLLDPNeighbors, BGP Part-1 * Updated unit tests for format_data utility * Reverting changes related to comma * reverting chnages from tools and test tools --------- Co-authored-by: Guillaume Mulocher --- anta/tests/connectivity.py | 3 +- anta/tests/routing/bgp.py | 12 ++--- anta/tests/services.py | 3 +- anta/tests/system.py | 2 +- tests/units/anta_tests/routing/test_bgp.py | 52 +++++++++++----------- tests/units/anta_tests/test_services.py | 2 +- tests/units/anta_tests/test_system.py | 8 ++-- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/anta/tests/connectivity.py b/anta/tests/connectivity.py index 132b1d163..b26c770fd 100644 --- a/anta/tests/connectivity.py +++ b/anta/tests/connectivity.py @@ -52,6 +52,7 @@ class Input(AntaTest.Input): hosts: list[Host] """List of host to ping.""" Host: ClassVar[type[Host]] = Host + """To maintain backward compatibility.""" def render(self, template: AntaTemplate) -> list[AntaCommand]: """Render the template for each host in the input list.""" @@ -104,7 +105,6 @@ class VerifyLLDPNeighbors(AntaTest): ``` """ - description = "Verifies that the provided LLDP neighbors are connected properly." categories: ClassVar[list[str]] = ["connectivity"] commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show lldp neighbors detail", revision=1)] @@ -114,6 +114,7 @@ class Input(AntaTest.Input): neighbors: list[LLDPNeighbor] """List of LLDP neighbors.""" Neighbor: ClassVar[type[Neighbor]] = Neighbor + """To maintain backward compatibility.""" @AntaTest.anta_test def test(self) -> None: diff --git a/anta/tests/routing/bgp.py b/anta/tests/routing/bgp.py index b3034ea78..4f55a0f4b 100644 --- a/anta/tests/routing/bgp.py +++ b/anta/tests/routing/bgp.py @@ -272,18 +272,18 @@ def test(self) -> None: for peer in relevant_peers: # Check if the BGP session is established if peer["state"] != "Established": - self.result.is_failure(f"{address_family} Peer: {peer['peerAddress']} - Session state is not established; State: {peer['state']}") + self.result.is_failure(f"{address_family} Peer: {peer['peerAddress']} - Session state is not established - State: {peer['state']}") # Check if the AFI/SAFI state is negotiated capability_status = get_value(peer, f"neighborCapabilities.multiprotocolCaps.{address_family.eos_key}") if not _check_bgp_neighbor_capability(capability_status): - self.result.is_failure(f"{address_family} Peer: {peer['peerAddress']} - AFI/SAFI state is not negotiated; {format_data(capability_status)}") + self.result.is_failure(f"{address_family} Peer: {peer['peerAddress']} - AFI/SAFI state is not negotiated - {format_data(capability_status)}") # Check the TCP session message queues inq = peer["peerTcpInfo"]["inputQueueLength"] outq = peer["peerTcpInfo"]["outputQueueLength"] if address_family.check_tcp_queues and (inq != 0 or outq != 0): - self.result.is_failure(f"{address_family} Peer: {peer['peerAddress']} - Session has non-empty message queues; InQ: {inq}, OutQ: {outq}") + self.result.is_failure(f"{address_family} Peer: {peer['peerAddress']} - Session has non-empty message queues - InQ: {inq}, OutQ: {outq}") class VerifyBGPSpecificPeers(AntaTest): @@ -373,7 +373,7 @@ def test(self) -> None: # Check if the BGP session is established if peer_data["state"] != "Established": - self.result.is_failure(f"{address_family} Peer: {peer_ip} - Session state is not established; State: {peer_data['state']}") + self.result.is_failure(f"{address_family} Peer: {peer_ip} - Session state is not established - State: {peer_data['state']}") # Check if the AFI/SAFI state is negotiated capability_status = get_value(peer_data, f"neighborCapabilities.multiprotocolCaps.{address_family.eos_key}") @@ -381,13 +381,13 @@ def test(self) -> None: self.result.is_failure(f"{address_family} Peer: {peer_ip} - AFI/SAFI state is not negotiated") if capability_status and not _check_bgp_neighbor_capability(capability_status): - self.result.is_failure(f"{address_family} Peer: {peer_ip} - AFI/SAFI state is not negotiated; {format_data(capability_status)}") + self.result.is_failure(f"{address_family} Peer: {peer_ip} - AFI/SAFI state is not negotiated - {format_data(capability_status)}") # Check the TCP session message queues inq = peer_data["peerTcpInfo"]["inputQueueLength"] outq = peer_data["peerTcpInfo"]["outputQueueLength"] if address_family.check_tcp_queues and (inq != 0 or outq != 0): - self.result.is_failure(f"{address_family} Peer: {peer_ip} - Session has non-empty message queues; InQ: {inq}, OutQ: {outq}") + self.result.is_failure(f"{address_family} Peer: {peer_ip} - Session has non-empty message queues - InQ: {inq}, OutQ: {outq}") class VerifyBGPExchangedRoutes(AntaTest): diff --git a/anta/tests/services.py b/anta/tests/services.py index 1e59791ab..dab1b3a56 100644 --- a/anta/tests/services.py +++ b/anta/tests/services.py @@ -133,7 +133,6 @@ class VerifyDNSServers(AntaTest): ``` """ - description = "Verifies if the DNS servers are correctly configured." categories: ClassVar[list[str]] = ["services"] commands: ClassVar[list[AntaCommand | AntaTemplate]] = [AntaCommand(command="show ip name-server", revision=1)] @@ -163,7 +162,7 @@ def test(self) -> None: # Check if the DNS server priority matches with expected. if output["priority"] != priority: - self.result.is_failure(f"{server} - Incorrect priority; Priority: {output['priority']}") + self.result.is_failure(f"{server} - Incorrect priority - Priority: {output['priority']}") class VerifyErrdisableRecovery(AntaTest): diff --git a/anta/tests/system.py b/anta/tests/system.py index f2ce47186..6bed495e4 100644 --- a/anta/tests/system.py +++ b/anta/tests/system.py @@ -350,4 +350,4 @@ def test(self) -> None: act_stratum = get_value(peers[matching_peer], "stratumLevel") if act_condition != exp_condition or act_stratum != exp_stratum: - self.result.is_failure(f"{ntp_server} - Bad association; Condition: {act_condition}, Stratum: {act_stratum}") + self.result.is_failure(f"{ntp_server} - Bad association - Condition: {act_condition}, Stratum: {act_stratum}") diff --git a/tests/units/anta_tests/routing/test_bgp.py b/tests/units/anta_tests/routing/test_bgp.py index e4b8b5c8b..c5b8cedb6 100644 --- a/tests/units/anta_tests/routing/test_bgp.py +++ b/tests/units/anta_tests/routing/test_bgp.py @@ -565,10 +565,10 @@ def test_check_bgp_neighbor_capability(input_dict: dict[str, bool], expected: bo "expected": { "result": "failure", "messages": [ - "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session state is not established; State: Idle", - "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - Session state is not established; State: Idle", - "AFI: path-selection Peer: 10.100.0.13 - Session state is not established; State: Idle", - "AFI: link-state Peer: 10.100.0.14 - Session state is not established; State: Idle", + "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session state is not established - State: Idle", + "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - Session state is not established - State: Idle", + "AFI: path-selection Peer: 10.100.0.13 - Session state is not established - State: Idle", + "AFI: link-state Peer: 10.100.0.14 - Session state is not established - State: Idle", ], }, }, @@ -624,14 +624,14 @@ def test_check_bgp_neighbor_capability(input_dict: dict[str, bool], expected: bo "expected": { "result": "failure", "messages": [ - "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session state is not established; State: Idle", - "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - AFI/SAFI state is not negotiated; Advertised: False, Received: False, Enabled: True", - "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - Session state is not established; State: Idle", - "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - AFI/SAFI state is not negotiated; Advertised: False, Received: False, Enabled: False", - "AFI: path-selection Peer: 10.100.0.13 - Session state is not established; State: Idle", - "AFI: path-selection Peer: 10.100.0.13 - AFI/SAFI state is not negotiated; Advertised: True, Received: False, Enabled: False", - "AFI: link-state Peer: 10.100.0.14 - Session state is not established; State: Idle", - "AFI: link-state Peer: 10.100.0.14 - AFI/SAFI state is not negotiated; Advertised: False, Received: False, Enabled: False", + "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session state is not established - State: Idle", + "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - AFI/SAFI state is not negotiated - Advertised: False, Received: False, Enabled: True", + "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - Session state is not established - State: Idle", + "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - AFI/SAFI state is not negotiated - Advertised: False, Received: False, Enabled: False", + "AFI: path-selection Peer: 10.100.0.13 - Session state is not established - State: Idle", + "AFI: path-selection Peer: 10.100.0.13 - AFI/SAFI state is not negotiated - Advertised: True, Received: False, Enabled: False", + "AFI: link-state Peer: 10.100.0.14 - Session state is not established - State: Idle", + "AFI: link-state Peer: 10.100.0.14 - AFI/SAFI state is not negotiated - Advertised: False, Received: False, Enabled: False", ], }, }, @@ -687,14 +687,14 @@ def test_check_bgp_neighbor_capability(input_dict: dict[str, bool], expected: bo "expected": { "result": "failure", "messages": [ - "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session state is not established; State: Idle", - "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session has non-empty message queues; InQ: 2, OutQ: 4", - "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - Session state is not established; State: Idle", - "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - Session has non-empty message queues; InQ: 5, OutQ: 1", - "AFI: path-selection Peer: 10.100.0.13 - Session state is not established; State: Idle", - "AFI: path-selection Peer: 10.100.0.13 - Session has non-empty message queues; InQ: 1, OutQ: 1", - "AFI: link-state Peer: 10.100.0.14 - Session state is not established; State: Idle", - "AFI: link-state Peer: 10.100.0.14 - Session has non-empty message queues; InQ: 3, OutQ: 2", + "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session state is not established - State: Idle", + "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session has non-empty message queues - InQ: 2, OutQ: 4", + "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - Session state is not established - State: Idle", + "AFI: ipv4 SAFI: sr-te VRF: MGMT Peer: 10.100.0.12 - Session has non-empty message queues - InQ: 5, OutQ: 1", + "AFI: path-selection Peer: 10.100.0.13 - Session state is not established - State: Idle", + "AFI: path-selection Peer: 10.100.0.13 - Session has non-empty message queues - InQ: 1, OutQ: 1", + "AFI: link-state Peer: 10.100.0.14 - Session state is not established - State: Idle", + "AFI: link-state Peer: 10.100.0.14 - Session has non-empty message queues - InQ: 3, OutQ: 2", ], }, }, @@ -849,8 +849,8 @@ def test_check_bgp_neighbor_capability(input_dict: dict[str, bool], expected: bo "expected": { "result": "failure", "messages": [ - "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session state is not established; State: Idle", - "AFI: ipv4 SAFI: unicast VRF: MGMT Peer: 10.100.0.14 - Session state is not established; State: Idle", + "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session state is not established - State: Idle", + "AFI: ipv4 SAFI: unicast VRF: MGMT Peer: 10.100.0.14 - Session state is not established - State: Idle", ], }, }, @@ -892,8 +892,8 @@ def test_check_bgp_neighbor_capability(input_dict: dict[str, bool], expected: bo "expected": { "result": "failure", "messages": [ - "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - AFI/SAFI state is not negotiated; Advertised: False, Received: False, Enabled: True", - "AFI: ipv4 SAFI: unicast VRF: MGMT Peer: 10.100.0.14 - AFI/SAFI state is not negotiated; Advertised: False, Received: False, Enabled: False", + "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - AFI/SAFI state is not negotiated - Advertised: False, Received: False, Enabled: True", + "AFI: ipv4 SAFI: unicast VRF: MGMT Peer: 10.100.0.14 - AFI/SAFI state is not negotiated - Advertised: False, Received: False, Enabled: False", ], }, }, @@ -978,8 +978,8 @@ def test_check_bgp_neighbor_capability(input_dict: dict[str, bool], expected: bo "expected": { "result": "failure", "messages": [ - "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session has non-empty message queues; InQ: 3, OutQ: 3", - "AFI: ipv4 SAFI: unicast VRF: MGMT Peer: 10.100.0.14 - Session has non-empty message queues; InQ: 2, OutQ: 2", + "AFI: ipv4 SAFI: unicast VRF: default Peer: 10.100.0.12 - Session has non-empty message queues - InQ: 3, OutQ: 3", + "AFI: ipv4 SAFI: unicast VRF: MGMT Peer: 10.100.0.14 - Session has non-empty message queues - InQ: 2, OutQ: 2", ], }, }, diff --git a/tests/units/anta_tests/test_services.py b/tests/units/anta_tests/test_services.py index 6802aab49..639c5c685 100644 --- a/tests/units/anta_tests/test_services.py +++ b/tests/units/anta_tests/test_services.py @@ -109,7 +109,7 @@ "expected": { "result": "failure", "messages": [ - "Server 10.14.0.1 (VRF: CS, Priority: 0) - Incorrect priority; Priority: 1", + "Server 10.14.0.1 (VRF: CS, Priority: 0) - Incorrect priority - Priority: 1", "Server 10.14.0.11 (VRF: default, Priority: 0) - Not configured", "Server 10.14.0.110 (VRF: MGMT, Priority: 0) - Not configured", ], diff --git a/tests/units/anta_tests/test_system.py b/tests/units/anta_tests/test_system.py index 532bd2337..f610a8e5b 100644 --- a/tests/units/anta_tests/test_system.py +++ b/tests/units/anta_tests/test_system.py @@ -413,9 +413,9 @@ "expected": { "result": "failure", "messages": [ - "1.1.1.1 (Preferred: True, Stratum: 1) - Bad association; Condition: candidate, Stratum: 2", - "2.2.2.2 (Preferred: False, Stratum: 2) - Bad association; Condition: sys.peer, Stratum: 2", - "3.3.3.3 (Preferred: False, Stratum: 2) - Bad association; Condition: sys.peer, Stratum: 3", + "1.1.1.1 (Preferred: True, Stratum: 1) - Bad association - Condition: candidate, Stratum: 2", + "2.2.2.2 (Preferred: False, Stratum: 2) - Bad association - Condition: sys.peer, Stratum: 2", + "3.3.3.3 (Preferred: False, Stratum: 2) - Bad association - Condition: sys.peer, Stratum: 3", ], }, }, @@ -490,7 +490,7 @@ "expected": { "result": "failure", "messages": [ - "1.1.1.1 (Preferred: True, Stratum: 1) - Bad association; Condition: candidate, Stratum: 1", + "1.1.1.1 (Preferred: True, Stratum: 1) - Bad association - Condition: candidate, Stratum: 1", "2.2.2.2 (Preferred: False, Stratum: 1) - Not configured", "3.3.3.3 (Preferred: False, Stratum: 1) - Not configured", ],