From b6f0e7f3234bfc650b21b2bb131f74ad2fc445e0 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 3 Apr 2025 16:15:50 -0700 Subject: [PATCH] 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 Reviewed-by: James Valleroy --- plinth/modules/upgrades/distupgrade.py | 7 +++++-- plinth/modules/upgrades/tests/test_distupgrade.py | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plinth/modules/upgrades/distupgrade.py b/plinth/modules/upgrades/distupgrade.py index 50b3db63b..f87133f5f 100644 --- a/plinth/modules/upgrades/distupgrade.py +++ b/plinth/modules/upgrades/distupgrade.py @@ -74,8 +74,11 @@ distribution_info: dict = { def _apt_run(arguments: list[str], enable_triggers: bool = False): """Run an apt command and ensure that output is written to stdout.""" - return action_utils.run_apt_command(arguments, stdout=None, - enable_triggers=enable_triggers) + returncode = action_utils.run_apt_command(arguments, stdout=None, + 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): diff --git a/plinth/modules/upgrades/tests/test_distupgrade.py b/plinth/modules/upgrades/tests/test_distupgrade.py index 57aa8754d..b60b54a4f 100644 --- a/plinth/modules/upgrades/tests/test_distupgrade.py +++ b/plinth/modules/upgrades/tests/test_distupgrade.py @@ -19,13 +19,17 @@ from plinth.modules.upgrades import distupgrade @patch('subprocess.run') def test_apt_run(run): """Test that running apt command logs properly.""" - run.return_value.returncode = 10 + run.return_value.returncode = 0 args = ['command', 'arg1', 'arg2'] - assert distupgrade._apt_run(args) == 10 + distupgrade._apt_run(args) assert run.call_args.args == \ (['apt-get', '--assume-yes', '--quiet=2'] + args,) 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): """Test that updating a sources file works."""