Skip to content

Commit

Permalink
refactor(anta.tests): Updated failure msgs to avoid use of ; (#936)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
vitthalmagadum and gmuloc authored Nov 28, 2024
1 parent 2de0f5a commit 6b6d8e1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
3 changes: 2 additions & 1 deletion anta/tests/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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)]

Expand All @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions anta/tests/routing/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -373,21 +373,21 @@ 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}")
if not capability_status:
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):
Expand Down
3 changes: 1 addition & 2 deletions anta/tests/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion anta/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
52 changes: 26 additions & 26 deletions tests/units/anta_tests/routing/test_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
},
},
Expand Down Expand Up @@ -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",
],
},
},
Expand Down Expand Up @@ -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",
],
},
},
Expand Down Expand Up @@ -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",
],
},
},
Expand Down Expand Up @@ -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",
],
},
},
Expand Down Expand Up @@ -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",
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/units/anta_tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
8 changes: 4 additions & 4 deletions tests/units/anta_tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
},
},
Expand Down Expand Up @@ -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",
],
Expand Down

0 comments on commit 6b6d8e1

Please sign in to comment.