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."""