fix(lldp): keep dotted interface names and read every id type

The local interface was the second dotted part of the key, so the
neighbours of eth0.1 landed under eth0 with every field missed. The
remote port was read from port.ifname or port.id.value, and lldpd
prints a port given by MAC or local id as port.mac / port.local, never
as id.value, so that port came back empty.

lldpd's output now goes through napalm-device-types'
parse_lldpctl_keyvalue and its two NAPALM projections, which keep the
interface name up to the neighbour's first field and read the ids under
whatever type lldpd prints. The detail gains the system description and
capabilities on the way. The module is under strict mypy now; the floor
on napalm-device-types rises to 4.24.0.

Closes #26
This commit is contained in:
Christian Manivong committed 2026-11-02 08:45:51 +01:00
1 parent d04a969eb1
commit 231def768e
5 files changed
+92 -73

No files matched your search

+61
View File
@@ -421,6 +421,67 @@ class TestLldpSeveralNeighboursOnOnePort:
assert len(driver.get_lldp_neighbors_detail("lan1")["lan1"]) == 2
# A swconfig VLAN interface (``eth0.1``) with a neighbour that names its port by
# MAC, and a switch on ``eth1`` that names itself and its port by local ids.
# Laid out the way lldpd's keyvalue writer prints them (src/client/display.c):
# an id is printed under its type, never as ``id.value``. Not recorded from a device.
LLDPCTL_KV_DOTTED_AND_ID_TYPES = """\
lldp.eth0.1.via=LLDP
lldp.eth0.1.rid=1
lldp.eth0.1.chassis.mac=00:11:22:33:44:01
lldp.eth0.1.chassis.name=desk-phone
lldp.eth0.1.chassis.descr=SIP phone
lldp.eth0.1.chassis.Tel.enabled=on
lldp.eth0.1.port.mac=00:11:22:33:44:01
lldp.eth0.1.port.descr=WAN
lldp.eth1.via=LLDP
lldp.eth1.rid=2
lldp.eth1.chassis.local=access-sw-01
lldp.eth1.chassis.name=access-sw
lldp.eth1.chassis.Bridge.enabled=on
lldp.eth1.chassis.Router.enabled=off
lldp.eth1.port.local=gi1/0/7
"""
class TestLldpDottedInterfaceAndPortIds:
"""``eth0.1`` keeps its name, and a port id given as MAC or local id is read (#26)."""
def test_a_dotted_interface_keeps_its_name(self, driver):
driver._send_command = lambda cmd, **kw: LLDPCTL_KV_DOTTED_AND_ID_TYPES
result = driver.get_lldp_neighbors()
assert sorted(result) == ["eth0.1", "eth1"]
assert result["eth0.1"][0]["hostname"] == "desk-phone"
def test_a_port_given_by_mac_or_local_id_is_read(self, driver):
driver._send_command = lambda cmd, **kw: LLDPCTL_KV_DOTTED_AND_ID_TYPES
result = driver.get_lldp_neighbors()
assert result["eth0.1"][0]["port"] == "00:11:22:33:44:01"
assert result["eth1"][0]["port"] == "gi1/0/7"
def test_a_chassis_given_by_a_local_id_is_read(self, driver):
driver._send_command = lambda cmd, **kw: LLDPCTL_KV_DOTTED_AND_ID_TYPES
switch = driver.get_lldp_neighbors_detail("eth1")["eth1"][0]
assert switch["remote_chassis_id"] == "access-sw-01"
def test_the_detail_carries_description_and_capabilities(self, driver):
driver._send_command = lambda cmd, **kw: LLDPCTL_KV_DOTTED_AND_ID_TYPES
detail = driver.get_lldp_neighbors_detail()
phone = detail["eth0.1"][0]
assert phone["remote_port_description"] == "WAN"
assert phone["remote_system_description"] == "SIP phone"
assert phone["remote_system_enable_capab"] == ["telephone"]
assert detail["eth1"][0]["remote_system_capab"] == ["bridge", "router"]
BRIDGE_VLAN_SHOW = """\
port vlan-id
eth0 1 PVID Egress Untagged