upgrades: Disable apt snapshots during dist upgrade

Take a snapshot before dist upgrade, if supported.

Tests:
- Ran dist upgrade test with apt snapshots enabled. Snapshot is taken
  at beginning. Apt snapshots are enabled at end.
- Ran dist upgrade test with apt snapshots disabled. Snapshot is taken
  at beginning. Apt snapshots are disabled at end.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2021-02-07 15:39:46 -05:00
parent 72716366c1
commit 4db96b17e5
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -18,6 +18,9 @@ from plinth.action_utils import (apt_hold, debconf_set_selections,
run_apt_command, service_daemon_reload,
service_restart)
from plinth.modules.apache.components import check_url
from plinth.modules.snapshot import (is_apt_snapshots_enabled, is_supported as
snapshot_is_supported, load_augeas as
snapshot_load_augeas)
from plinth.modules.upgrades import (BACKPORTS_SOURCES_LIST, SOURCES_LIST,
get_current_release, is_backports_current)
@ -397,6 +400,26 @@ def _check_dist_upgrade(test_upgrade=False):
def _perform_dist_upgrade():
"""Perform upgrade to next release of Debian."""
# Take a snapshot if supported and enabled, then disable snapshots.
snapshots_supported = snapshot_is_supported()
if snapshots_supported:
print('Taking a snapshot before dist upgrade...', flush=True)
subprocess.run(['/usr/share/plinth/actions/snapshot', 'create'],
check=True)
aug = snapshot_load_augeas()
apt_snapshots_enabled = is_apt_snapshots_enabled(aug)
if apt_snapshots_enabled:
print('Disable apt snapshots during dist upgrade...', flush=True)
subprocess.run([
'/usr/share/plinth/actions/snapshot', 'disable-apt-snapshot',
'yes'
], check=True)
else:
print('Apt snapshots already disabled.', flush=True)
else:
print('Snapshots are not supported, skip taking a snapshot.',
flush=True)
# Hold freedombox package during entire dist upgrade.
print('Holding freedombox package...', flush=True)
with apt_hold():
@ -448,6 +471,13 @@ def _perform_dist_upgrade():
print('Running unattended-upgrade...', flush=True)
subprocess.run(['unattended-upgrade', '--verbose'])
# Restore original snapshots configuration.
if snapshots_supported and apt_snapshots_enabled:
print('Re-enable apt snapshots...', flush=True)
subprocess.run([
'/usr/share/plinth/actions/snapshot', 'disable-apt-snapshot', 'no'
], check=True)
# Restart FreedomBox service to ensure it is using the latest
# dependencies.
print('Restarting FreedomBox service...', flush=True)