A failed read over the REST API raises instead of reading as an empty switch.
ProcurveApiClient.get() raises ConnectionException when the switch does not answer or refuses the session (HTTP 401/403), and RuntimeError with the status for any other non-2xx answer or a body that is not JSON. It returned {} for all of them.
A getter that expects a resource to be missing on some firmware or configuration says so with get(..., missing_ok=True), and only a 404 reads as empty there: system/status (stacked switches fall back to system/status/global_info), dns, system/status/switch, port-statistics, vlans/<id>/ipv4, poe/ports. Every other read (ports, vlans, vlans-ports, arp, mac-table, lldp/remote-device, ntp/server, system/status/global_info) raises.
get_interfaces no longer swallows every error from system/status/switch (only its 404).
get_config: a failed REST read still falls back to SSH, but when the SSH read fails too it raises instead of returning an empty running configuration. A changed SSH host key keeps its own exception type.
cli() over REST goes through the new ProcurveApiClient.run_cli() and raises on a failed request. It returned "Error: HTTP <status>" as the command's output.
Why
An expired session cookie, a timeout or an HTTP 500 produced a switch with an empty hostname, no ports, no VLANs and no neighbours, and the application stored that as the switch's state.
Tests
Fixtures only (no device). tests/unit/test_rest_failed_reads.py drives the real ProcurveApiClient against a fake session that answers per endpoint: 500/401/403/timeout/non-JSON on get(), every REST getter with its primary read answering 500, each missing_ok resource answering 404, get_config with REST and SSH failing, and cli() with 500/401/connection refused. The first of them (test_get_interfaces_raises_when_ports_answers_500) failed before the change. The cli() test that pinned "Error: HTTP 401" as output is replaced by these.
## What
A failed read over the REST API raises instead of reading as an empty switch.
- `ProcurveApiClient.get()` raises `ConnectionException` when the switch does not answer or refuses the session (HTTP 401/403), and `RuntimeError` with the status for any other non-2xx answer or a body that is not JSON. It returned `{}` for all of them.
- A getter that expects a resource to be missing on some firmware or configuration says so with `get(..., missing_ok=True)`, and only a 404 reads as empty there: `system/status` (stacked switches fall back to `system/status/global_info`), `dns`, `system/status/switch`, `port-statistics`, `vlans/<id>/ipv4`, `poe/ports`. Every other read (`ports`, `vlans`, `vlans-ports`, `arp`, `mac-table`, `lldp/remote-device`, `ntp/server`, `system/status/global_info`) raises.
- `get_interfaces` no longer swallows every error from `system/status/switch` (only its 404).
- `get_config`: a failed REST read still falls back to SSH, but when the SSH read fails too it raises instead of returning an empty running configuration. A changed SSH host key keeps its own exception type.
- `cli()` over REST goes through the new `ProcurveApiClient.run_cli()` and raises on a failed request. It returned `"Error: HTTP <status>"` as the command's output.
## Why
An expired session cookie, a timeout or an HTTP 500 produced a switch with an empty hostname, no ports, no VLANs and no neighbours, and the application stored that as the switch's state.
## Tests
Fixtures only (no device). `tests/unit/test_rest_failed_reads.py` drives the real `ProcurveApiClient` against a fake session that answers per endpoint: 500/401/403/timeout/non-JSON on `get()`, every REST getter with its primary read answering 500, each `missing_ok` resource answering 404, `get_config` with REST and SSH failing, and `cli()` with 500/401/connection refused. The first of them (`test_get_interfaces_raises_when_ports_answers_500`) failed before the change. The cli() test that pinned `"Error: HTTP 401"` as output is replaced by these.
pytest 149 passed, ruff format/check clean, mypy clean, `napalm-standard ratchet` within the baseline (tightened: `get_interfaces` 65→62 lines / complexity 15→14, `procurve.py` 1387→1385 lines), `napalm-standard check` passes.
Not changed: there is no re-login after a 401 within one session; the next `open()` starts a new one.
Closes #22
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What
A failed read over the REST API raises instead of reading as an empty switch.
ProcurveApiClient.get()raisesConnectionExceptionwhen the switch does not answer or refuses the session (HTTP 401/403), andRuntimeErrorwith the status for any other non-2xx answer or a body that is not JSON. It returned{}for all of them.get(..., missing_ok=True), and only a 404 reads as empty there:system/status(stacked switches fall back tosystem/status/global_info),dns,system/status/switch,port-statistics,vlans/<id>/ipv4,poe/ports. Every other read (ports,vlans,vlans-ports,arp,mac-table,lldp/remote-device,ntp/server,system/status/global_info) raises.get_interfacesno longer swallows every error fromsystem/status/switch(only its 404).get_config: a failed REST read still falls back to SSH, but when the SSH read fails too it raises instead of returning an empty running configuration. A changed SSH host key keeps its own exception type.cli()over REST goes through the newProcurveApiClient.run_cli()and raises on a failed request. It returned"Error: HTTP <status>"as the command's output.Why
An expired session cookie, a timeout or an HTTP 500 produced a switch with an empty hostname, no ports, no VLANs and no neighbours, and the application stored that as the switch's state.
Tests
Fixtures only (no device).
tests/unit/test_rest_failed_reads.pydrives the realProcurveApiClientagainst a fake session that answers per endpoint: 500/401/403/timeout/non-JSON onget(), every REST getter with its primary read answering 500, eachmissing_okresource answering 404,get_configwith REST and SSH failing, andcli()with 500/401/connection refused. The first of them (test_get_interfaces_raises_when_ports_answers_500) failed before the change. The cli() test that pinned"Error: HTTP 401"as output is replaced by these.pytest 149 passed, ruff format/check clean, mypy clean,
napalm-standard ratchetwithin the baseline (tightened:get_interfaces65→62 lines / complexity 15→14,procurve.py1387→1385 lines),napalm-standard checkpasses.Not changed: there is no re-login after a 401 within one session; the next
open()starts a new one.Closes #22
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