fix: DNS detection and Kea search raise on a failed read, hermetic open() test (#39, #40, #41) #42

Merged
christianmanivong merged 4 commits from fix/bugs-2026-11-02 into main 2026-11-02 08:20:46 +00:00
Owner

What

  • #39 _detect_active_dns() no longer swallows a failed /api/core/service/search: the request error propagates, and None means only that the list was read and neither Unbound nor Dnsmasq runs. get_dns_entries() raises instead of returning []; sync_dns_zone() raises the API error instead of "No active DNS service (Unbound or Dnsmasq) detected", and writes nothing.
  • #40 create_dhcp_reservation() raises RuntimeError naming searchReservation (with the request error as its cause) when the search for an existing reservation fails, before anything is written. It used to log at debug level and post addReservation anyway.
  • #41 test_open_raises_connection_exception_on_error patches requests.Session.get to refuse the connection and checks ConnectionException, the status URL asked for and session is None. It used to resolve unreachable.invalid through the host's resolver.

Why

A failed read must not look like an empty answer: an empty get_dns_entries() makes the application drop the firewall's DNS records after one transient API error, and a reservation write after a failed search can add a second reservation for the same address, which Kea refuses to load. Unit tests never open a socket (driver standard §4).

Tests

Fixtures only. Each fix starts with a test that failed on main:

  • TestDnsServiceDetection (failed search makes get_dns_entries() and sync_dns_zone() raise without any POST; a read with neither service running still gives []).
  • TestCreateDhcpReservation::test_failed_reservation_search_raises_before_any_write (HTTP error and connection error; only searchReservation was posted).
  • TestOpenClose::test_open_raises_connection_exception_on_error, checked with a guard that fails any name lookup or connect: on main it was the only test in the suite that touched the network; now none does.

Full suite 485 passed, coverage 83 % (floor 79), ruff format/check clean, mypy clean, bandit clean.

Closes #39
Closes #40
Closes #41

## What - **#39** `_detect_active_dns()` no longer swallows a failed `/api/core/service/search`: the request error propagates, and `None` means only that the list was read and neither Unbound nor Dnsmasq runs. `get_dns_entries()` raises instead of returning `[]`; `sync_dns_zone()` raises the API error instead of "No active DNS service (Unbound or Dnsmasq) detected", and writes nothing. - **#40** `create_dhcp_reservation()` raises `RuntimeError` naming `searchReservation` (with the request error as its cause) when the search for an existing reservation fails, before anything is written. It used to log at debug level and post `addReservation` anyway. - **#41** `test_open_raises_connection_exception_on_error` patches `requests.Session.get` to refuse the connection and checks `ConnectionException`, the status URL asked for and `session is None`. It used to resolve `unreachable.invalid` through the host's resolver. ## Why A failed read must not look like an empty answer: an empty `get_dns_entries()` makes the application drop the firewall's DNS records after one transient API error, and a reservation write after a failed search can add a second reservation for the same address, which Kea refuses to load. Unit tests never open a socket (driver standard §4). ## Tests Fixtures only. Each fix starts with a test that failed on main: - `TestDnsServiceDetection` (failed search makes `get_dns_entries()` and `sync_dns_zone()` raise without any POST; a read with neither service running still gives `[]`). - `TestCreateDhcpReservation::test_failed_reservation_search_raises_before_any_write` (HTTP error and connection error; only `searchReservation` was posted). - `TestOpenClose::test_open_raises_connection_exception_on_error`, checked with a guard that fails any name lookup or connect: on main it was the only test in the suite that touched the network; now none does. Full suite 485 passed, coverage 83 % (floor 79), ruff format/check clean, mypy clean, bandit clean. Closes #39 Closes #40 Closes #41
christianmanivong added 3 commits 2026-11-02 07:38:52 +00:00
_detect_active_dns caught every error from /api/core/service/search and
returned None, so get_dns_entries() reported a transient API error as an
empty list (no DNS service) and sync_dns_zone() blamed the DNS service.
Let the request error propagate; None only when the list was read and
neither Unbound nor Dnsmasq runs.

Closes #39
create_dhcp_reservation searched for an existing reservation so a retry
updates it, but a failed search was logged at debug level and the add
went ahead: a write based on a read that did not happen. Raise a
RuntimeError naming searchReservation before anything is written.

Closes #40
fix(tests): keep the open() failure test off the network
driver / standard (pull_request) Failing after 20s
driver / lint (pull_request) Successful in 21s
driver / types (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 1m44s
driver / test (3.13) (pull_request) Successful in 1m28s
driver / lowest (pull_request) Successful in 56s
driver / build (pull_request) Successful in 34s
driver / security (pull_request) Successful in 1m8s
CI / driver (pull_request) Failing after 3m33s
driver / publish (pull_request) Skipped
96a4a139d0
test_open_raises_connection_exception_on_error called open() on
"unreachable.invalid" unpatched, so the unit test resolved the name
through the host's resolver and depended on it failing fast. Patch
requests.Session.get to refuse the connection and check that open()
raises ConnectionException and leaves no session behind.

Closes #41
christianmanivong added 1 commit 2026-11-02 07:51:22 +00:00
refactor(dhcp): move the Kea subnet lookup into kea_reservations
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 17s
driver / types (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 1m17s
driver / test (3.13) (pull_request) Successful in 1m12s
driver / lowest (pull_request) Successful in 36s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m7s
CI / driver (pull_request) Successful in 2m56s
driver / publish (pull_request) Skipped
6ac7a6f6a2
create_dhcp_reservation and _kea_subnet_uuid_for each walked the
searchSubnet rows for the one holding an address. Both now call the
pure subnet_containing(), which brings create_dhcp_reservation under
the complexity limit and back below its recorded length after #40;
the quality baseline records the shrunk entries.
christianmanivong merged commit 80d6b8cb71 into main 2026-11-02 08:20:46 +00:00
christianmanivong deleted branch fix/bugs-2026-11-02 2026-11-02 08:20:46 +00:00
Sign in to join this conversation.