def run(self): log = "Running the {}-update scripts...".format(self._type) logger.info(log) current_version = self._old_version target_version = get_target_version() while current_version < target_version: step_found = False for (from_version, to_version), func in self._scenarios.iteritems(): if current_version == from_version: msg = "Running {}-update from {} to {}.".format( self._type, from_version, to_version) logger.info(msg) func() current_version = to_version step_found = True break if not step_found: msg = "{}-update step missing".format(self._type) update_failed(msg) raise Exception(msg) self._finalise()
def run(self, progress): log = "Running the {}-update scripts...".format(self._type) logger.info(log) current_version = self._old_version target_version = get_target_version() while current_version < target_version: step_found = False for (from_version, to_version), func in self._scenarios.iteritems(): if current_version == from_version: msg = "Running {}-update from {} to {}.".format( self._type, from_version, to_version ) logger.info(msg) func(progress) current_version = to_version step_found = True break if not step_found: msg = "{}-update step missing".format(self._type) update_failed(msg) raise Exception(msg) self._finalise()
def test_install(apt, state, system_version, free_space, run_cmd, internet, server_available, autologin_checks): import kano_updater.commands.install space_available, space_required = free_space progress = PyTestProgress() should_succeed = internet and server_available and \ (space_available >= space_required) relaunch_expected = system_version <= get_target_version() rc_warning = ( 'NOTE: Return value from install() is now coupled to whether the ' 'updater requires a relaunch.') try: res = kano_updater.commands.install.install(progress=progress, gui=False) assert ( res == should_succeed and should_succeed == tests.fixtures.autologin_checks.all_checks(autologin_checks)) if relaunch_expected and should_succeed: pytest.fail("Updater should have relaunched but didn't\n\n" + rc_warning) except AbortError: assert not should_succeed except AssertionError: if relaunch_expected: pytest.xfail(rc_warning) else: raise
def covers_update(self): min_version = self._old_version max_version = get_target_version() current_version = min_version while current_version < max_version: next_step = None for from_version, to_version in self._scenarios.iterkeys(): if current_version == from_version: next_step = to_version break if next_step is None: return False else: current_version = next_step return True
def covers_update(self): min_version = self._old_version max_version = get_target_version() current_version = min_version while current_version < max_version: next_step = None for from_version, to_version in self._scenarios.iterkeys(): if current_version == from_version \ and to_version <= max_version: next_step = to_version break if next_step is None: return False else: current_version = next_step return True
def test_install(apt, state, system_version, free_space, run_cmd, internet, server_available, autologin_checks): import kano_updater.commands.install space_available, space_required = free_space progress = PyTestProgress() should_succeed = internet and server_available and \ (space_available >= space_required) relaunch_expected = system_version <= get_target_version() rc_warning = ( 'NOTE: Return value from install() is now coupled to whether the ' 'updater requires a relaunch.' ) try: res = kano_updater.commands.install.install( progress=progress, gui=False ) assert( res == should_succeed and should_succeed == tests.fixtures.autologin_checks.all_checks(autologin_checks) ) if relaunch_expected and should_succeed: pytest.fail( "Updater should have relaunched but didn't\n\n" + rc_warning ) except AbortError: assert not should_succeed except AssertionError: if relaunch_expected: pytest.xfail(rc_warning) else: raise
def install_standard(progress, status): progress.split( Phase( 'init', _("Starting Update"), 10, is_main=True ), Phase( 'updating-itself', _("Updating Itself"), 10, is_main=True ), Phase( 'preupdate', _("Running The Preupdate Scripts"), 10, is_main=True ), Phase( 'updating-deb-packages', _("Updating Deb Packages"), 30, is_main=True ), Phase( 'postupdate', _("Running The Postupdate Scripts"), 10, is_main=True ), Phase( 'aux-tasks', _("Performing auxiliary tasks"), 10, is_main=True ) ) progress.start('init') apt_handle = AptWrapper.get_instance() apt_handle.clear_cache() apt_handle.fix_broken(progress) # determine the versions (from and to) system_version = get_system_version() target_version = get_target_version() msg = "Upgrading from {} to {}".format(system_version, target_version) logger.info(msg) # set up the scenarios and check whether they cover updating # from this version preup = PreUpdate(system_version) postup = PostUpdate(system_version) if not (preup.covers_update() and postup.covers_update()): title = _("Unfortunately, your version of Kano OS is too old " "to be updated through the updater.") description = _("You will need to download the image of the " "OS and reflash your SD card.") msg = "{}: {}".format(title, description) logger.error("Updating from a version that is no longer supported ({})" .format(system_version)) progress.fail(msg) raise InstallError(msg) old_updater = apt_handle.get_package('kano-updater').installed.version progress.start('updating-itself') apt_handle.upgrade('kano-updater', progress) # relaunch if the updater has changed new_updater = apt_handle.get_package('kano-updater') if old_updater != new_updater.installed.version: # Remove the installation in progress status so it doesn't # block the start of the new instance. status.state = UpdaterStatus.UPDATES_DOWNLOADED status.save() logger.info("The updater has been updated, relaunching.") progress.relaunch() return False progress.start('preupdate') try: preup.run(progress) except Relaunch: progress.relaunch() return False except Exception as e: logger.error("The pre-update scenarios failed", exception=e) progress.abort("The pre-update tasks failed.") raise logger.info("Updating deb packages") progress.start('updating-deb-packages') install_deb_packages(progress) progress.start('postupdate') try: postup.run(progress) except Relaunch: bump_system_version() progress.relaunch() return False except Exception as e: logger.error("The post-update scenarios failed", exception=e) progress.abort("The post-update tasks failed.") raise bump_system_version() # We don't care too much when these fail progress.start('aux-tasks') run_aux_tasks(progress) return True
def install_standard(progress, status): progress.split( Phase('init', _("Starting Update"), 10, is_main=True), Phase('updating-itself', _("Updating Itself"), 10, is_main=True), Phase('preupdate', _("Running The Preupdate Scripts"), 10, is_main=True), Phase('updating-deb-packages', _("Updating Deb Packages"), 30, is_main=True), Phase('postupdate', _("Running The Postupdate Scripts"), 10, is_main=True), Phase('aux-tasks', _("Performing auxiliary tasks"), 10, is_main=True)) progress.start('init') apt_handle = AptWrapper.get_instance() apt_handle.clear_cache() apt_handle.fix_broken(progress) # determine the versions (from and to) system_version = get_system_version() target_version = get_target_version() msg = "Upgrading from {} to {}".format(system_version, target_version) logger.info(msg) # set up the scenarios and check whether they cover updating # from this version preup = PreUpdate(system_version) postup = PostUpdate(system_version) if not (preup.covers_update() and postup.covers_update()): title = _("Unfortunately, your version of Kano OS is too old " \ "to be updated through the updater.") description = _("You will need to download the image of the " \ "OS and reflash your SD card.") msg = "{}: {}".format(title, description) logger.error( "Updating from a version that is no longer supported ({})".format( system_version)) progress.fail(msg) raise InstallError(msg) old_updater = apt_handle.get_package('kano-updater').installed.version progress.start('updating-itself') apt_handle.upgrade('kano-updater', progress) # relaunch if the updater has changed new_updater = apt_handle.get_package('kano-updater') if old_updater != new_updater.installed.version: # Remove the installation in progress status so it doesn't # block the start of the new instance. status.state = UpdaterStatus.UPDATES_DOWNLOADED status.save() logger.info("The updater has been updated, relaunching.") progress.relaunch() return False progress.start('preupdate') try: preup.run() except Exception as err: logger.error("The pre-update scenarios failed.") logger.error(err.encode('utf-8')) progress.abort("The pre-update tasks failed.") raise logger.debug("Updating deb packages") progress.start('updating-deb-packages') install_deb_packages(progress) progress.start('postupdate') try: postup.run() except Exception as err: logger.error("The post-update scenarios failed.") logger.error(err.encode('utf-8')) progress.abort("The post-update tasks failed.") raise bump_system_version() # We don't care too much when these fail progress.start('aux-tasks') run_aux_tasks(progress)