fix(lldp): shared lldpctl parser; raise on failed LLDP and environment reads #30

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

What

The LLDP getters use napalm-device-types' shared lldpctl parser and LLDP projections (NAPALM/napalm-device-types#78), and the LLDP and environment getters raise on a failed read. Three commits, one per issue. The floor on napalm-device-types rises to 4.24.0.

#26: dotted interface names, port ids by type

  • The local interface was the second dotted part of the key: the neighbours of eth0.1 came back under eth0 with every field empty. It now runs up to the neighbour's first field.
  • The remote port was read from port.ifname or port.id.value; lldpd prints a MAC or local port id as port.mac= / port.local= and never prints id.value, so those ports came back empty. The chassis id is read under any type too (chassis.local, chassis.ip).
  • With the shared projection the detail also carries the system description and capabilities, which were always empty.
  • lldp_mixin is under strict mypy now (dropped from the relaxed list and the baseline).

#27: a failed read raises

  • lldpctl runs as LLDPCTL_KEYVALUE_COMMAND (lldpctl -f keyvalue 2>&1; echo __LLDPCTL_RC=$?). A non-zero status (lldpctl missing, lldpd not running) raises ValueError with lldpctl's message instead of returning {}; {} now means lldpctl ran and listed nobody.
  • get_environment() raises ValueError when /proc/stat gives no two readable cpu lines or /proc/meminfo lacks MemTotal/MemAvailable, instead of 0 % CPU and 0 bytes of memory. 0 % stays for counters that did not move. The #10 test that took a single read as 0 % now expects the raise.

For netOrk: the poll calls get_lldp_neighbors() in try/except Exception (netork/jobs/tasks/poll/_collect.py:108), logs a warning and goes on with no neighbours, so a failure is now logged instead of silent. get_environment() is only called for BMC drivers (_bmc.py), not for OpenWrt.

#31: the neighbour's chassis MAC

get_lldp_neighbors() carries mac (lower case) when the chassis id is a MAC address, as napalm-linux does. netOrk matches a neighbour by it first (netork/core/lldp_neighbors.py:135). The rule lives in device-types' lldp_neighbors projection (second commit of NAPALM/napalm-device-types#78); here the getter returns its LldpNeighborDict.

Tests

Fixtures only (tests/unit/test_driver.py: TestLldpDottedInterfaceAndPortIds, TestLldpFailedRead, TestGetEnvironmentCpu). The #26 tests and the #27 command and environment tests failed before their commit; the "lldpctl not found raises" cases already passed after the #26 commit, because the shared parser refuses output without a single neighbour line. test_the_chassis_mac_is_reported (#31) failed against the first device-types commit and passes with the second. pytest 239 passed, ruff format --check, ruff check, mypy, napalm-standard ratchet within the baseline, 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), 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 #26
Closes #27
Closes #31

## What The LLDP getters use napalm-device-types' shared lldpctl parser and LLDP projections (NAPALM/napalm-device-types#78), and the LLDP and environment getters raise on a failed read. Three commits, one per issue. The floor on napalm-device-types rises to 4.24.0. ### #26: dotted interface names, port ids by type - The local interface was the second dotted part of the key: the neighbours of `eth0.1` came back under `eth0` with every field empty. It now runs up to the neighbour's first field. - The remote port was read from `port.ifname` or `port.id.value`; lldpd prints a MAC or local port id as `port.mac=` / `port.local=` and never prints `id.value`, so those ports came back empty. The chassis id is read under any type too (`chassis.local`, `chassis.ip`). - With the shared projection the detail also carries the system description and capabilities, which were always empty. - `lldp_mixin` is under strict mypy now (dropped from the relaxed list and the baseline). ### #27: a failed read raises - lldpctl runs as `LLDPCTL_KEYVALUE_COMMAND` (`lldpctl -f keyvalue 2>&1; echo __LLDPCTL_RC=$?`). A non-zero status (lldpctl missing, lldpd not running) raises `ValueError` with lldpctl's message instead of returning `{}`; `{}` now means lldpctl ran and listed nobody. - `get_environment()` raises `ValueError` when `/proc/stat` gives no two readable `cpu` lines or `/proc/meminfo` lacks `MemTotal`/`MemAvailable`, instead of 0 % CPU and 0 bytes of memory. 0 % stays for counters that did not move. The #10 test that took a single read as 0 % now expects the raise. For netOrk: the poll calls `get_lldp_neighbors()` in `try/except Exception` (`netork/jobs/tasks/poll/_collect.py:108`), logs a warning and goes on with no neighbours, so a failure is now logged instead of silent. `get_environment()` is only called for BMC drivers (`_bmc.py`), not for OpenWrt. ### #31: the neighbour's chassis MAC `get_lldp_neighbors()` carries `mac` (lower case) when the chassis id is a MAC address, as napalm-linux does. netOrk matches a neighbour by it first (`netork/core/lldp_neighbors.py:135`). The rule lives in device-types' `lldp_neighbors` projection (second commit of NAPALM/napalm-device-types#78); here the getter returns its `LldpNeighborDict`. ## Tests Fixtures only (`tests/unit/test_driver.py`: `TestLldpDottedInterfaceAndPortIds`, `TestLldpFailedRead`, `TestGetEnvironmentCpu`). The #26 tests and the #27 command and environment tests failed before their commit; the "lldpctl not found raises" cases already passed after the #26 commit, because the shared parser refuses output without a single neighbour line. `test_the_chassis_mac_is_reported` (#31) failed against the first device-types commit and passes with the second. `pytest` 239 passed, `ruff format --check`, `ruff check`, `mypy`, `napalm-standard ratchet` within the baseline, 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), 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 #26 Closes #27 Closes #31
christianmanivong added 2 commits 2026-11-02 07:47:54 +00:00
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
fix(getters): raise on a failed LLDP or environment read
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 21s
driver / types (pull_request) Failing after 6s
driver / test (3.12) (pull_request) Failing after 17s
driver / test (3.13) (pull_request) Failing after 15s
driver / lowest (pull_request) Failing after 6s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Failing after 38s
CI / driver (pull_request) Failing after 1m36s
driver / publish (pull_request) Skipped
aafb5636a9
lldpctl's error text has no "=", so a missing lldpctl or a stopped
lldpd read as a device without neighbours. lldpctl now runs as
napalm-device-types' LLDPCTL_KEYVALUE_COMMAND, which brings its exit
status and message back, and the shared parser raises on a failure.

get_environment swallowed an unreadable /proc/stat or /proc/meminfo
and reported 0 % CPU and 0 bytes of memory, a plausible value instead
of a failure. Both now raise ValueError; 0 % stays for counters that
did not move between the two reads.

Closes #27
christianmanivong added 1 commit 2026-11-02 07:51:28 +00:00
fix(lldp): report the neighbour's chassis MAC
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 28s
driver / types (pull_request) Failing after 30s
driver / test (3.13) (pull_request) Failing after 15s
driver / test (3.12) (pull_request) Failing after 17s
driver / lowest (pull_request) Failing after 18s
driver / build (pull_request) Successful in 35s
driver / security (pull_request) Failing after 40s
CI / driver (pull_request) Failing after 1m41s
driver / publish (pull_request) Skipped
071beeb68a
lldpd tells the chassis MAC, but get_lldp_neighbors reported only name
and port, so netOrk, which matches a neighbour by MAC first, could match
OpenWrt's neighbours by name only. napalm-device-types' lldp_neighbors
projection now carries mac (lower case) when the chassis id is a MAC
address, as napalm-linux reports it.

Closes #31
christianmanivong added 1 commit 2026-11-02 10:06:07 +00:00
Merge remote-tracking branch 'origin/main' into fix/lldp-keyvalue
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 1m0s
driver / test (3.12) (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 56s
driver / lowest (pull_request) Successful in 25s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 59s
CI / driver (pull_request) Successful in 2m24s
driver / publish (pull_request) Skipped
f9af7abaf6
christianmanivong merged commit 0380350a4c into main 2026-11-02 11:04:12 +00:00
christianmanivong deleted branch fix/lldp-keyvalue 2026-11-02 11:04:12 +00:00
Sign in to join this conversation.