mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
upgrades: Trigger special package operations in a simpler way
Closes: #2498. - Now, as soon as service starts, it will perform force upgrade operations and post-installation app setup operations. So, it is no loner necessary to wait for 10 minutes and trigger the one of the operations with 'apt-get update'. - In addition, the post-installation operations are triggered more explicitly and sooner. Tests: - Install MediaWiki on Bookworm. Run distribution upgrade to Trixie and it works. Log shows that post install operations were performed and mediawiki setup was rerun. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
bc116e028a
commit
42586feee8
@ -72,10 +72,9 @@ distribution_info: dict = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _apt_run(arguments: list[str], enable_triggers: bool = False):
|
def _apt_run(arguments: list[str]):
|
||||||
"""Run an apt command and ensure that output is written to stdout."""
|
"""Run an apt command and ensure that output is written to stdout."""
|
||||||
returncode = action_utils.run_apt_command(arguments, stdout=None,
|
returncode = action_utils.run_apt_command(arguments, stdout=None)
|
||||||
enable_triggers=enable_triggers)
|
|
||||||
if returncode:
|
if returncode:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f'Apt command failed with return code: {returncode}')
|
f'Apt command failed with return code: {returncode}')
|
||||||
@ -318,10 +317,10 @@ def _packages_remove_obsolete() -> None:
|
|||||||
_apt_run(['remove'] + OBSOLETE_PACKAGES)
|
_apt_run(['remove'] + OBSOLETE_PACKAGES)
|
||||||
|
|
||||||
|
|
||||||
def _apt_update(enable_triggers: bool = False):
|
def _apt_update():
|
||||||
"""Run 'apt update'."""
|
"""Run 'apt update'."""
|
||||||
logger.info('Updating Apt cache...')
|
logger.info('Updating Apt cache...')
|
||||||
_apt_run(['update'], enable_triggers=enable_triggers)
|
_apt_run(['update'])
|
||||||
|
|
||||||
|
|
||||||
def _apt_fix():
|
def _apt_fix():
|
||||||
@ -365,12 +364,6 @@ def _freedombox_restart():
|
|||||||
action_utils.service_restart('plinth')
|
action_utils.service_restart('plinth')
|
||||||
|
|
||||||
|
|
||||||
def _wait():
|
|
||||||
"""Wait for 10 minutes before performing remaining actions."""
|
|
||||||
logger.info('Waiting for 10 minutes...')
|
|
||||||
time.sleep(10 * 60)
|
|
||||||
|
|
||||||
|
|
||||||
def _trigger_on_complete():
|
def _trigger_on_complete():
|
||||||
"""Trigger the on complete step in a separate service."""
|
"""Trigger the on complete step in a separate service."""
|
||||||
# The dist-upgrade process will be run /etc/apt/sources.list file bind
|
# The dist-upgrade process will be run /etc/apt/sources.list file bind
|
||||||
@ -414,8 +407,6 @@ def perform():
|
|||||||
|
|
||||||
_unattended_upgrades_run()
|
_unattended_upgrades_run()
|
||||||
_freedombox_restart()
|
_freedombox_restart()
|
||||||
_wait()
|
|
||||||
_apt_update(enable_triggers=True)
|
|
||||||
_trigger_on_complete()
|
_trigger_on_complete()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -368,11 +368,7 @@ def test_packages_remove_obsolete(apt_run):
|
|||||||
def test_apt_update(apt_run):
|
def test_apt_update(apt_run):
|
||||||
"""Test that apt update works."""
|
"""Test that apt update works."""
|
||||||
distupgrade._apt_update()
|
distupgrade._apt_update()
|
||||||
apt_run.assert_called_with(['update'], enable_triggers=False)
|
apt_run.assert_called_with(['update'])
|
||||||
|
|
||||||
apt_run.reset_mock()
|
|
||||||
distupgrade._apt_update(enable_triggers=True)
|
|
||||||
apt_run.assert_called_with(['update'], enable_triggers=True)
|
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.upgrades.distupgrade._apt_run')
|
@patch('plinth.modules.upgrades.distupgrade._apt_run')
|
||||||
@ -419,13 +415,6 @@ def test_freedombox_restart(service_restart):
|
|||||||
service_restart.assert_called_with('plinth')
|
service_restart.assert_called_with('plinth')
|
||||||
|
|
||||||
|
|
||||||
@patch('time.sleep')
|
|
||||||
def test_wait(sleep):
|
|
||||||
"""Test that sleeping works."""
|
|
||||||
distupgrade._wait()
|
|
||||||
sleep.assert_called_with(600)
|
|
||||||
|
|
||||||
|
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_trigger_on_complete(run):
|
def test_trigger_on_complete(run):
|
||||||
"""Test triggering post completion process."""
|
"""Test triggering post completion process."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user