mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
diagnostics: Add DiagnosticCheck dataclass
- Set unique check_id for each diagnostic check. - Result is a string-based enumeration. The default value (NOT_DONE) can be used for diagnostic checks that have not been completed yet. - Result is StrEnum so that the return value of check_url can still be used directly as a diagnostic result. Closes: #2375 Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
19 files changed
+284
-183
No files matched your search
@@ -12,6 +12,7 @@ from plinth import app as app_module
|
||||
from plinth import cfg, menu
|
||||
from plinth.config import DropinConfigs
|
||||
from plinth.daemon import Daemon
|
||||
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
|
||||
from plinth.package import Packages
|
||||
from plinth.privileged import service as service_privileged
|
||||
|
||||
@@ -112,32 +113,34 @@ class UsersApp(app_module.App):
|
||||
|
||||
def _diagnose_ldap_entry(search_item):
|
||||
"""Diagnose that an LDAP entry exists."""
|
||||
result = 'failed'
|
||||
check_id = f'users-ldap-entry-{search_item}'
|
||||
result = Result.FAILED
|
||||
|
||||
try:
|
||||
subprocess.check_output(
|
||||
['ldapsearch', '-x', '-b', 'dc=thisbox', search_item])
|
||||
result = 'passed'
|
||||
result = Result.PASSED
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
template = _('Check LDAP entry "{search_item}"')
|
||||
testname = format_lazy(template, search_item=search_item)
|
||||
description = format_lazy(template, search_item=search_item)
|
||||
|
||||
return [testname, result]
|
||||
return DiagnosticCheck(check_id, description, result)
|
||||
|
||||
|
||||
def _diagnose_nslcd_config(config, key, value):
|
||||
"""Diagnose that nslcd has a configuration."""
|
||||
check_id = f'users-nslcd-config-{key}'
|
||||
try:
|
||||
result = 'passed' if config[key] == value else 'failed'
|
||||
result = Result.PASSED if config[key] == value else Result.FAILED
|
||||
except KeyError:
|
||||
result = 'failed'
|
||||
result = Result.FAILED
|
||||
|
||||
template = _('Check nslcd config "{key} {value}"')
|
||||
testname = format_lazy(template, key=key, value=value)
|
||||
description = format_lazy(template, key=key, value=value)
|
||||
|
||||
return [testname, result]
|
||||
return DiagnosticCheck(check_id, description, result)
|
||||
|
||||
|
||||
def _diagnose_nsswitch_config():
|
||||
@@ -151,22 +154,23 @@ def _diagnose_nsswitch_config():
|
||||
|
||||
results = []
|
||||
for database in ['passwd', 'group', 'shadow']:
|
||||
result = 'failed'
|
||||
check_id = f'users-nsswitch-config-{database}'
|
||||
result = Result.FAILED
|
||||
for match in aug.match('database'):
|
||||
if aug.get(match) != database:
|
||||
continue
|
||||
|
||||
for service_match in aug.match(match + '/service'):
|
||||
if 'ldap' == aug.get(service_match):
|
||||
result = 'passed'
|
||||
result = Result.PASSED
|
||||
break
|
||||
|
||||
break
|
||||
|
||||
template = _('Check nsswitch config "{database}"')
|
||||
testname = format_lazy(template, database=database)
|
||||
description = format_lazy(template, database=database)
|
||||
|
||||
results.append([testname, result])
|
||||
results.append(DiagnosticCheck(check_id, description, result))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
Reference in new issue
Block a user