From 70c37f309eee7e671559045e59448eb92e8f26cc Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 1 Oct 2024 19:11:30 -0700 Subject: [PATCH] names: Don't control resolved daemon when package is not installed Tests: - Ensure that systemd-resolved is not installed. - There is no warning showing that systemd-resolved daemon is not running. - When re-running setup, systemd-resolved is not enabled. - Diagnostic shows a warning that systemd-resolved is not installed. - Ensure that systemd-resolved is installed. - If daemon is not running, warning shown that it is not running. - If daemon is running, warning is not shown. - When re-running setup, systemd-resolved is enabled. - Diagnostic shows that the daemon is running when running and not running when it is not. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- plinth/modules/names/__init__.py | 42 +++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index 1855481dd..6236f78f7 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -70,7 +70,7 @@ class NamesApp(app_module.App): 'names:domains', can_have_certificate=True) self.add(domain_type) - daemon = Daemon('daemon-names', 'systemd-resolved') + daemon = ResolvedDaemon('daemon-names', 'systemd-resolved') self.add(daemon) backup_restore = BackupRestore('backup-restore-names', @@ -122,6 +122,46 @@ class NamesApp(app_module.App): self.enable() +class ResolvedDaemon(Daemon): + """Perform work only if systemd-resolved is installed.""" + + def is_enabled(self): + """Return if the daemon/unit is enabled.""" + if not is_resolved_installed(): + return True + + return super().is_enabled() + + def enable(self): + """Run operations to enable the daemon/unit.""" + if is_resolved_installed(): + super().enable() + + def disable(self): + """Run operations to disable the daemon/unit.""" + if is_resolved_installed(): + super().disable() + + def is_running(self): + """Return whether the daemon/unit is running.""" + if not is_resolved_installed(): + return True + + return super().is_running() + + def diagnose(self) -> list[DiagnosticCheck]: + """Check if the daemon is running and listening on expected ports.""" + if not is_resolved_installed(): + return [ + DiagnosticCheck( + 'names-resolved-installed', + gettext_noop('Package systemd-resolved is installed'), + Result.WARNING, {}, self.component_id) + ] + + return super().diagnose() + + def diagnose_resolution(domain: str) -> DiagnosticCheck: """Perform a diagnostic check for whether a domain can be resolved.""" result = Result.NOT_DONE