mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
upgrades: Don't ignore apt error during distribution upgrade
- This is important because only if all the command succeed, the changes to /etc/apt/sources.list file are committed. Tests: - Set the time to 2025-09-20. Distribution updates are triggered. 'apt update' fails due an mismatch with release file's timestamp. Instead of proceeding, the distribution upgrade is halted. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
44b4c38d8a
commit
b6f0e7f323
@ -74,8 +74,11 @@ distribution_info: dict = {
|
|||||||
|
|
||||||
def _apt_run(arguments: list[str], enable_triggers: bool = False):
|
def _apt_run(arguments: list[str], enable_triggers: bool = False):
|
||||||
"""Run an apt command and ensure that output is written to stdout."""
|
"""Run an apt command and ensure that output is written to stdout."""
|
||||||
return action_utils.run_apt_command(arguments, stdout=None,
|
returncode = action_utils.run_apt_command(arguments, stdout=None,
|
||||||
enable_triggers=enable_triggers)
|
enable_triggers=enable_triggers)
|
||||||
|
if returncode:
|
||||||
|
raise RuntimeError(
|
||||||
|
f'Apt command failed with return code: {returncode}')
|
||||||
|
|
||||||
|
|
||||||
def _sources_list_update(old_codename: str, new_codename: str):
|
def _sources_list_update(old_codename: str, new_codename: str):
|
||||||
|
|||||||
@ -19,13 +19,17 @@ from plinth.modules.upgrades import distupgrade
|
|||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_apt_run(run):
|
def test_apt_run(run):
|
||||||
"""Test that running apt command logs properly."""
|
"""Test that running apt command logs properly."""
|
||||||
run.return_value.returncode = 10
|
run.return_value.returncode = 0
|
||||||
args = ['command', 'arg1', 'arg2']
|
args = ['command', 'arg1', 'arg2']
|
||||||
assert distupgrade._apt_run(args) == 10
|
distupgrade._apt_run(args)
|
||||||
assert run.call_args.args == \
|
assert run.call_args.args == \
|
||||||
(['apt-get', '--assume-yes', '--quiet=2'] + args,)
|
(['apt-get', '--assume-yes', '--quiet=2'] + args,)
|
||||||
assert not run.call_args.kwargs['stdout']
|
assert not run.call_args.kwargs['stdout']
|
||||||
|
|
||||||
|
run.return_value.returncode = 10
|
||||||
|
with pytest.raises(RuntimeError):
|
||||||
|
distupgrade._apt_run(args)
|
||||||
|
|
||||||
|
|
||||||
def test_sources_list_update(tmp_path):
|
def test_sources_list_update(tmp_path):
|
||||||
"""Test that updating a sources file works."""
|
"""Test that updating a sources file works."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user