feat: open() waits out sshd's per-source penalty (NetOrk/netork#1800)
driver / lint (pull_request) Successful in 15s
driver / standard (pull_request) Failing after 15s
driver / types (pull_request) Successful in 1m3s
driver / test (3.13) (pull_request) Failing after 59s
driver / test (3.12) (pull_request) Failing after 1m9s
driver / lowest (pull_request) Failing after 28s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Failing after 2m17s
driver / publish (pull_request) Skipped

OpenSSH 9.8+ closes every connection from a source it has just
penalised, before its banner, for seconds to minutes. open() now wraps
netmiko's ConnectHandler in napalm-device-types' retry_refused, so the
connection is tried again after 1, 3, 7 and 15 s instead of failing.
Needs NAPALM/napalm-device-types#63.
This commit is contained in:
Christian Manivong committed 2026-11-01 00:26:47 +01:00
1 parent 7550b884b0
commit 49b7d7fef7
3 files changed
+47 -10

No files matched your search

+27
View File
@@ -86,3 +86,30 @@ def test_a_changed_key_is_refused():
driver.open()
assert driver._device is None
assert seen[0]["accepted"] is False
def test_a_connection_sshd_turns_away_is_tried_again(monkeypatch):
"""OpenSSH 9.8+ closes every connection from a source it has just penalised,
before its banner; the penalty ends after seconds (NetOrk/netork#1800)."""
from napalm_device_types import ssh_host_keys
slept: list[float] = []
monkeypatch.setattr(ssh_host_keys.time, "sleep", slept.append)
attempts: list[int] = []
def turned_away(**kwargs):
attempts.append(1)
if len(attempts) < 3:
try:
raise paramiko.SSHException("Error reading SSH protocol banner")
except paramiko.SSHException as exc:
raise NetmikoTimeoutException(f"A paramiko SSHException occurred: {exc}") from exc
return _device()
driver = _driver([])
with patch("napalm_linux.linux.ConnectHandler", side_effect=turned_away):
driver.open()
assert driver._device is not None
assert len(attempts) == 3
assert slept == list(ssh_host_keys.REFUSED_RETRY_WAITS[:2])