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

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
This commit is contained in:
Christian Manivong committed 2026-11-02 10:58:14 +01:00
1 parent 5f0c7c76b3
commit e5ce4e32b1
5 files changed
+74 -5

No files matched your search

+7 -1
View File
@@ -219,7 +219,13 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
self._device_info = None
def is_alive(self) -> dict[str, bool]:
"""Check if the device is reachable via TCP connection."""
"""Whether this driver's session is open and the gateway still answers on its port.
Without an open session (never opened, or closed) it is not alive, and no
connection is made: NAPALM's ``__del__`` asks this of every collected driver (#19).
"""
if self._session is None or self._sessionkey is None:
return {"is_alive": False}
try:
sock = socket.create_connection((self.hostname, self.port), timeout=5)
sock.close()