fix(dns): raise when the host overrides cannot be read

The Unbound and Dnsmasq override reads logged any error and returned an
empty list. sync_dns_zone took that for "no overrides": it deleted
nothing and added every record again, so a transient API error left
each record twice on the firewall. The reads now raise, which stops the
sync before it writes and lets get_dns_entries callers tell a failed
read from an empty one.

Closes #14
This commit is contained in:
Christian Manivong committed 2026-11-01 21:45:12 +01:00
1 parent 4e377923db
commit 4fc7b2424e
4 files changed
+107 -73

No files matched your search

+38
View File
@@ -2888,6 +2888,44 @@ class TestSyncDnsZone:
assert len([p for p, _ in calls if p.endswith("addhostoverride")]) == 1
@pytest.mark.parametrize("service", ["unbound", "dnsmasq"])
def test_a_failed_read_raises_and_changes_nothing(self, driver, service):
"""#14: a sync on an inventory it could not read deleted nothing and
added every record a second time."""
calls = []
def _post(path, data=None):
calls.append(path)
if path.endswith("searchhostoverride"):
raise requests.exceptions.ConnectionError("reset by peer")
return {"result": "saved"}
driver._detect_active_dns = lambda: service
driver._post = _post
with pytest.raises(requests.exceptions.ConnectionError):
driver.sync_dns_zone(
"office.local",
[{"hostname": "nas", "ip": "172.22.40.8", "record_type": "A", "enabled": True}],
)
assert calls == [f"/api/{service}/settings/searchhostoverride"]
class TestHostOverrideReadFailure:
"""A failed read raises: an empty list would say the firewall has no overrides."""
@pytest.mark.parametrize("service", ["unbound", "dnsmasq"])
def test_get_dns_entries_raises_when_the_search_fails(self, driver, service):
def _post(path, data=None):
raise requests.exceptions.HTTPError("500 Server Error")
driver._detect_active_dns = lambda: service
driver._post = _post
with pytest.raises(requests.exceptions.HTTPError):
driver.get_dns_entries()
# ---------------------------------------------------------------------------
# uninstall_package – says what it cannot do