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

+6 -4
View File
@@ -19,6 +19,7 @@ from plinth.modules.apache.components import diagnose_url_on_all
from plinth.modules.backups.components import BackupRestore
from . import manifest
from .check import Result
_description = [
_('The system diagnostic test will run a number of checks on your '
@@ -299,13 +300,14 @@ def _run_background_diagnostics():
for _app_id, app_data in results.items():
if app_data['exception']:
exception_count += 1
continue
for _test, result in app_data['diagnosis']:
if result == 'error':
for check in app_data['diagnosis']:
if check.result == Result.ERROR:
error_count += 1
elif result == 'failed':
elif check.result == Result.FAILED:
failure_count += 1
elif cfg.develop and result == 'warning':
elif check.result == Result.WARNING:
warning_count += 1
notification_id = 'diagnostics-background'
+28
View File
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Diagnostic check data type
"""
from dataclasses import dataclass
from enum import StrEnum
class Result(StrEnum):
"""The result of a diagnostic check."""
NOT_DONE = 'not_done'
PASSED = 'passed'
WARNING = 'warning'
FAILED = 'failed'
ERROR = 'error'
# TODO: Add parameters for test.
# TODO: Description should not be translated until we need to display it.
@dataclass
class DiagnosticCheck:
"""A diagnostic check and optional result."""
check_id: str
description: str
result: Result = Result.NOT_DONE
@@ -13,18 +13,18 @@
</tr>
</thead>
<tbody>
{% for test, result in results %}
{% for result in results %}
<tr>
<td>{{ test }}</td>
<td>{{ result.description }}</td>
<td class="diagnostics-result">
{% if result == 'passed' %}
<span class="badge badge-success">{% trans result %}</span>
{% elif result == 'failed' %}
<span class="badge badge-danger">{% trans result %}</span>
{% elif result == 'error' or result == 'warning' %}
<span class="badge badge-warning">{% trans result %}</span>
{% if result.result == 'passed' %}
<span class="badge badge-success">{% trans result.result %}</span>
{% elif result.result == 'failed' %}
<span class="badge badge-danger">{% trans result.result %}</span>
{% elif result.result == 'error' or result.result == 'warning' %}
<span class="badge badge-warning">{% trans result.result %}</span>
{% else %}
{{ result }}
{{ result.result }}
{% endif %}
</td>
</tr>