fix(connect): name a full switch and a web page, not a bad password
A switch whose Telnet sessions were all taken, and a REST API answering the login with the web UI's HTML page, were both reported as an authentication failure, which sent the operator after the password. The Telnet login now keeps the switch's greeting in an in-memory session log and reports a full switch as a connection error; an HTML answer to the REST login says so. An SSH attempt records netmiko's underlying error instead of "timed out" when it was not a timeout. Session log objects need netmiko 4.3.0, which becomes the floor. Closes #13
This commit is contained in:
1 parent
874e25a1ce
commit
ee49948b2b
7 files changed
+233
-12
No files matched your search
@@ -42,13 +42,11 @@ from napalm_device_types.ssh_host_keys import (
|
||||
SshHostKeyMismatch,
|
||||
)
|
||||
from netmiko import ConnectHandler
|
||||
from netmiko.exceptions import (
|
||||
NetmikoAuthenticationException,
|
||||
NetmikoTimeoutException,
|
||||
)
|
||||
from netmiko.exceptions import NetmikoAuthenticationException
|
||||
|
||||
from napalm_procurve import parsers
|
||||
from napalm_procurve.api_client import ProcurveApiClient
|
||||
from napalm_procurve.connect_reasons import NO_FREE_TELNET_SESSION, TelnetTranscript, failure_reason
|
||||
|
||||
logger = logging.getLogger("napalm_procurve")
|
||||
|
||||
@@ -363,18 +361,15 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
||||
raise
|
||||
except NetmikoAuthenticationException as exc:
|
||||
raise self._auth_failure(transport, exc) from exc
|
||||
except NetmikoTimeoutException:
|
||||
logger.debug("%s timeout for %s", label, self.hostname)
|
||||
self._attempts.append(f"{transport}: timed out")
|
||||
return False
|
||||
except Exception as exc:
|
||||
logger.debug("%s failed for %s: %s", label, self.hostname, exc)
|
||||
self._attempts.append(f"{transport}: {exc}")
|
||||
self._attempts.append(f"{transport}: {failure_reason(exc)}")
|
||||
return False
|
||||
|
||||
def _try_telnet(self) -> bool:
|
||||
"""Probe and connect via Telnet. Returns True on success."""
|
||||
logger.debug("Trying Telnet for %s", self.hostname)
|
||||
transcript = TelnetTranscript() # a full switch refuses before the login (#13)
|
||||
try:
|
||||
conn = ConnectHandler(
|
||||
device_type=self.NETMIKO_DEVICE_TYPE_TELNET,
|
||||
@@ -384,13 +379,17 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
||||
secret=self._secret,
|
||||
port=self.telnet_port,
|
||||
timeout=self.timeout,
|
||||
session_log=transcript,
|
||||
)
|
||||
self._device = conn
|
||||
self._transport = "telnet"
|
||||
logger.info("Connected to %s via Telnet", self.hostname)
|
||||
return True
|
||||
except NetmikoAuthenticationException as exc:
|
||||
raise self._auth_failure("telnet", exc) from exc
|
||||
if not transcript.no_free_session:
|
||||
raise self._auth_failure("telnet", exc) from exc
|
||||
self._attempts.append(f"telnet: {NO_FREE_TELNET_SESSION}")
|
||||
return False
|
||||
except Exception as exc:
|
||||
logger.debug("Telnet failed for %s: %s", self.hostname, exc)
|
||||
self._attempts.append(f"telnet: {exc}")
|
||||
|
||||
Reference in new issue
Block a user