mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
upgrades: Add diagnostic for held packages
- Add a new diagnostic check result for skipped tests. Tests: - Put a hold on a package. The diagnostic is failed. - Remove the hold from the package. The diagnostic is passed. - Start installing an app, then immediately run the upgrades diagnostics. The diagnostic is skipped. Helps: #2347 Signed-off-by: James Valleroy <jvalleroy@mailbox.org> [sunil: Allow i18n for new state 'skipped'] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
0e8597a034
commit
f08211d228
@ -17,6 +17,7 @@ DiagnosticCheckParameters: TypeAlias = dict[str, str | int | bool | None]
|
|||||||
class Result(StrEnum):
|
class Result(StrEnum):
|
||||||
"""The result of a diagnostic check."""
|
"""The result of a diagnostic check."""
|
||||||
NOT_DONE = 'not_done'
|
NOT_DONE = 'not_done'
|
||||||
|
SKIPPED = 'skipped'
|
||||||
PASSED = 'passed'
|
PASSED = 'passed'
|
||||||
WARNING = 'warning'
|
WARNING = 'warning'
|
||||||
FAILED = 'failed'
|
FAILED = 'failed'
|
||||||
|
|||||||
@ -96,6 +96,7 @@ def _run_on_all_enabled_modules():
|
|||||||
|
|
||||||
# Four result strings returned by tests, mark for translation and
|
# Four result strings returned by tests, mark for translation and
|
||||||
# translate later.
|
# translate later.
|
||||||
|
gettext_noop('skipped')
|
||||||
gettext_noop('passed')
|
gettext_noop('passed')
|
||||||
gettext_noop('failed')
|
gettext_noop('failed')
|
||||||
gettext_noop('error')
|
gettext_noop('error')
|
||||||
|
|||||||
@ -23,6 +23,8 @@
|
|||||||
<span class="badge badge-danger">{% trans result.result %}</span>
|
<span class="badge badge-danger">{% trans result.result %}</span>
|
||||||
{% elif result.result == 'error' or result.result == 'warning' %}
|
{% elif result.result == 'error' or result.result == 'warning' %}
|
||||||
<span class="badge badge-warning">{% trans result.result %}</span>
|
<span class="badge badge-warning">{% trans result.result %}</span>
|
||||||
|
{% elif result.result == 'skipped' %}
|
||||||
|
<span class="badge badge-secondary">{% trans result.result %}</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ result.result }}
|
{{ result.result }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@ -11,9 +11,10 @@ from django.utils.translation import gettext_noop
|
|||||||
|
|
||||||
import plinth
|
import plinth
|
||||||
from plinth import app as app_module
|
from plinth import app as app_module
|
||||||
from plinth import cfg, glib, kvstore, menu
|
from plinth import action_utils, cfg, glib, kvstore, menu, package
|
||||||
from plinth.config import DropinConfigs
|
from plinth.config import DropinConfigs
|
||||||
from plinth.daemon import RelatedDaemon
|
from plinth.daemon import RelatedDaemon
|
||||||
|
from plinth.diagnostic_check import DiagnosticCheck, Result
|
||||||
from plinth.modules.backups.components import BackupRestore
|
from plinth.modules.backups.components import BackupRestore
|
||||||
from plinth.package import Packages
|
from plinth.package import Packages
|
||||||
|
|
||||||
@ -159,6 +160,12 @@ class UpgradesApp(app_module.App):
|
|||||||
# install and on version increment.
|
# install and on version increment.
|
||||||
setup_repositories(None)
|
setup_repositories(None)
|
||||||
|
|
||||||
|
def diagnose(self) -> list[DiagnosticCheck]:
|
||||||
|
"""Run diagnostics and return the results."""
|
||||||
|
results = super().diagnose()
|
||||||
|
results.append(_diagnose_held_packages())
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
def setup_repositories(_):
|
def setup_repositories(_):
|
||||||
"""Setup apt repositories for backports."""
|
"""Setup apt repositories for backports."""
|
||||||
@ -296,3 +303,19 @@ def test_dist_upgrade():
|
|||||||
"""Test dist-upgrade from stable to testing."""
|
"""Test dist-upgrade from stable to testing."""
|
||||||
if can_test_dist_upgrade():
|
if can_test_dist_upgrade():
|
||||||
try_start_dist_upgrade(test=True)
|
try_start_dist_upgrade(test=True)
|
||||||
|
|
||||||
|
|
||||||
|
def _diagnose_held_packages():
|
||||||
|
"""Check if any packages have holds."""
|
||||||
|
check = DiagnosticCheck('upgrades-package-holds',
|
||||||
|
gettext_noop('Check for package holds'),
|
||||||
|
Result.NOT_DONE)
|
||||||
|
if (package.is_package_manager_busy()
|
||||||
|
or action_utils.service_is_running('freedombox-dist-upgrade')):
|
||||||
|
check.result = Result.SKIPPED
|
||||||
|
return check
|
||||||
|
|
||||||
|
output = subprocess.check_output(['apt-mark', 'showhold']).decode().strip()
|
||||||
|
held_packages = output.split()
|
||||||
|
check.result = Result.FAILED if held_packages else Result.PASSED
|
||||||
|
return check
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user