diagnostics: Refactor check IDs, tests and background checks

- Ensure that each diagnostic test category can be identified by easy prefix
matching on the test ID.

- Give a different unique IDs each different kind of test. More specific tests
of a type get a different kind of ID.

- Make comparison of diagnostic test results in test cases more comprehensive.

- Simplify code that shows the number if issues identified.

- In many languages, there is complex logic to write plural forms. Plurals
can't be handled by assuming singular = 1 item and plural is > 1. Translation of
messages in Notification does not support plurals properly. Avoid this for now
by using sometimes incorrect plural form.

- For i18n we should avoid joining phrases/words. Words don't always maintain
order after translation.

- Notify about the total number of issues in diagnostics and not just the most
severe category. This is likely to draw more attention and avoid i18n
complexity.

- Dismiss the diagnostic notification if the latest run succeeded completely.

Tests:

- Unit tests pass.

- Diagnostics for following apps works: networks (drop-in config),
apache (daemon, listen address, internal firewall, external firewall),
tor (netcat), torproxy (internal only firewall, torproxy url, torproxy using
tor), privoxy (privoxy url, package available, package latest),

- Untested: Is release file available method in upgrades app.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2023-10-07 04:52:22 +09:00
1 parent a233bbfd9b
commit 465e452daf
17 files changed
+247 -197

No files matched your search

+12 -10
View File
@@ -8,7 +8,7 @@ from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy
from plinth import action_utils, app
from plinth.modules.diagnostics.check import DiagnosticCheck
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
from plinth.privileged import service as service_privileged
from . import privileged
@@ -142,11 +142,15 @@ def diagnose_url(url, kind=None, env=None, check_certificate=True,
Kind can be '4' for IPv4 or '6' for IPv6.
"""
result = check_url(url, kind, env, check_certificate, extra_options,
wrapper, expected_output)
try:
return_value = check_url(url, kind, env, check_certificate,
extra_options, wrapper, expected_output)
result = Result.PASSED if return_value else Result.FAILED
except FileNotFoundError:
result = Result.ERROR
if kind:
check_id = f'apache-url-{url}-{kind}'
check_id = f'apache-url-kind-{url}-{kind}'
template = gettext_lazy('Access URL {url} on tcp{kind}')
description = format_lazy(template, url=url, kind=kind)
else:
@@ -201,15 +205,13 @@ def check_url(url, kind=None, env=None, check_certificate=True,
process = subprocess.run(command, env=env, check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = 'passed'
result = True
if expected_output and expected_output not in process.stdout.decode():
result = 'failed'
result = False
except subprocess.CalledProcessError as exception:
result = 'failed'
result = False
# Authorization failed is a success
if exception.stdout.decode().strip() in ('401', '405'):
result = 'passed'
except FileNotFoundError:
result = 'error'
result = True
return result