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.
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.
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.
## 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
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
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.
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What
get_lldp_neighbors()parseslldpctl -f keyvaluewith napalm-device-types' sharedparse_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)
chassis.id.subtype == "mac"/chassis.id.value, keys lldpd never prints (it writeschassis.mac=), somacwas 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.100was cut at its dot.Now every neighbour is its own entry,
macis 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 keeps2>/dev/null || true.#66: a stopped lldpd, a failed read
"active"anywhere in the answer, and systemctl answersinactivefor a stopped lldpd. Theservice ... | grep -q runningfallback also matched a sysvinitnot running. The check is now one command that prints exactlyrunning(systemd has lldpd active, or alldpdprocess runs) orstopped, and that word is compared whole. A missing or stopped lldpd still answers{}.LLDPCTL_KEYVALUE_COMMAND. A failure (socket out of the login's reach, a restarting daemon) raisesValueErrorwith lldpctl's message instead of returning{}. netOrk's poll wrapsget_lldp_neighbors()inexcept Exceptionwith a warning (netork/jobs/tasks/poll/_collect.py:108), so the failure is logged and nothing stored changes.A refactor commit in between takes
macfrom device-types'lldp_neighborsprojection, 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 oneth0, a switch oneth0.100with a local chassis and port id). Six of the #58 tests failed before that change. For #66, the running check is run in a localshwithsystemctl/service/pgrepstubbed (inactive, failed, running, running without systemd);test_a_stopped_lldpd_is_not_asked[inactive],test_lldpctl_is_asked_with_its_exit_statusandtest_an_unreachable_lldpd_raisesfailed first.pytest313 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_keyvalueyet), and thelowestjob needs napalm-device-types 4.24.0 on PyPI. Merge order: device-types #78, release 4.24.0, then this.Closes #58
Closes #66
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