Files
napalm-proxmox/tests/test_lldp.py
T
Christian Manivong 89c70d85be fix(lldp): keep every neighbour of a port apart
lldpcli prints one Interface block per neighbour. The summary parser
reused the port's last entry, so a second neighbour overwrote the
first, and a neighbour without SysName was dropped. Each block now
starts an entry of its own.

Closes #22
2026-11-01 21:46:51 +01:00

66 lines
2.3 KiB
Python

"""LLDP neighbours read from lldpd's ``lldpcli show neighbors``."""
from __future__ import annotations
from napalm_proxmox import ProxmoxDriver
# lldpd 1.0 output: one "Interface:" block per neighbour, so a port with two
# neighbours (a switch and a phone behind it) appears twice. The phone sends
# no SysName.
TWO_NEIGHBOURS_ON_ONE_PORT = """\
-------------------------------------------------------------------------------
LLDP neighbors:
-------------------------------------------------------------------------------
Interface: eno1, via: LLDP, RID: 1, Time: 0 day, 00:10:12
Chassis:
ChassisID: mac 00:11:22:33:44:55
SysName: sw1
Port:
PortID: ifname gi1/0/1
PortDescr: GigabitEthernet1/0/1
-------------------------------------------------------------------------------
Interface: eno1, via: LLDP, RID: 2, Time: 0 day, 00:01:02
Chassis:
ChassisID: mac aa:bb:cc:dd:ee:ff
Port:
PortID: mac aa:bb:cc:dd:ee:ff
-------------------------------------------------------------------------------
Interface: eno2, via: LLDP, RID: 3, Time: 0 day, 00:10:12
Chassis:
ChassisID: mac 00:11:22:33:44:66
SysName: sw2
Port:
PortID: ifname gi1/0/2
-------------------------------------------------------------------------------
"""
def _driver(output: str) -> ProxmoxDriver:
d = ProxmoxDriver("pve", "root@pam", "pw")
d._exec_ssh_command = lambda command: output
return d
class TestGetLldpNeighbors:
def test_every_neighbour_on_a_port_is_its_own_entry(self):
result = _driver(TWO_NEIGHBOURS_ON_ONE_PORT).get_lldp_neighbors()
assert result == {
"eno1": [
{"hostname": "sw1", "port": "gi1/0/1"},
{"hostname": "", "port": "aa:bb:cc:dd:ee:ff"},
],
"eno2": [{"hostname": "sw2", "port": "gi1/0/2"}],
}
def test_no_lldpd_output_is_no_neighbour(self):
assert _driver("").get_lldp_neighbors() == {}
class TestGetLldpNeighborsDetail:
def test_every_neighbour_on_a_port_is_its_own_entry(self):
result = _driver(TWO_NEIGHBOURS_ON_ONE_PORT).get_lldp_neighbors_detail()
assert [e["remote_system_name"] for e in result["eno1"]] == ["sw1", ""]
assert result["eno1"][1]["remote_chassis_id"] == "aa:bb:cc:dd:ee:ff"