fix(config): read what retrieve asks in the REST-to-SSH fallback
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 25s
driver / types (pull_request) Successful in 1m15s
driver / test (3.12) (pull_request) Successful in 1m8s
driver / test (3.13) (pull_request) Successful in 1m4s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m9s
CI / driver (pull_request) Successful in 2m54s
driver / publish (pull_request) Skipped

A switch whose REST API has no configuration is read over a temporary
SSH session. That path read the running config only, whatever retrieve
asked for, and returned an empty startup config. It now reads through
the same code as the SSH transport: running and/or startup as asked,
"show config" where "show startup-config" is unknown, and a part that
could not be read raises.

Closes #25
This commit is contained in:
Christian Manivong committed 2026-11-02 09:15:03 +01:00
1 parent f3da8944a3
commit e0ff997d1b
6 files changed
+141 -29

No files matched your search

+23 -25
View File
@@ -638,44 +638,42 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
result = {}
if result.get("running"):
return result
# REST endpoint not available on this firmware (e.g. HP 2530 / YA series).
# HP switches allow only one session per user — close the REST session
# first so the switch accepts the SSH connection.
# No REST config on this firmware (e.g. 2530 / YA series): SSH. One session
# per user, so the REST one is closed first for the switch to accept SSH.
try:
self._api._session.close()
except Exception:
logger.debug("closing the REST session: ignored", exc_info=True)
running = self._get_config_via_ssh()
return {"running": running, "startup": "", "candidate": ""}
return self._get_config_via_ssh(retrieve)
return self._read_config(retrieve)
running = ""
startup = ""
candidate = self._candidate_config or ""
def _read_config(self, retrieve: str) -> dict[str, str]:
"""Running and/or startup config as *retrieve* asks; a part not asked for is ""."""
commands = {
"running": "show running-config",
"startup": ["show startup-config", "show config"],
}
config = {"running": "", "startup": "", "candidate": self._candidate_config or ""}
for part, command in commands.items():
if retrieve in ("all", part):
config[part] = self._send_command(command)
return config
if retrieve in ("all", "running"):
running = self._send_command("show running-config")
if retrieve in ("all", "startup"):
startup = self._send_command(["show startup-config", "show config"])
return {"running": running, "startup": startup, "candidate": candidate}
def _get_config_via_ssh(self) -> str:
"""Retrieve running-config via netmiko on port 22.
HP ProCurve switches do not support exec_channel SSH; they require
an interactive shell (invoke_shell), which netmiko's hp_procurve
device type handles correctly. Port 22: ``port`` is the REST API's.
"""
def _get_config_via_ssh(self, retrieve: str = "running") -> dict[str, str]:
"""The config over a temporary SSH session on port 22 (``port`` is the REST API's)."""
device = self._device
try:
conn = self._ssh_connect(port=_SSH_PORT_BESIDE_API)
self._device = conn = self._ssh_connect(port=_SSH_PORT_BESIDE_API)
try:
return conn.send_command("show running-config")
return self._read_config(retrieve)
finally:
conn.disconnect()
except ConnectionException: # a changed host key, say: as it is
raise
except Exception as exc: # a failed read raises (#22)
except Exception as exc: # a failed read raises (#22, #25)
raise ConnectionException(f"SSH config read failed for {self.hostname}: {exc}") from exc
finally:
self._device = device
# ------------------------------------------------------------------
# NAPALM: get_environment