REST transport: ProcurveApiClient.get() returns {} on any error, so every REST getter reports a failed read as empty #22

Closed
opened 2026-11-01 21:44:46 +00:00 by christianmanivong · 0 comments
Owner

What happens

ProcurveApiClient.get() (napalm_procurve/api_client.py 171-186) returns parsed JSON or, on any non-2xx status or exception, logs and returns {}:

"""GET ``{base_url}{endpoint}`` and return parsed JSON (or empty dict)."""
...
logger.warning("GET %s error: %s", url, exc)

Every REST getter builds its answer from it — get_facts (system.get("name", ""), line 217), interfaces (ports_data = self.get("ports"), line 256), counters, VLANs, LLDP — so an expired session cookie, a timeout or an HTTP 500 produces a switch with an empty hostname, no ports, no VLANs and no neighbours instead of an error. netOrk stores those answers as the switch's state.

(get_snmp_communities / configure_snmp_community use the same get(); they are dead code per #12, and #10 proposes using get_snmp_communities on the REST transport — its endpoint snmp-server/community and the snmp_community_element key should be checked against a real switch's REST API before that, since an error there would also read as "no communities".)

Expected

get() raises ConnectionException (connection error, 401/403 after re-login) or a RuntimeError with the status for other non-2xx answers; a 404 for an optional resource is handled by the caller that expects it. Test-first: get("ports") answering 500 makes get_interfaces() raise.

Priority: P3 — wrong (empty) switch state in netOrk after any transient REST error.

Found during the bug sweep of 2026-11-01.

## What happens `ProcurveApiClient.get()` (`napalm_procurve/api_client.py` 171-186) returns parsed JSON or, on any non-2xx status or exception, logs and returns `{}`: ```python """GET ``{base_url}{endpoint}`` and return parsed JSON (or empty dict).""" ... logger.warning("GET %s error: %s", url, exc) ``` Every REST getter builds its answer from it — `get_facts` (`system.get("name", "")`, line 217), interfaces (`ports_data = self.get("ports")`, line 256), counters, VLANs, LLDP — so an expired session cookie, a timeout or an HTTP 500 produces a switch with an empty hostname, no ports, no VLANs and no neighbours instead of an error. netOrk stores those answers as the switch's state. (`get_snmp_communities` / `configure_snmp_community` use the same `get()`; they are dead code per #12, and #10 proposes using `get_snmp_communities` on the REST transport — its endpoint `snmp-server/community` and the `snmp_community_element` key should be checked against a real switch's REST API before that, since an error there would also read as "no communities".) ## Expected `get()` raises `ConnectionException` (connection error, 401/403 after re-login) or a `RuntimeError` with the status for other non-2xx answers; a 404 for an optional resource is handled by the caller that expects it. Test-first: `get("ports")` answering 500 makes `get_interfaces()` raise. Priority: P3 — wrong (empty) switch state in netOrk after any transient REST error. Found during the bug sweep of 2026-11-01.
christianmanivong added the
prio
P3
bug
labels 2026-11-01 21:44:46 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-hpe-aruba-procurve#22