fix(dal): raise on a failed request instead of reading it as empty #16

Merged
christianmanivong merged 1 commits from fix/bugs-2026-11-02b into main 2026-11-02 09:40:44 +00:00
Owner

What

A failed request to the gateway raises instead of reading as empty data.

  • _dal_query and _fetch_page raise ConnectionException when the gateway does not answer or refuses the session (HTTP 401/403), and RuntimeError naming the request (DAL <oid> / GET <path>) for any other HTTP error or an answer that cannot be read. They returned None for every failure, including except Exception in _dal_query.
  • The getters that read the DAL with an HTML page as fallback (get_hosts, get_port_forwards, get_wireless_clients, get_ssids, get_radio_status) go through one helper, _read_dal_or_page: the DAL answer when it can be read, else the page; when the page fails too, the getter raises. get_arp_table and get_nat_translations build on them and raise with them. get_radio_status's inline parsing moves into _parse_radio_status_dal / _parse_radio_status_html (complexity 14 → under the limit; its baseline entry is gone).
  • get_diagnostics, reboot_host and restart_wifi raise when their DAL request fails. The refused-answer checks of the two actions are unchanged.
  • get_facts no longer turns a failed get_interfaces into interface_list=[].

Why

A timeout or an expired session read as a gateway with no hosts, port forwards, SSIDs or Wi-Fi clients.

Tests

Fixtures only (no device). tests/test_failed_reads.py drives the driver against a stub session answering per path: _dal_query with timeout, 401/403, 500 and a non-JSON answer; every DAL-or-page getter with both sources failing; the page fallback; a DAL answer with no hosts reading as none; get_facts with get_interfaces raising. 14 of them failed before the change. The stub's driver does not let NAPALM's __del__ open a TCP connection through is_alive().

pytest 66 passed, ruff format/check clean, mypy clean, napalm-standard check passes, napalm-standard ratchet within the baseline (one complexity entry fewer).

Closes #15

## What A failed request to the gateway raises instead of reading as empty data. - `_dal_query` and `_fetch_page` raise `ConnectionException` when the gateway does not answer or refuses the session (HTTP 401/403), and `RuntimeError` naming the request (`DAL <oid>` / `GET <path>`) for any other HTTP error or an answer that cannot be read. They returned `None` for every failure, including `except Exception` in `_dal_query`. - The getters that read the DAL with an HTML page as fallback (`get_hosts`, `get_port_forwards`, `get_wireless_clients`, `get_ssids`, `get_radio_status`) go through one helper, `_read_dal_or_page`: the DAL answer when it can be read, else the page; when the page fails too, the getter raises. `get_arp_table` and `get_nat_translations` build on them and raise with them. `get_radio_status`'s inline parsing moves into `_parse_radio_status_dal` / `_parse_radio_status_html` (complexity 14 → under the limit; its baseline entry is gone). - `get_diagnostics`, `reboot_host` and `restart_wifi` raise when their DAL request fails. The refused-answer checks of the two actions are unchanged. - `get_facts` no longer turns a failed `get_interfaces` into `interface_list=[]`. ## Why A timeout or an expired session read as a gateway with no hosts, port forwards, SSIDs or Wi-Fi clients. ## Tests Fixtures only (no device). `tests/test_failed_reads.py` drives the driver against a stub session answering per path: `_dal_query` with timeout, 401/403, 500 and a non-JSON answer; every DAL-or-page getter with both sources failing; the page fallback; a DAL answer with no hosts reading as none; `get_facts` with `get_interfaces` raising. 14 of them failed before the change. The stub's driver does not let NAPALM's `__del__` open a TCP connection through `is_alive()`. pytest 66 passed, ruff format/check clean, mypy clean, `napalm-standard check` passes, `napalm-standard ratchet` within the baseline (one complexity entry fewer). Closes #15
christianmanivong added 1 commit 2026-11-02 08:19:01 +00:00
fix(dal): raise on a failed request instead of reading it as empty
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 4m10s
driver / test (3.13) (pull_request) Successful in 4m6s
driver / lowest (pull_request) Successful in 3m43s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m17s
CI / driver (pull_request) Successful in 5m59s
driver / publish (pull_request) Skipped
ded19238c0
_dal_query and _fetch_page returned None for any failure, and the
getters turned that into empty data, so a timeout or an expired session
read as a gateway with no hosts, port forwards, SSIDs or Wi-Fi clients.
Both now raise: ConnectionException when the gateway does not answer or
refuses the session, RuntimeError naming the request otherwise. A getter
whose DAL request fails still reads the HTML page and raises when that
fails too; get_facts no longer swallows a failed get_interfaces.

Closes #15
christianmanivong merged commit 98f9df188e into main 2026-11-02 09:40:44 +00:00
christianmanivong deleted branch fix/bugs-2026-11-02b 2026-11-02 09:40:44 +00:00
Sign in to join this conversation.