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

+12 -10
View File
@@ -2794,15 +2794,16 @@ class OPNsenseDriver(
# ------------------------------------------------------------------
def _detect_active_dns(self) -> str | None:
"""Return 'unbound' or 'dnsmasq' depending on which service is running."""
try:
data = self._get("/api/core/service/search")
for row in data.get("rows", []):
name = (row.get("name") or "").lower()
if name in ("unbound", "dnsmasq") and row.get("running"):
return name
except Exception as exc:
logger.warning("DNS service detection failed: %s", exc)
"""Return 'unbound' or 'dnsmasq' depending on which service is running.
None only when the service list was read and neither runs; a failed
read raises, so it cannot pass for "no DNS service".
"""
data = self._get("/api/core/service/search")
for row in data.get("rows", []):
name = (row.get("name") or "").lower()
if name in ("unbound", "dnsmasq") and row.get("running"):
return name
return None
def get_dns_entries(self) -> list[dict[str, Any]]:
@@ -2810,7 +2811,8 @@ class OPNsenseDriver(
Checks whether Unbound (DNS Resolver) or Dnsmasq (DNS Forwarder) is
running and returns host overrides from whichever is active. If neither
is running, returns an empty list. A failed read of the overrides raises.
is running, returns an empty list. A failed read of the service list
or of the overrides raises.
Each entry::