Skip to content

Commit

Permalink
Updated test for multiple neighbor
Browse files Browse the repository at this point in the history
  • Loading branch information
VitthalMagadum committed Nov 8, 2024
1 parent bafa2f0 commit c589ee9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
23 changes: 13 additions & 10 deletions anta/tests/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from anta.input_models.connectivity import Host, Neighbor
from anta.models import AntaCommand, AntaTemplate, AntaTest
from anta.tools import get_item, get_value


class VerifyReachability(AntaTest):
Expand Down Expand Up @@ -121,15 +120,19 @@ def test(self) -> None:

output = self.instance_commands[0].json_output["lldpNeighbors"]
for neighbor in self.inputs.neighbors:
if not (lldp_neighbor_info := get_value(output, f"{neighbor.port}.lldpNeighborInfo")) or not (
neighbor_info := get_item(lldp_neighbor_info, "systemName", neighbor.neighbor_device)
):
self.result.is_failure(f"{neighbor} - Not configured")
if neighbor.port not in output:
self.result.is_failure(f"{neighbor} - Port not found")
continue

sytem_name = neighbor_info.get("systemName")
neighbor_port = neighbor_info.get("neighborInterfaceInfo", {}).get("interfaceId_v2")
if len(lldp_neighbor_info := output[neighbor.port]["lldpNeighborInfo"]) == 0:
self.result.is_failure(f"{neighbor} - No LLDP neighbors on the port")
continue

# Check if the neighbor details matches the expected details
if sytem_name != neighbor.neighbor_device or neighbor_port != neighbor.neighbor_port:
self.result.is_failure(f"{neighbor} - Inconsistent LLDP neighbors; Neighbor device: {sytem_name}, Neighbor port: {neighbor_port}")
# Check if the system name and neighbor port matches
match_found = any(
info["systemName"] == neighbor.neighbor_device and info["neighborInterfaceInfo"]["interfaceId_v2"] == neighbor.neighbor_port
for info in lldp_neighbor_info
)
if not match_found:
failure_msg = [f"{info['systemName']}/{info['neighborInterfaceInfo']['interfaceId_v2']}" for info in lldp_neighbor_info]
self.result.is_failure(f"{neighbor} - Wrong LLDP neighbors on the ports; {', '.join(failure_msg)}")
54 changes: 44 additions & 10 deletions tests/units/anta_tests/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,40 @@
{"port": "Ethernet2", "neighbor_device": "DC1-SPINE2", "neighbor_port": "Ethernet1"},
],
},
"expected": {"result": "failure", "messages": ["Port Ethernet2 (Neighbor: DC1-SPINE2, Neighbor port: Ethernet1) - Not configured"]},
"expected": {"result": "failure", "messages": ["Port Ethernet2 (Neighbor: DC1-SPINE2, Neighbor port: Ethernet1) - Port not found"]},
},
{
"name": "failure-no-neighbor",
"test": VerifyLLDPNeighbors,
"eos_data": [
{
"lldpNeighbors": {
"Ethernet1": {
"lldpNeighborInfo": [
{
"chassisIdType": "macAddress",
"chassisId": "001c.73a0.fc18",
"systemName": "DC1-SPINE1",
"neighborInterfaceInfo": {
"interfaceIdType": "interfaceName",
"interfaceId": '"Ethernet1"',
"interfaceId_v2": "Ethernet1",
"interfaceDescription": "P2P_LINK_TO_DC1-LEAF1A_Ethernet1",
},
},
],
},
"Ethernet2": {"lldpNeighborInfo": []},
},
},
],
"inputs": {
"neighbors": [
{"port": "Ethernet1", "neighbor_device": "DC1-SPINE1", "neighbor_port": "Ethernet1"},
{"port": "Ethernet2", "neighbor_device": "DC1-SPINE2", "neighbor_port": "Ethernet1"},
],
},
"expected": {"result": "failure", "messages": ["Port Ethernet2 (Neighbor: DC1-SPINE2, Neighbor port: Ethernet1) - No LLDP neighbors on the port"]},
},
{
"name": "failure-wrong-neighbor",
Expand Down Expand Up @@ -379,10 +412,7 @@
},
"expected": {
"result": "failure",
"messages": [
"Port Ethernet2 (Neighbor: DC1-SPINE2, Neighbor port: Ethernet1) - "
"Inconsistent LLDP neighbors; Neighbor device: DC1-SPINE2, Neighbor port: Ethernet2"
],
"messages": ["Port Ethernet2 (Neighbor: DC1-SPINE2, Neighbor port: Ethernet1) - Wrong LLDP neighbors on the ports; DC1-SPINE2/Ethernet2"],
},
},
{
Expand Down Expand Up @@ -420,10 +450,9 @@
"expected": {
"result": "failure",
"messages": [
"Port Ethernet1 (Neighbor: DC1-SPINE1, Neighbor port: Ethernet1) - Inconsistent LLDP neighbors; "
"Neighbor device: DC1-SPINE1, Neighbor port: Ethernet2",
"Port Ethernet2 (Neighbor: DC1-SPINE2, Neighbor port: Ethernet1) - Not configured",
"Port Ethernet3 (Neighbor: DC1-SPINE3, Neighbor port: Ethernet1) - Not configured",
"Port Ethernet1 (Neighbor: DC1-SPINE1, Neighbor port: Ethernet1) - Wrong LLDP neighbors on the ports; DC1-SPINE1/Ethernet2",
"Port Ethernet2 (Neighbor: DC1-SPINE2, Neighbor port: Ethernet1) - No LLDP neighbors on the port",
"Port Ethernet3 (Neighbor: DC1-SPINE3, Neighbor port: Ethernet1) - Port not found",
],
},
},
Expand Down Expand Up @@ -467,6 +496,11 @@
{"port": "Ethernet1", "neighbor_device": "DC1-SPINE3", "neighbor_port": "Ethernet1"},
],
},
"expected": {"result": "failure", "messages": ["Port Ethernet1 (Neighbor: DC1-SPINE3, Neighbor port: Ethernet1) - Not configured"]},
"expected": {
"result": "failure",
"messages": [
"Port Ethernet1 (Neighbor: DC1-SPINE3, Neighbor port: Ethernet1) - Wrong LLDP neighbors on the ports; DC1-SPINE1/Ethernet1, DC1-SPINE2/Ethernet1"
],
},
},
]

0 comments on commit c589ee9

Please sign in to comment.