Exemple #1
0
    def manual(self, job, path):
        """
        Apply manual update of file `path`.
        """
        dest_extracted = os.path.join(os.path.dirname(path), '.update')
        try:
            try:
                job.set_progress(30, 'Extracting file')
                ExtractFrozenUpdate(path, dest_extracted, verbose=True)
                job.set_progress(50, 'Applying update')
                ApplyUpdate(dest_extracted)
            except Exception as e:
                self.logger.debug('Applying manual update failed',
                                  exc_info=True)
                raise CallError(str(e), errno.EFAULT)

            job.set_progress(95, 'Cleaning up')
        finally:
            if os.path.exists(path):
                os.unlink(path)

            if os.path.exists(dest_extracted):
                shutil.rmtree(dest_extracted, ignore_errors=True)

        if path.startswith(UPLOAD_LOCATION):
            self.middleware.call_sync('update.destroy_upload_location')
Exemple #2
0
 def do_update():
     try:
         job.set_progress(30, 'Extracting uploaded file')
         ExtractFrozenUpdate(destfile, dest_extracted, verbose=True)
         job.set_progress(50, 'Applying update')
         ApplyUpdate(dest_extracted)
     except Exception as e:
         raise CallError(str(e))
Exemple #3
0
 def do_update():
     try:
         job.set_progress(30, 'Extracting uploaded file')
         ExtractFrozenUpdate(destfile, dest_extracted, verbose=True)
         job.set_progress(50, 'Applying update')
         if ApplyUpdate(dest_extracted) is None:
             raise ValueError(
                 'Uploaded file is not a manual update file')
     except Exception as e:
         raise CallError(str(e))
Exemple #4
0
 def run(self):
     self.message = 'Applying Updates...'
     self.set_progress(0)
     handler = UpdateHandler(self.dispatcher,
                             update_progress=self.update_progress)
     cache_dir = update_cache.get('cache_dir')
     if cache_dir is None:
         try:
             cache_dir = self.dispatcher.call_sync(
                 'system-dataset.request_directory', 'update')
         except RpcException:
             cache_dir = '/var/tmp/update'
     # Note: for now we force reboots always, TODO: Fix in M3-M4
     try:
         ApplyUpdate(cache_dir,
                     install_handler=handler.install_handler,
                     force_reboot=True)
     except ManifestInvalidSignature as e:
         logger.debug(
             'UpdateApplyTask Error: Cached manifest has invalid signature: %s',
             e)
         raise TaskException(
             errno.EINVAL,
             'Cached manifest has invalid signature: {0}'.format(str(e)))
     except UpdateBootEnvironmentException as e:
         logger.debug('UpdateApplyTask Boot Environment Error: {0}'.format(
             str(e)))
         raise TaskException(errno.EAGAIN, str(e))
     except UpdatePackageException as e:
         logger.debug('UpdateApplyTask Package Error: {0}'.format(str(e)))
         raise TaskException(errno.EAGAIN, str(e))
     except Exception as e:
         raise TaskException(
             errno.EAGAIN,
             'Got exception {0} while trying to Apply Updates'.format(
                 str(e)))
     handler.finished = True
     handler.emit_update_details()
     self.message = "Updates Finished Installing Successfully"
     self.set_progress(100)
Exemple #5
0
def update_apply(request):

    try:
        updateobj = models.Update.objects.order_by('-id')[0]
    except IndexError:
        updateobj = models.Update.objects.create()

    if request.method == 'POST':
        uuid = request.GET.get('uuid')
        handler = UpdateHandler(uuid=uuid)
        if not uuid:
            #FIXME: ugly
            pid = os.fork()
            if pid != 0:
                return HttpResponse(handler.uuid, status=202)
            else:
                handler.pid = os.getpid()
                handler.dump()
                path = notifier().system_dataset_path()
                if not path:
                    raise MiddlewareError(_('System dataset not configured'))
                try:
                    ApplyUpdate(
                        '%s/update' % path,
                        install_handler=handler.install_handler,
                    )
                except Exception, e:
                    handler.error = unicode(e)
                handler.finished = True
                handler.dump()
                os.kill(handler.pid, 9)
        else:
            if handler.error is not False:
                raise MiddlewareError(handler.error)
            if not handler.finished:
                return HttpResponse(handler.uuid, status=202)
            handler.exit()
            request.session['allow_reboot'] = True
            return render(request, 'system/done.html')
Exemple #6
0
 def run(self, reboot_post_install=False):
     self.message = 'Applying Updates...'
     self.set_progress(0)
     handler = UpdateHandler(self.dispatcher,
                             update_progress=self.update_progress)
     cache_dir = self.dispatcher.call_sync('update.update_cache_getter',
                                           'cache_dir')
     if cache_dir is None:
         try:
             cache_dir = self.dispatcher.call_sync(
                 'system_dataset.request_directory', 'update')
         except RpcException:
             cache_dir = '/var/tmp/update'
     new_manifest = Manifest.Manifest(require_signature=True)
     try:
         new_manifest.LoadPath(cache_dir + '/MANIFEST')
     except ManifestInvalidSignature as e:
         logger.error("Cached manifest has invalid signature: %s" % str(e))
         raise TaskException(errno.EINVAL, str(e))
     except FileNotFoundError as e:
         raise TaskException(
             errno.EIO,
             'No Manifest file found at path: {0}'.format(cache_dir +
                                                          '/MANIFEST'))
     version = new_manifest.Version()
     # Note: for now we force reboots always, TODO: Fix in M3-M4
     try:
         result = ApplyUpdate(cache_dir,
                              install_handler=handler.install_handler,
                              force_reboot=True)
     except ManifestInvalidSignature as e:
         logger.debug(
             'UpdateApplyTask Error: Cached manifest has invalid signature: %s',
             e)
         raise TaskException(
             errno.EINVAL,
             'Cached manifest has invalid signature: {0}'.format(str(e)))
     except UpdateBootEnvironmentException as e:
         logger.debug('UpdateApplyTask Boot Environment Error: {0}'.format(
             str(e)))
         raise TaskException(errno.EAGAIN, str(e))
     except UpdatePackageException as e:
         logger.debug('UpdateApplyTask Package Error: {0}'.format(str(e)))
         raise TaskException(errno.EAGAIN, str(e))
     except Exception as e:
         raise TaskException(
             errno.EAGAIN,
             'Got exception {0} while trying to Apply Updates'.format(
                 str(e)))
     if result is None:
         raise TaskException(errno.ENOENT,
                             'No downloaded Updates available to apply.')
     handler.finished = True
     handler.emit_update_details()
     self.dispatcher.call_sync('update.update_alert_set', 'UpdateInstalled',
                               version)
     update_cache_value_dict = default_update_dict.copy()
     update_cache_value_dict.update({
         'installed': True,
         'installed_version': version
     })
     self.dispatcher.call_sync('update.update_cache_putter',
                               update_cache_value_dict)
     self.message = "Updates Finished Installing Successfully"
     if reboot_post_install:
         self.message = "Scheduling user specified reboot post succesfull update"
         # Note not using subtasks on purpose as they do not have queuing logic
         self.dispatcher.submit_task('system.reboot', 3)
     self.set_progress(100)