fix(session): report is_alive from the driver's own session #20

Merged
christianmanivong merged 1 commits from fix/bugs-2026-11-02d into main 2026-11-02 10:05:26 +00:00
Owner

What

is_alive() reports from the driver's own session, as in napalm-fritzbox (fc is None):

  • Without an open session (never opened, or after close(), i.e. _session or _sessionkey is unset) it returns {"is_alive": False} and makes no connection.
  • With an open session it reports whether the gateway still answers on its web port: the same TCP check as before, now only while there is a session to check.

The README row for is_alive says the same.

Why

is_alive() connected to the gateway in every case. NAPALM's NetworkDriver.__del__ asks it of every collected driver, so each one connected once more and could stall for up to five seconds in __del__. netOrk drops a driver after every poll.

Tests

Fixtures only (no device). tests/test_is_alive.py:

  • a never-opened and a closed driver: False, and socket.create_connection is not called (both failed before the change);
  • an open session with the port answering: True;
  • an open session with the connection refused: False.

The is_alive tests in test_zyxel.py now give the driver a mock session first. The session-wide no-socket guard from #18 stays green. pytest 70 passed, ruff format/check clean, mypy clean, napalm-standard check passes, napalm-standard ratchet within the baseline.

Closes #19

## What `is_alive()` reports from the driver's own session, as in napalm-fritzbox (`fc is None`): - Without an open session (never opened, or after `close()`, i.e. `_session` or `_sessionkey` is unset) it returns `{"is_alive": False}` and makes no connection. - With an open session it reports whether the gateway still answers on its web port: the same TCP check as before, now only while there is a session to check. The README row for `is_alive` says the same. ## Why `is_alive()` connected to the gateway in every case. NAPALM's `NetworkDriver.__del__` asks it of every collected driver, so each one connected once more and could stall for up to five seconds in `__del__`. netOrk drops a driver after every poll. ## Tests Fixtures only (no device). `tests/test_is_alive.py`: - a never-opened and a closed driver: `False`, and `socket.create_connection` is not called (both failed before the change); - an open session with the port answering: `True`; - an open session with the connection refused: `False`. The `is_alive` tests in `test_zyxel.py` now give the driver a mock session first. The session-wide no-socket guard from #18 stays green. pytest 70 passed, ruff format/check clean, mypy clean, `napalm-standard check` passes, `napalm-standard ratchet` within the baseline. Closes #19
christianmanivong added 1 commit 2026-11-02 09:58:23 +00:00
fix(session): report is_alive from the driver's own session
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m3s
driver / lowest (pull_request) Successful in 34s
driver / test (3.13) (pull_request) Successful in 1m9s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m12s
CI / driver (pull_request) Successful in 2m53s
driver / publish (pull_request) Skipped
e5ce4e32b1
is_alive() opened a TCP connection to the gateway whether or not the
driver was opened, and after close() too. NAPALM's __del__ asks it of
every collected driver, so each one connected once more and could stall
for up to five seconds. Without an open session it now answers False
and connects nowhere; with one, it reports whether the gateway still
answers on its port.

Closes #19
christianmanivong merged commit ca8d02233a into main 2026-11-02 10:05:26 +00:00
christianmanivong deleted branch fix/bugs-2026-11-02d 2026-11-02 10:05:26 +00:00
Sign in to join this conversation.