fix(lldp): list every neighbour of a port, with its chassis MAC #62

Merged
christianmanivong merged 4 commits from fix/lldp-keyvalue into main 2026-11-02 11:03:06 +00:00
Owner

What

get_lldp_neighbors() parses lldpctl -f keyvalue with napalm-device-types' shared parse_lldpctl_keyvalue (NAPALM/napalm-device-types#78) instead of its own loop. The floor on napalm-device-types rises to 4.24.0.

Why (#58)

  • Lines were grouped by interface, so a second neighbour on a port (a phone and the PC behind it, an unmanaged switch) overwrote the first.
  • The chassis MAC was looked up as chassis.id.subtype == "mac" / chassis.id.value, keys lldpd never prints (it writes chassis.mac=), so mac was never set; netOrk resolves a neighbour by that MAC first. A port id given as MAC or local id (port.mac=, port.local=) came back empty.
  • eth0.100 was cut at its dot.

Now every neighbour is its own entry, mac is set (lower case) when the chassis id is a MAC address, the port is read whatever its id type, and the interface name stays whole. Behaviour without lldpd (not installed, not running) is unchanged: {}; the lldpctl call itself keeps 2>/dev/null || true.

#66: a stopped lldpd, a failed read

  • The running check looked for "active" anywhere in the answer, and systemctl answers inactive for a stopped lldpd. The service ... | grep -q running fallback also matched a sysvinit not running. The check is now one command that prints exactly running (systemd has lldpd active, or a lldpd process runs) or stopped, and that word is compared whole. A missing or stopped lldpd still answers {}.
  • With lldpd running, lldpctl runs as LLDPCTL_KEYVALUE_COMMAND. A failure (socket out of the login's reach, a restarting daemon) raises ValueError with lldpctl's message instead of returning {}. netOrk's poll wraps get_lldp_neighbors() in except Exception with a warning (netork/jobs/tasks/poll/_collect.py:108), so the failure is logged and nothing stored changes.

A refactor commit in between takes mac from device-types' lldp_neighbors projection, which now applies the same rule (lower case, only for a MAC chassis id), so linux and openwrt report neighbours the same way.

Tests

tests/test_lldp.py, fixtures only (keyvalue output laid out per lldpd's source: two neighbours on eth0, a switch on eth0.100 with a local chassis and port id). Six of the #58 tests failed before that change. For #66, the running check is run in a local sh with systemctl/service/pgrep stubbed (inactive, failed, running, running without systemd); test_a_stopped_lldpd_is_not_asked[inactive], test_lldpctl_is_asked_with_its_exit_status and test_an_unreachable_lldpd_raises failed first. pytest 313 passed, ruff format --check, ruff check, mypy, napalm-standard ratchet (baseline: linux.py shrank, 2142 -> 2122 lines), all run against the device-types branch of NAPALM/napalm-device-types#78.

CI stays red until NAPALM/napalm-device-types#78 is merged (CI installs napalm-device-types from git main, which has no parse_lldpctl_keyvalue yet), and the lowest job needs napalm-device-types 4.24.0 on PyPI. Merge order: device-types #78, release 4.24.0, then this.

Closes #58
Closes #66

## What `get_lldp_neighbors()` parses `lldpctl -f keyvalue` with napalm-device-types' shared `parse_lldpctl_keyvalue` (NAPALM/napalm-device-types#78) instead of its own loop. The floor on napalm-device-types rises to 4.24.0. ## Why (#58) - Lines were grouped by interface, so a second neighbour on a port (a phone and the PC behind it, an unmanaged switch) overwrote the first. - The chassis MAC was looked up as `chassis.id.subtype == "mac"` / `chassis.id.value`, keys lldpd never prints (it writes `chassis.mac=`), so `mac` was never set; netOrk resolves a neighbour by that MAC first. A port id given as MAC or local id (`port.mac=`, `port.local=`) came back empty. - `eth0.100` was cut at its dot. Now every neighbour is its own entry, `mac` is set (lower case) when the chassis id is a MAC address, the port is read whatever its id type, and the interface name stays whole. Behaviour without lldpd (not installed, not running) is unchanged: `{}`; the lldpctl call itself keeps `2>/dev/null || true`. ### #66: a stopped lldpd, a failed read - The running check looked for `"active"` anywhere in the answer, and systemctl answers `inactive` for a stopped lldpd. The `service ... | grep -q running` fallback also matched a sysvinit `not running`. The check is now one command that prints exactly `running` (systemd has lldpd active, or a `lldpd` process runs) or `stopped`, and that word is compared whole. A missing or stopped lldpd still answers `{}`. - With lldpd running, lldpctl runs as `LLDPCTL_KEYVALUE_COMMAND`. A failure (socket out of the login's reach, a restarting daemon) raises `ValueError` with lldpctl's message instead of returning `{}`. netOrk's poll wraps `get_lldp_neighbors()` in `except Exception` with a warning (`netork/jobs/tasks/poll/_collect.py:108`), so the failure is logged and nothing stored changes. A refactor commit in between takes `mac` from device-types' `lldp_neighbors` projection, which now applies the same rule (lower case, only for a MAC chassis id), so linux and openwrt report neighbours the same way. ## Tests `tests/test_lldp.py`, fixtures only (keyvalue output laid out per lldpd's source: two neighbours on `eth0`, a switch on `eth0.100` with a local chassis and port id). Six of the #58 tests failed before that change. For #66, the running check is run in a local `sh` with `systemctl`/`service`/`pgrep` stubbed (inactive, failed, running, running without systemd); `test_a_stopped_lldpd_is_not_asked[inactive]`, `test_lldpctl_is_asked_with_its_exit_status` and `test_an_unreachable_lldpd_raises` failed first. `pytest` 313 passed, `ruff format --check`, `ruff check`, `mypy`, `napalm-standard ratchet` (baseline: linux.py shrank, 2142 -> 2122 lines), all run against the device-types branch of NAPALM/napalm-device-types#78. **CI stays red until NAPALM/napalm-device-types#78 is merged** (CI installs napalm-device-types from git main, which has no `parse_lldpctl_keyvalue` yet), and the `lowest` job needs napalm-device-types 4.24.0 on PyPI. Merge order: device-types #78, release 4.24.0, then this. Closes #58 Closes #66
christianmanivong added 1 commit 2026-11-02 07:44:28 +00:00
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
3d2de27988
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
christianmanivong added 2 commits 2026-11-02 07:53:52 +00:00
napalm-device-types' lldp_neighbors now carries the chassis MAC as mac
when the chassis id is a MAC address, the rule this driver applied
itself. The getter uses the projection, so linux and openwrt report
neighbours the same way.
fix(lldp): recognise a stopped lldpd and raise on a failed read
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 15s
driver / test (3.12) (pull_request) Failing after 57s
driver / types (pull_request) Failing after 1m7s
driver / test (3.13) (pull_request) Failing after 50s
driver / lowest (pull_request) Failing after 23s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Failing after 1m9s
CI / driver (pull_request) Failing after 2m35s
driver / publish (pull_request) Skipped
d3189806d3
The running check looked for "active" anywhere in the answer, and
systemctl answers "inactive" for a stopped lldpd, so lldpctl was asked
anyway. The check now prints one word, running or stopped, and is
compared whole. With lldpd running, lldpctl runs as napalm-device-types'
LLDPCTL_KEYVALUE_COMMAND: a failure (socket out of the login's reach, a
daemon restarting) raises with lldpctl's message instead of reading as
a host without neighbours. A missing or stopped lldpd still answers {}.

Closes #66
christianmanivong added 1 commit 2026-11-02 08:29:09 +00:00
Merge remote-tracking branch 'origin/main' into fix/lldp-keyvalue
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 20s
driver / types (pull_request) Successful in 1m8s
driver / test (3.13) (pull_request) Successful in 58s
driver / test (3.12) (pull_request) Successful in 1m6s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Successful in 1m3s
CI / driver (pull_request) Successful in 2m21s
driver / publish (pull_request) Skipped
c7317925ed
# Conflicts:
#	CHANGELOG.md
#	tests/quality_baseline.json
christianmanivong merged commit cb0e308a78 into main 2026-11-02 11:03:06 +00:00
christianmanivong deleted branch fix/lldp-keyvalue 2026-11-02 11:03:06 +00:00
Sign in to join this conversation.