fix(rest): raise on a failed REST read instead of returning {}
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 1m14s
driver / test (3.12) (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 1m10s
driver / lowest (pull_request) Successful in 30s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m10s
CI / driver (pull_request) Successful in 2m49s
driver / publish (pull_request) Skipped

ProcurveApiClient.get() answered {} for a timeout, a refused session or
any HTTP error, so every REST getter reported a failed read as a switch
with no hostname, ports, VLANs or neighbours. get() now raises
ConnectionException (no answer, 401/403) or RuntimeError (other
non-2xx, a body that is not JSON); the getters that expect a resource
to be missing on some firmware pass missing_ok for its 404.

get_config no longer returns an empty configuration when both the REST
read and the SSH fallback failed, and cli() over REST raises instead of
returning "Error: HTTP <status>" as the command's output.

Closes #22
This commit is contained in:
Christian Manivong committed 2026-11-02 08:39:04 +01:00
1 parent 1105c47a3d
commit 628a827cbe
6 files changed
+340 -73

No files matched your search

+11 -13
View File
@@ -631,7 +631,11 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
) -> dict[str, str]:
"""Return device configuration."""
if self._transport == "api":
result = self._api.get_config()
try:
result = self._api.get_config()
except (ConnectionException, RuntimeError) as exc: # SSH reads it, or raises
logger.info("REST config read failed for %s: %s", self.hostname, exc)
result = {}
if result.get("running"):
return result
# REST endpoint not available on this firmware (e.g. HP 2530 / YA series).
@@ -668,9 +672,10 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
return conn.send_command("show running-config")
finally:
conn.disconnect()
except Exception as exc:
logger.warning("SSH config fallback failed for %s: %s", self.hostname, exc)
return ""
except ConnectionException: # a changed host key, say: as it is
raise
except Exception as exc: # a failed read raises (#22)
raise ConnectionException(f"SSH config read failed for {self.hostname}: {exc}") from exc
# ------------------------------------------------------------------
# NAPALM: get_environment
@@ -1137,15 +1142,8 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
def cli(self, commands: list[str], encoding: str = "text") -> dict[str, str]:
"""Execute raw CLI commands and return output dict."""
if self._transport == "api":
# ArubaOS REST API supports CLI via POST /rest/<ver>/cli
results: dict[str, str] = {}
for cmd in commands:
resp = self._api.post("cli", json={"cmd": cmd})
if resp.ok:
results[cmd] = parsers.parse_cli_answer(resp.json())
else:
results[cmd] = f"Error: HTTP {resp.status_code}"
return results
# POST /rest/<ver>/cli; a failed request raises, it is not the command's output
return {cmd: parsers.parse_cli_answer(self._api.run_cli(cmd)) for cmd in commands}
return {cmd: self._send_command(cmd) for cmd in commands}