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 2025-03-11 15:27:34 -07:00 committed by James Valleroy
parent bbb59e16de
commit 91c5931c59
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 19 additions and 0 deletions

View File

@ -223,6 +223,13 @@ def _apt_update():
_apt_run(['update'])
def _apt_fix():
"""Try to fix any problems with apt/dpkg before the upgrade."""
logger.info('Fixing any broken apt/dpkg states...')
subprocess.run(['dpkg', '--configure', '-a'], check=False)
_apt_run(['--fix-broken', 'install'])
def _apt_autoremove():
"""Run 'apt autoremove'."""
logger.info('Running apt autoremove...')
@ -298,6 +305,7 @@ def perform():
_services_disable(), \
_apt_hold_packages():
_apt_update()
_apt_fix()
_debconf_set_selections()
_packages_remove_obsolete()
_apt_full_upgrade()

View File

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