fix(lldp): list every neighbour of a port, with its chassis MAC
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 15s
driver / test (3.12) (pull_request) Failing after 48s
driver / types (pull_request) Failing after 1m0s
driver / lowest (pull_request) Failing after 22s
driver / test (3.13) (pull_request) Failing after 48s
driver / build (pull_request) Successful in 38s
driver / security (pull_request) Failing after 1m20s
CI / driver (pull_request) Failing after 2m46s
driver / publish (pull_request) Skipped

lldpctl -f keyvalue was grouped by interface, so a second neighbour on a
port overwrote the first. The driver looked for chassis.id.value and
port.id.value, keys lldpd never prints (it names an id by its type,
chassis.mac, port.local), so the chassis MAC was never reported and a
port given by MAC or local id came back empty; and eth0.100 was cut at
its dot. The output now goes through napalm-device-types'
parse_lldpctl_keyvalue, which splits neighbours at their via line and
keeps the interface name whole; the floor on napalm-device-types rises
to 4.24.0 for it.

Closes #58
This commit is contained in:
Christian Manivong committed 2026-11-02 08:44:15 +01:00
1 parent 5687f5d9a1
commit 3d2de27988
5 files changed
+150 -29

No files matched your search

+14 -27
View File
@@ -50,6 +50,7 @@ from napalm_device_types import (
open_stream_on_transport,
parse_apt_upgradable,
parse_dnf_security,
parse_lldpctl_keyvalue,
run_fix_steps,
run_on_transport,
strip_terminal_codes,
@@ -127,6 +128,10 @@ _DNF_RC_RE = re.compile(r"^__DNF_RC=(\d+)\s*$", re.MULTILINE)
#: Restart the host two seconds later, detached from this session: the launcher's
#: exit status comes back before the host goes down, and closing the session
#: cannot take the restart with it.
#: lldpd's neighbours; a failure prints nothing and reads as none, as before (#58).
_LLDPCTL_COMMAND = "lldpctl -f keyvalue 2>/dev/null || true"
#: A chassis id lldpd names ``mac`` that really is one.
_MAC_RE = re.compile(r"^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$")
_REBOOT_DETACHED = "sh -c '(trap \"\" HUP; sleep 2; /sbin/reboot) </dev/null >/dev/null 2>&1 &'"
#: Why ``run_command`` refuses stdin to a privileged command while a sudo
@@ -763,7 +768,9 @@ class LinuxDriver(
def get_lldp_neighbors(self) -> dict[str, list[dict[str, Any]]]:
"""Return LLDP neighbors if lldpd is installed and currently running.
Uses ``lldpctl -f keyvalue``. Returns an empty dict when lldpd is
Uses ``lldpctl -f keyvalue``, parsed by napalm-device-types: every
neighbour of a port is its own entry, and one whose chassis id is a MAC
address carries it as ``mac``. Returns an empty dict when lldpd is
absent or stopped — does NOT attempt to start the daemon.
"""
# Check lldpctl is available
@@ -779,33 +786,13 @@ class LinuxDriver(
if "active" not in running:
return {}
output = self._send("lldpctl -f keyvalue 2>/dev/null || true")
output = self._send(_LLDPCTL_COMMAND)
neighbors: dict[str, list[dict[str, Any]]] = {}
entries: dict[str, dict[str, str]] = {}
for line in output.splitlines():
line = line.strip()
if "=" not in line:
continue
key, _, value = line.partition("=")
parts = key.split(".")
if len(parts) < 3 or parts[0] != "lldp":
continue
iface = parts[1]
subkey = ".".join(parts[2:])
entries.setdefault(iface, {})[subkey] = value
for iface, data in entries.items():
entry = {
"hostname": data.get("chassis.name", ""),
"port": data.get("port.ifname", data.get("port.id.value", "")),
}
if data.get("chassis.id.subtype") == "mac":
mac = data.get("chassis.id.value", "")
if re.match(r"^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$", mac):
entry["mac"] = mac.lower()
neighbors.setdefault(iface, []).append(entry)
for row in parse_lldpctl_keyvalue(output):
entry: dict[str, Any] = {"hostname": row["system_name"], "port": row["port_id"]}
if row["chassis_id_type"] == "mac" and _MAC_RE.match(row["chassis_id"]):
entry["mac"] = row["chassis_id"].lower()
neighbors.setdefault(row["local_port"], []).append(entry)
return neighbors
def get_interfaces(self) -> dict[str, Any]: