fix(dns): raise when the DNS service detection fails

_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
This commit is contained in:
Christian Manivong committed 2026-11-02 08:35:49 +01:00
1 parent 91a17b54a8
commit 901df1b523
3 files changed
+54 -10

No files matched your search

+37
View File
@@ -3005,6 +3005,43 @@ class TestHostOverrideReadFailure:
driver.get_dns_entries()
class TestDnsServiceDetection:
"""A failed service search raises: None would say neither Unbound nor Dnsmasq runs (#39)."""
def test_get_dns_entries_raises_when_the_service_search_fails(self, driver):
driver.session.get.side_effect = requests.exceptions.ConnectionError("reset by peer")
with pytest.raises(requests.exceptions.ConnectionError):
driver.get_dns_entries()
driver.session.post.assert_not_called()
def test_sync_dns_zone_reports_the_api_error_and_writes_nothing(self, driver):
driver.session.get.side_effect = requests.exceptions.HTTPError("502 Bad Gateway")
with pytest.raises(requests.exceptions.HTTPError, match="502"):
driver.sync_dns_zone(
"office.local",
[{"hostname": "nas", "ip": "172.22.40.8", "record_type": "A", "enabled": True}],
)
driver.session.post.assert_not_called()
def test_get_dns_entries_is_empty_when_neither_service_runs(self, driver):
driver.session.get.return_value = _make_json_response(
{
"rows": [
{"name": "unbound", "running": 0},
{"name": "dnsmasq", "running": 0},
{"name": "sshd", "running": 1},
]
}
)
assert driver.get_dns_entries() == []
driver.session.post.assert_not_called()
# ---------------------------------------------------------------------------
# uninstall_package – says what it cannot do
# ---------------------------------------------------------------------------