#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.
#40create_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.
#41test_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.
## 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
_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
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
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.
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
_detect_active_dns()no longer swallows a failed/api/core/service/search: the request error propagates, andNonemeans 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.create_dhcp_reservation()raisesRuntimeErrornamingsearchReservation(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 postaddReservationanyway.test_open_raises_connection_exception_on_errorpatchesrequests.Session.getto refuse the connection and checksConnectionException, the status URL asked for andsession is None. It used to resolveunreachable.invalidthrough 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 makesget_dns_entries()andsync_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; onlysearchReservationwas 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