upgrades: Run dpkg/apt fixes before dist upgrade

Closes: #2490

Tests:

- Unit tests works.

- On a fresh stable container, enable auto updates. Run 'apt install
mumble-server' and kill the apt process when it is unpacking. After this any apt
install command will ask for running dpkg --configure -a. At this time, run the
Testing dist upgrade. Dist upgrade starts successfully and then shows the
message 'Fixing any broken apt/dpkg states...'. It also shows that packages that
were not setup have been setup. Dist upgrades proceeds after that.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2025-03-17 08:10:46 -04:00
1 parent bbb59e16de
commit 91c5931c59
2 files changed
+19

No files matched your search

@@ -283,6 +283,17 @@ def test_apt_update(apt_run):
apt_run.assert_called_with(['update'])
@patch('plinth.modules.upgrades.distupgrade._apt_run')
@patch('subprocess.run')
def test_apt_fix(run, apt_run):
"""Test that apt fixes work."""
distupgrade._apt_fix()
assert run.call_args_list == [
call(['dpkg', '--configure', '-a'], check=False)
]
assert apt_run.call_args_list == [call(['--fix-broken', 'install'])]
@patch('plinth.modules.upgrades.distupgrade._apt_run')
def test_apt_autoremove(apt_run):
"""Test that apt autoremove works."""