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 <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2024-10-01 19:11:30 -07:00 committed by Veiko Aasa
parent 5c06b6c31a
commit 70c37f309e
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -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