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:
James Valleroy committed 2023-10-07 04:52:13 +09:00
1 parent d9491d5762
commit 79f36e6a0c
19 files changed
+284 -183

No files matched your search

+13 -8
View File
@@ -12,6 +12,7 @@ from django.utils.translation import gettext_lazy as _
from plinth import app
from plinth.modules import firewall
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
logger = logging.getLogger(__name__)
@@ -130,25 +131,29 @@ class Firewall(app.FollowerComponent):
for port_number, protocol in port_detail['details']))
# Internal zone
result = 'passed' if port in internal_ports else 'failed'
check_id = f'firewall-port-{port}-internal'
result = Result.PASSED if port in internal_ports else Result.FAILED
template = _(
'Port {name} ({details}) available for internal networks')
testname = format_lazy(template, name=port, details=details)
results.append([testname, result])
description = format_lazy(template, name=port, details=details)
results.append(DiagnosticCheck(check_id, description, result))
# External zone
check_id = f'firewall-port-{port}-external'
if self.is_external:
result = 'passed' if port in external_ports else 'failed'
result = Result.PASSED \
if port in external_ports else Result.FAILED
template = _(
'Port {name} ({details}) available for external networks')
testname = format_lazy(template, name=port, details=details)
description = format_lazy(template, name=port, details=details)
else:
result = 'passed' if port not in external_ports else 'failed'
result = Result.PASSED \
if port not in external_ports else Result.FAILED
template = _(
'Port {name} ({details}) unavailable for external networks'
)
testname = format_lazy(template, name=port, details=details)
results.append([testname, result])
description = format_lazy(template, name=port, details=details)
results.append(DiagnosticCheck(check_id, description, result))
return results