mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
upgrades: Move start-dist-upgrade result string to app
Separate checking for dist upgrade from other setup. We don't want to start a dist upgrade during the module's setup. Tests: Checked logs for the following: - Up to date. - Updates not enabled. - Dist upgrade started. Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
parent
d747f77f80
commit
3ada482b90
@ -320,12 +320,11 @@ def _check_dist_upgrade(test_upgrade=False):
|
||||
if not.
|
||||
"""
|
||||
if dist_upgrade_flag.exists():
|
||||
return (True, 'Found previously interrupted dist-upgrade.')
|
||||
return (True, 'found-previous')
|
||||
|
||||
release, dist = get_current_release()
|
||||
if release in ['unstable', 'testing']:
|
||||
return (False, f'System release is {release}. Skip checking for new '
|
||||
'stable release.')
|
||||
return (False, f'already-{release}')
|
||||
|
||||
check_dists = ['stable']
|
||||
if test_upgrade:
|
||||
@ -351,23 +350,22 @@ def _check_dist_upgrade(test_upgrade=False):
|
||||
codename = line.split()[1]
|
||||
|
||||
if not codename:
|
||||
return (False, '"Codename:" not found in release file.')
|
||||
return (False, 'codename-not-found')
|
||||
|
||||
if codename == dist:
|
||||
return (False, f'{dist} is already the latest release.')
|
||||
return (False, f'already-{dist}')
|
||||
|
||||
if not _check_auto():
|
||||
return (False, 'Automatic updates are not enabled.')
|
||||
return (False, 'upgrades-not-enabled')
|
||||
|
||||
if check_dist == 'testing' and not test_upgrade:
|
||||
return (False, f'Skipping dist-upgrade to {check_dist} since --test is'
|
||||
' not set.')
|
||||
return (False, 'test-not-set')
|
||||
|
||||
output = subprocess.check_output(['df', '--output=avail,pcent', '/'])
|
||||
output = output.decode().split('\n')[1].split()
|
||||
free_space, free_percent = int(output[0]), int(output[1][:-1])
|
||||
if free_space < 5000000 or free_percent < 10:
|
||||
return (False, 'Not enough free space in /.')
|
||||
return (False, 'not-enough-free-space')
|
||||
|
||||
logging.info('Upgrading from %s to %s...', dist, codename)
|
||||
with open(SOURCES_LIST, 'r') as sources_list:
|
||||
@ -389,7 +387,7 @@ def _check_dist_upgrade(test_upgrade=False):
|
||||
|
||||
logging.info('Dist upgrade in progress. Setting flag.')
|
||||
dist_upgrade_flag.touch(mode=0o660)
|
||||
return (True, 'Started dist upgrade.')
|
||||
return (True, 'started-dist-upgrade')
|
||||
|
||||
|
||||
def _perform_dist_upgrade():
|
||||
|
||||
@ -91,10 +91,14 @@ class UpgradesApp(app_module.App):
|
||||
|
||||
# Check every day (every 3 minutes in debug mode):
|
||||
# - backports becomes available -> configure it if selected by user
|
||||
interval = 180 if cfg.develop else 24 * 3600
|
||||
glib.schedule(interval, setup_repositories)
|
||||
|
||||
# Check every day (every 3 minutes in debug mode):
|
||||
# - new stable release becomes available -> perform dist-upgrade if
|
||||
# updates are enabled
|
||||
interval = 180 if cfg.develop else 24 * 3600
|
||||
glib.schedule(interval, setup_repositories)
|
||||
glib.schedule(interval, check_dist_upgrade)
|
||||
|
||||
def _show_new_release_notification(self):
|
||||
"""When upgraded to new release, show a notification."""
|
||||
@ -169,8 +173,8 @@ def disable():
|
||||
actions.superuser_run('upgrades', ['disable-auto'])
|
||||
|
||||
|
||||
def setup_repositories(data):
|
||||
"""Setup apt repositories for backports or new stable release."""
|
||||
def setup_repositories(_):
|
||||
"""Setup apt repositories for backports."""
|
||||
if is_backports_requested():
|
||||
command = ['activate-backports']
|
||||
if cfg.develop:
|
||||
@ -178,13 +182,35 @@ def setup_repositories(data):
|
||||
|
||||
actions.superuser_run('upgrades', command)
|
||||
|
||||
|
||||
def check_dist_upgrade(_):
|
||||
"""Check for upgrade to new stable release."""
|
||||
if is_dist_upgrade_enabled():
|
||||
output = actions.superuser_run('upgrades', ['start-dist-upgrade'])
|
||||
result = json.loads(output)
|
||||
dist_upgrade_started = result['dist_upgrade_started']
|
||||
reason = result['reason']
|
||||
logger.info('Result of start-dist-upgrade: %s, %s',
|
||||
dist_upgrade_started, reason)
|
||||
if 'found-previous' in reason:
|
||||
logger.info(
|
||||
'Found previous dist-upgrade. If it was interrupted, it will '
|
||||
'be restarted.')
|
||||
elif 'already-' in reason:
|
||||
logger.info('Skip dist upgrade: System is already up-to-date.')
|
||||
elif 'codename-not-found' in reason:
|
||||
logger.warning('Skip dist upgrade: Codename not found in release '
|
||||
'file.')
|
||||
elif 'upgrades-not-enabled' in reason:
|
||||
logger.info('Skip dist upgrade: Automatic updates are not '
|
||||
'enabled.')
|
||||
elif 'test-not-set' in reason:
|
||||
logger.info('Skip dist upgrade: --test is not set.')
|
||||
elif 'not-enough-free-space' in reason:
|
||||
logger.warning('Skip dist upgrade: Not enough free space in /.')
|
||||
elif 'started-dist-upgrade' in reason:
|
||||
logger.info('Started dist upgrade.')
|
||||
else:
|
||||
logger.warning('Unhandled result of start-dist-upgrade: %s, %s',
|
||||
dist_upgrade_started, reason)
|
||||
|
||||
|
||||
def is_backports_requested():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user