From 1eb578fdb5cdfa240f9b4963727bd8cd1f3005fc Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 4 Sep 2024 08:29:48 -0700 Subject: [PATCH] names: Implement a diagnostic check for checking name resolution - Use deb.debian.org because it is already contacted regularly for checking/downloading packages and updates. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- plinth/modules/names/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index f34137de2..2e5e46773 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -4,12 +4,16 @@ FreedomBox app to configure name services. """ import logging +import subprocess from django.utils.translation import gettext_lazy as _ +from django.utils.translation import gettext_noop from plinth import app as app_module from plinth import cfg, menu, network from plinth.daemon import Daemon +from plinth.diagnostic_check import (DiagnosticCheck, + DiagnosticCheckParameters, Result) from plinth.modules.backups.components import BackupRestore from plinth.package import Packages from plinth.privileged import service as service_privileged @@ -70,6 +74,12 @@ class NamesApp(app_module.App): domain_added.connect(on_domain_added) domain_removed.connect(on_domain_removed) + def diagnose(self) -> list[DiagnosticCheck]: + """Run diagnostics and return the results.""" + results = super().diagnose() + results.append(diagnose_resolution('deb.debian.org')) + return results + def setup(self, old_version): """Install and configure the app.""" super().setup(old_version) @@ -94,6 +104,22 @@ class NamesApp(app_module.App): self.enable() +def diagnose_resolution(domain: str) -> DiagnosticCheck: + """Perform a diagnostic check for whether a domain can be resolved.""" + result = Result.NOT_DONE + try: + subprocess.run(['resolvectl', 'query', '--cache=no', domain], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + check=True) + result = Result.PASSED + except subprocess.CalledProcessError: + result = Result.FAILED + + description = gettext_noop('Resolve domain name: {domain}') + parameters: DiagnosticCheckParameters = {'domain': domain} + return DiagnosticCheck('names-resolve', description, result, parameters) + + def on_domain_added(sender, domain_type, name='', description='', services=None, **kwargs): """Add domain to global list."""