fix(lldp): read lldpd through the shared parser and raise on failure #46

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

What

The LLDP getters read lldpd through napalm-device-types' shared parser (NAPALM/napalm-device-types#78) instead of parsing lldpcli show neighbors text:

  • the node runs LLDPCTL_KEYVALUE_COMMAND (lldpctl -f keyvalue 2>&1; echo __LLDPCTL_RC=$?) through _exec_ssh_command (only called, the transport is unchanged)
  • parse_lldpctl_keyvalue gives one row per neighbour; lldp_neighbors / lldp_neighbors_detail project them
  • the floor on napalm-device-types rises to 4.24.0; lldp_mixin is under strict mypy now (dropped from the relaxed list and the baseline, with its 52-line function)

Why (#44)

  • 2>/dev/null || true turned every failure (lldpd not running, lldpctl missing, the command not running at all) into "no neighbours". Now a non-zero lldpctl status raises ValueError with lldpctl's message, and an empty answer raises too: the command always prints its exit status, so nothing at all means it never ran. {} only when lldpctl ran and listed nobody.
  • Capabilities were lldpd's symbols lower-cased (tel, wlan, docsis); they are NAPALM's names now (telephone, wlan-access-point, docsis-cable-device). bridge stays bridge, so _find_switch_uplink keeps finding the switch.
  • On the way: a neighbour named by its chassis MAC carries mac in get_lldp_neighbors (netOrk matches neighbours by it first), and the detail gains the system description.

For callers: _find_switch_uplink (sdn_mixin.py) already wraps both getters in try/except and falls through to "no uplink found", as with an empty result. netOrk's poll wraps get_lldp_neighbors() in except Exception with a warning (netork/jobs/tasks/poll/_collect.py:108), so a failure is now logged; what is stored does not change.

Tests

Fixtures only. tests/test_lldp.py uses keyvalue output laid out per lldpd's source (two neighbours on eno1, a phone with Tel, a switch, an AP with Wlan); it covers the projections, the capability names, the command sent, lldpctl failing, lldpctl missing and an empty answer. All 13 new or changed tests failed before the change. TestLLDPNeighbors in test_misc.py now feeds keyvalue output through a patched _exec_ssh_command. pytest 505 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.

fix/bugs-2026-11-02 (#17) also edits TestLLDPNeighbors.test_empty_when_no_lldp in tests/test_misc.py, so whichever merges second gets a small conflict there. Keep this branch's version: it patches _exec_ssh_command and works with either transport.

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 #44

## What The LLDP getters read lldpd through napalm-device-types' shared parser (NAPALM/napalm-device-types#78) instead of parsing `lldpcli show neighbors` text: - the node runs `LLDPCTL_KEYVALUE_COMMAND` (`lldpctl -f keyvalue 2>&1; echo __LLDPCTL_RC=$?`) through `_exec_ssh_command` (only called, the transport is unchanged) - `parse_lldpctl_keyvalue` gives one row per neighbour; `lldp_neighbors` / `lldp_neighbors_detail` project them - the floor on napalm-device-types rises to 4.24.0; `lldp_mixin` is under strict mypy now (dropped from the relaxed list and the baseline, with its 52-line function) ## Why (#44) - `2>/dev/null || true` turned every failure (lldpd not running, lldpctl missing, the command not running at all) into "no neighbours". Now a non-zero lldpctl status raises `ValueError` with lldpctl's message, and an empty answer raises too: the command always prints its exit status, so nothing at all means it never ran. `{}` only when lldpctl ran and listed nobody. - Capabilities were lldpd's symbols lower-cased (`tel`, `wlan`, `docsis`); they are NAPALM's names now (`telephone`, `wlan-access-point`, `docsis-cable-device`). `bridge` stays `bridge`, so `_find_switch_uplink` keeps finding the switch. - On the way: a neighbour named by its chassis MAC carries `mac` in `get_lldp_neighbors` (netOrk matches neighbours by it first), and the detail gains the system description. For callers: `_find_switch_uplink` (`sdn_mixin.py`) already wraps both getters in `try/except` and falls through to "no uplink found", as with an empty result. netOrk's poll wraps `get_lldp_neighbors()` in `except Exception` with a warning (`netork/jobs/tasks/poll/_collect.py:108`), so a failure is now logged; what is stored does not change. ## Tests Fixtures only. `tests/test_lldp.py` uses keyvalue output laid out per lldpd's source (two neighbours on `eno1`, a phone with `Tel`, a switch, an AP with `Wlan`); it covers the projections, the capability names, the command sent, lldpctl failing, lldpctl missing and an empty answer. All 13 new or changed tests failed before the change. `TestLLDPNeighbors` in `test_misc.py` now feeds keyvalue output through a patched `_exec_ssh_command`. `pytest` 505 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. `fix/bugs-2026-11-02` (#17) also edits `TestLLDPNeighbors.test_empty_when_no_lldp` in `tests/test_misc.py`, so whichever merges second gets a small conflict there. Keep this branch's version: it patches `_exec_ssh_command` and works with either transport. **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 #44
christianmanivong added 1 commit 2026-11-02 07:56:24 +00:00
fix(lldp): read lldpd through the shared parser and raise on failure
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Failing after 29s
driver / test (3.12) (pull_request) Failing after 20s
driver / test (3.13) (pull_request) Failing after 17s
driver / lowest (pull_request) Failing after 18s
driver / security (pull_request) Failing after 45s
driver / build (pull_request) Successful in 35s
CI / driver (pull_request) Failing after 1m43s
driver / publish (pull_request) Skipped
f93daa381e
lldpcli's text was read with 2>/dev/null || true, so lldpd not running,
lldpctl missing or the command not running at all came back as a node
without neighbours. Capabilities were lldpd's symbols lower-cased (tel,
wlan, docsis) rather than NAPALM's names.

The node now runs napalm-device-types' LLDPCTL_KEYVALUE_COMMAND, whose
output carries lldpctl's exit status; parse_lldpctl_keyvalue raises on a
failure, an empty answer raises too, and the lldp_neighbors projections
give NAPALM's capability names and the chassis MAC. The module is under
strict mypy now; the floor on napalm-device-types rises to 4.24.0.

Closes #44
christianmanivong added 1 commit 2026-11-02 08:29:45 +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 15s
driver / test (3.12) (pull_request) Failing after 17s
driver / types (pull_request) Failing after 27s
driver / test (3.13) (pull_request) Failing after 15s
driver / lowest (pull_request) Failing after 18s
driver / security (pull_request) Failing after 37s
driver / build (pull_request) Successful in 33s
CI / driver (pull_request) Failing after 1m39s
driver / publish (pull_request) Skipped
4ffe93fe4c
# Conflicts:
#	README.md
#	tests/test_misc.py
christianmanivong added 1 commit 2026-11-02 10:08:12 +00:00
Merge remote-tracking branch 'origin/main' into fix/lldp-keyvalue
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 58s
driver / test (3.12) (pull_request) Successful in 1m6s
driver / test (3.13) (pull_request) Successful in 57s
driver / lowest (pull_request) Successful in 31s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m9s
CI / driver (pull_request) Successful in 2m44s
driver / publish (pull_request) Skipped
7259c842e3
christianmanivong merged commit 321cef3426 into main 2026-11-02 11:06:19 +00:00
christianmanivong deleted branch fix/lldp-keyvalue 2026-11-02 11:06:19 +00:00
Sign in to join this conversation.