Beispiel #1
0
 def run(self):
     self.message = 'Downloading Updates...'
     self.set_progress(0)
     handler = UpdateHandler(self.dispatcher,
                             update_progress=self.update_progress)
     train = self.configstore.get('update.train')
     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'
     try:
         download_successful = DownloadUpdate(
             train,
             cache_dir,
             get_handler=handler.get_handler,
             check_handler=handler.check_handler,
         )
     except Exception as e:
         raise TaskException(
             errno.EAGAIN,
             'Got exception {0} while trying to Download Updates'.format(
                 str(e)))
     if not download_successful:
         handler.error = True
         handler.emit_update_details()
         raise TaskException(
             errno.EAGAIN,
             'Downloading Updates Failed for some reason, check logs')
     handler.finished = True
     handler.emit_update_details()
     self.message = "Updates Finished Downloading"
     self.set_progress(100)
Beispiel #2
0
 def run(self):
     self.message = 'Downloading Updates...'
     self.set_progress(0)
     handler = UpdateHandler(self.dispatcher,
                             update_progress=self.update_progress)
     train = self.configstore.get('update.train')
     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'
     try:
         download_successful = DownloadUpdate(
             train,
             cache_dir,
             get_handler=handler.get_handler,
             check_handler=handler.check_handler)
     except ManifestInvalidSignature as e:
         raise TaskException(
             errno.EBADMSG,
             'Latest manifest has invalid signature: {0}'.format(str(e)))
     except UpdateIncompleteCacheException as e:
         raise TaskException(
             errno.EIO,
             'Possibly with no network, cached update is incomplete')
     except UpdateBusyCacheException as e:
         raise TaskException(errno.EBUSY, str(e))
     except ChecksumFailException as e:
         raise TaskException(errno.EBADMSG, str(e))
     except UpdatePackageNotFound as e:
         raise TaskException(
             errno.EIO,
             "Update Package: '{0}' Not Found. This could be due to a failed Download"
             .format(str(e)))
     except Exception as e:
         raise TaskException(
             errno.EAGAIN,
             'Got exception {0} while trying to Download Updates'.format(
                 str(e)))
     if not download_successful:
         handler.error = True
         handler.emit_update_details()
         raise TaskException(
             errno.EAGAIN,
             'Downloading Updates Failed for some reason, check logs')
     check_updates(self.dispatcher,
                   self.configstore,
                   cache_dir=cache_dir,
                   check_now=False)
     handler.finished = True
     handler.emit_update_details()
     self.message = "Updates Finished Downloading"
     self.set_progress(100)
Beispiel #3
0
def update_check(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')
        if request.POST.get('apply') == '1':
            apply_ = True
        else:
            apply_ = False
        handler = UpdateHandler(uuid=uuid, apply_=apply_)
        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:
                    if handler.apply:
                        Update(
                            train=updateobj.get_train(),
                            get_handler=handler.get_handler,
                            install_handler=handler.install_handler,
                            cache_dir='%s/update' % path,
                        )
                    else:
                        DownloadUpdate(
                            updateobj.get_train(),
                            '%s/update' % path,
                            check_handler=handler.get_handler,
                            get_handler=handler.get_file_handler,
                        )
                except Exception, e:
                    from freenasUI.common.log import log_traceback
                    log_traceback(log=log)
                    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()
            if handler.apply:
                request.session['allow_reboot'] = True
                return render(request, 'system/done.html')
            else:
                return JsonResp(
                    request,
                    message=_('Packages downloaded'),
                )