示例#1
0
    def revert(self, result, **kwargs):
        if isinstance(result, failure.Failure):
            LOG.error(
                _LE('Task: %(task_id)s failed to import image '
                    '%(image_id)s to the filesystem.'), {
                        'task_id': self.task_id,
                        'image_id': self.image_id
                    })
            # NOTE(abhishekk): Revert image state back to 'queued' as
            # something went wrong.
            image = self.image_repo.get(self.image_id)
            image.status = 'queued'
            self.image_repo.save(image)

        # NOTE(abhishekk): Deleting partial image data from staging area
        if self._path is not None:
            LOG.debug(('Deleting image %(image_id)s from staging '
                       'area.'), {'image_id': self.image_id})
            try:
                if CONF.enabled_backends:
                    store_api.delete(self._path, None)
                else:
                    store_api.delete_from_backend(self._path)
            except Exception:
                LOG.exception(
                    _LE("Error reverting web-download "
                        "task: %(task_id)s"), {'task_id': self.task_id})
示例#2
0
    def revert(self, result, **kwargs):
        if isinstance(result, failure.Failure):
            LOG.error(_LE('Task: %(task_id)s failed to import image '
                          '%(image_id)s to the filesystem.'),
                      {'task_id': self.task_id,
                       'image_id': self.image_id})
            # NOTE(abhishekk): Revert image state back to 'queued' as
            # something went wrong.
            # NOTE(danms): If we failed to stage the image, then none
            # of the _ImportToStore() tasks could have run, so we need
            # to move all stores out of "importing" and into "failed".
            with self.action_wrapper as action:
                action.set_image_attribute(status='queued')
                action.remove_importing_stores(self.stores)
                action.add_failed_stores(self.stores)

        # NOTE(abhishekk): Deleting partial image data from staging area
        if self._path is not None:
            LOG.debug(('Deleting image %(image_id)s from staging '
                       'area.'), {'image_id': self.image_id})
            try:
                if CONF.enabled_backends:
                    store_api.delete(self._path, None)
                else:
                    store_api.delete_from_backend(self._path)
            except Exception:
                LOG.exception(_LE("Error reverting web-download "
                                  "task: %(task_id)s"), {
                    'task_id': self.task_id})
示例#3
0
def delete_csar(context, package_uuid, location):

    try:
        glance_store.delete_from_backend(location, context)
    except store_exceptions.NotFound:
        LOG.info(
            "Failed to find csar data in glance store for "
            "package %(uuid)s", {"uuid": package_uuid})
示例#4
0
    def revert(self, image_id, result, **kwargs):
        if isinstance(result, failure.Failure):
            LOG.exception(_LE('Task: %(task_id)s failed to import image '
                              '%(image_id)s to the filesystem.'),
                          {'task_id': self.task_id, 'image_id': image_id})
            return

        if os.path.exists(result.split("file://")[-1]):
            store_api.delete_from_backend(result)
示例#5
0
    def revert(self, image_id, result=None, **kwargs):
        # NOTE(flaper87): If result is None, it probably
        # means this task failed. Otherwise, we would have
        # a result from its execution.
        if result is None:
            return

        if os.path.exists(result.split("file://")[-1]):
            store_api.delete_from_backend(result)
示例#6
0
    def revert(self, image_id, result=None, **kwargs):
        # NOTE(flaper87): If result is None, it probably
        # means this task failed. Otherwise, we would have
        # a result from its execution.
        if result is None:
            return

        if os.path.exists(result.split("file://")[-1]):
            store_api.delete_from_backend(result)
示例#7
0
    def execute(self, file_path):
        """Remove file from the backend

        :param file_path: path to the file being deleted
        """
        if CONF.enabled_backends:
            store_api.delete(file_path, 'os_glance_tasks_store')
        else:
            store_api.delete_from_backend(file_path)
示例#8
0
 def _scrubber_cleanup_with_store_delete_exception(self, ex):
     uri = 'file://some/path/%s' % uuid.uuid4()
     id = 'helloworldid'
     scrub = scrubber.Scrubber(glance_store)
     self.mox.StubOutWithMock(glance_store, "delete_from_backend")
     glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndRaise(ex)
     self.mox.ReplayAll()
     scrub._scrub_image(id, [(id, '-', uri)])
     self.mox.VerifyAll()
示例#9
0
    def revert(self, image_id, result, **kwargs):
        if isinstance(result, failure.Failure):
            LOG.exception(_LE('Task: %(task_id)s failed to import image '
                              '%(image_id)s to the filesystem.'),
                          {'task_id': self.task_id, 'image_id': image_id})
            return

        if os.path.exists(result.split("file://")[-1]):
            store_api.delete_from_backend(result)
示例#10
0
    def test_store_delete_successful(self, mock_image_get):
        uri = 'file://some/path/%s' % uuid.uuid4()
        id = 'helloworldid'

        scrub = scrubber.Scrubber(glance_store)
        self.mox.StubOutWithMock(glance_store, "delete_from_backend")
        glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndReturn('')
        self.mox.ReplayAll()
        scrub._scrub_image(id, [(id, '-', uri)])
        self.mox.VerifyAll()
示例#11
0
 def _scrubber_cleanup_with_store_delete_exception(self, ex):
     uri = "file://some/path/%s" % uuid.uuid4()
     id = "helloworldid"
     scrub = scrubber.Scrubber(glance_store)
     scrub.registry = self.mox.CreateMockAnything()
     scrub.registry.get_image(id).AndReturn({"status": "pending_delete"})
     scrub.registry.update_image(id, {"status": "deleted"})
     self.mox.StubOutWithMock(glance_store, "delete_from_backend")
     glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndRaise(ex)
     self.mox.ReplayAll()
     scrub._scrub_image(eventlet.greenpool.GreenPool(1), id, [(id, "-", uri)])
     self.mox.VerifyAll()
示例#12
0
 def _scrubber_cleanup_with_store_delete_exception(self, ex):
     uri = 'file://some/path/%s' % uuid.uuid4()
     id = 'helloworldid'
     scrub = scrubber.Scrubber(glance_store)
     scrub.registry = self.mox.CreateMockAnything()
     scrub.registry.get_image(id).AndReturn({'status': 'pending_delete'})
     scrub.registry.update_image(id, {'status': 'deleted'})
     self.mox.StubOutWithMock(glance_store, "delete_from_backend")
     glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndRaise(ex)
     self.mox.ReplayAll()
     scrub._scrub_image(id, [(id, '-', uri)])
     self.mox.VerifyAll()
示例#13
0
    def test_store_delete_notfound_exception(self, mock_image_get):
        # While scrubbing image data, NotFound exception is ignored and image
        # scrubbing succeeds
        uri = 'file://some/path/%s' % uuid.uuid4()
        id = 'helloworldid'
        ex = glance_store.NotFound(message='random')

        scrub = scrubber.Scrubber(glance_store)
        self.mox.StubOutWithMock(glance_store, "delete_from_backend")
        glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndRaise(ex)
        self.mox.ReplayAll()
        scrub._scrub_image(id, [(id, '-', uri)])
        self.mox.VerifyAll()
示例#14
0
    def test_store_delete_store_exceptions(self, mock_image_get):
        # While scrubbing image data, all store exceptions, other than
        # NotFound, cause image scrubbing to fail. Essentially, no attempt
        # would be made to update the status of image.

        uri = 'file://some/path/%s' % uuid.uuid4()
        id = 'helloworldid'
        ex = glance_store.GlanceStoreException()

        scrub = scrubber.Scrubber(glance_store)
        self.mox.StubOutWithMock(glance_store, "delete_from_backend")
        glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndRaise(ex)
        self.mox.ReplayAll()
        scrub._scrub_image(id, [(id, '-', uri)])
        self.mox.VerifyAll()
示例#15
0
    def test_scrubber_exits(self):
        # Checks for Scrubber exits when it is not able to fetch jobs from
        # the queue
        uri = 'file://some/path/%s' % uuid.uuid4()
        id = 'helloworldid'

        scrub = scrubber.Scrubber(glance_store)
        scrub.registry = self.mox.CreateMockAnything()
        scrub.registry.get_image(id).AndReturn({'status': 'pending_delete'})
        scrub.registry.update_image(id, {'status': 'deleted'})
        self.mox.StubOutWithMock(glance_store, "delete_from_backend")
        ex = glance_store.GlanceStoreException()
        glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndRaise(ex)
        self.mox.ReplayAll()
        self.assertRaises(exception.FailedToGetScrubberJobs,
                          scrub._get_delete_jobs)
示例#16
0
    def test_store_delete_notfound_exception(self):
        # While scrubbing image data, NotFound exception is ignored and image
        # scrubbing succeeds
        uri = 'file://some/path/%s' % uuid.uuid4()
        id = 'helloworldid'
        ex = glance_store.NotFound(message='random')

        scrub = scrubber.Scrubber(glance_store)
        scrub.registry = self.mox.CreateMockAnything()
        scrub.registry.get_image(id).AndReturn({'status': 'pending_delete'})
        scrub.registry.update_image(id, {'status': 'deleted'})
        self.mox.StubOutWithMock(glance_store, "delete_from_backend")
        glance_store.delete_from_backend(uri, mox.IgnoreArg()).AndRaise(ex)
        self.mox.ReplayAll()
        scrub._scrub_image(id, [(id, '-', uri)])
        self.mox.VerifyAll()
示例#17
0
def safe_delete_from_backend(context, image_id, location):
    """
    Given a location, delete an image from the store and
    update location status to db.

    This function try to handle all known exceptions which might be raised
    by those calls on store and DB modules in its implementation.

    :param context: The request context
    :param image_id: The image identifier
    :param location: The image location entry
    """

    try:
        ret = store_api.delete_from_backend(location['url'], context=context)
        location['status'] = 'deleted'
        if 'id' in location:
            db_api.get_api().image_location_delete(context, image_id,
                                                   location['id'], 'deleted')
        return ret
    except store_api.NotFound:
        msg = _LW('Failed to delete image %s in store from URI') % image_id
        LOG.warn(msg)
    except store_api.StoreDeleteNotSupported as e:
        LOG.warn(encodeutils.exception_to_unicode(e))
    except store_api.UnsupportedBackend:
        exc_type = sys.exc_info()[0].__name__
        msg = (_LE('Failed to delete image %(image_id)s from store: %(exc)s') %
               dict(image_id=image_id, exc=exc_type))
        LOG.error(msg)
示例#18
0
def safe_delete_from_backend(context, image_id, location):
    """
    Given a location, delete an image from the store and
    update location status to db.

    This function try to handle all known exceptions which might be raised
    by those calls on store and DB modules in its implementation.

    :param context: The request context
    :param image_id: The image identifier
    :param location: The image location entry
    """

    try:
        ret = store_api.delete_from_backend(location['url'], context=context)
        location['status'] = 'deleted'
        if 'id' in location:
            db_api.get_api().image_location_delete(context, image_id,
                                                   location['id'], 'deleted')
        return ret
    except store_api.NotFound:
        msg = _LW('Failed to delete image %s in store from URI') % image_id
        LOG.warn(msg)
    except store_api.StoreDeleteNotSupported as e:
        LOG.warn(encodeutils.exception_to_unicode(e))
    except store_api.UnsupportedBackend:
        exc_type = sys.exc_info()[0].__name__
        msg = (_LE('Failed to delete image %(image_id)s from store: %(exc)s') %
               dict(image_id=image_id, exc=exc_type))
        LOG.error(msg)
示例#19
0
    def _scrubber_cleanup_with_store_delete_exception(self, ex):
        uri = 'file://some/path/%s' % uuid.uuid4()
        id = 'helloworldid'
        scrub = scrubber.Scrubber(glance_store)
        scrub.registry = self.mox.CreateMockAnything()
        scrub.registry.get_image(id).AndReturn({'status': 'pending_delete'})
        scrub.registry.update_image(id, {'status': 'deleted'})
        self.mox.StubOutWithMock(glance_store, "delete_from_backend")
        glance_store.delete_from_backend(
            uri,
            mox.IgnoreArg()).AndRaise(ex)
        self.mox.ReplayAll()
        scrub._scrub_image(eventlet.greenpool.GreenPool(1),
                           id, [(id, '-', uri)])
        self.mox.VerifyAll()

        q_path = os.path.join(self.data_dir, id)
        self.assertFalse(os.path.exists(q_path))
示例#20
0
    def _scrubber_cleanup_with_store_delete_exception(self, ex):
        uri = 'file://some/path/%s' % uuid.uuid4()
        id = 'helloworldid'
        scrub = scrubber.Scrubber(glance_store)
        scrub.registry = self.mox.CreateMockAnything()
        scrub.registry.get_image(id).AndReturn({'status': 'pending_delete'})
        scrub.registry.update_image(id, {'status': 'deleted'})
        self.mox.StubOutWithMock(glance_store, "delete_from_backend")
        glance_store.delete_from_backend(
            mox.IgnoreArg(),
            uri).AndRaise(ex)
        self.mox.ReplayAll()
        scrub._scrub_image(eventlet.greenpool.GreenPool(1),
                           id, [(id, '-', uri)])
        self.mox.VerifyAll()

        q_path = os.path.join(self.data_dir, id)
        self.assertFalse(os.path.exists(q_path))
示例#21
0
def safe_delete_from_backend(context, image_id, location):
    """
    Given a location, delete an image from the store and
    update location status to db.

    This function try to handle all known exceptions which might be raised
    by those calls on store and DB modules in its implementation.

    :param context: The request context
    :param image_id: The image identifier
    :param location: The image location entry
    """

    try:
        if CONF.enabled_backends:
            backend = location['metadata'].get('store')
            ret = store_api.delete(location['url'],
                                   backend,
                                   context=context)
        else:
            ret = store_api.delete_from_backend(location['url'],
                                                context=context)

        location['status'] = 'deleted'
        if 'id' in location:
            db_api.get_api().image_location_delete(context, image_id,
                                                   location['id'], 'deleted')
        return ret
    except store_api.NotFound:
        msg = ("The image data for %(iid)s was not found in the store. "
               "The image record has been updated to reflect "
               "this." % {'iid': image_id})
        LOG.warn(msg)
    except store_api.StoreDeleteNotSupported as e:
        LOG.warn(encodeutils.exception_to_unicode(e))
    except store_api.UnsupportedBackend:
        exc_type = sys.exc_info()[0].__name__
        msg = (_LE('Failed to delete image %(image_id)s from store: %(exc)s') %
               dict(image_id=image_id, exc=exc_type))
        LOG.error(msg)
示例#22
0
    def execute(self, file_path):
        """Remove file from the backend

        :param file_path: path to the file being deleted
        """
        store_api.delete_from_backend(file_path)
示例#23
0
    def execute(self, file_path):
        """Remove file from the backend

        :param file_path: path to the file being deleted
        """
        store_api.delete_from_backend(file_path)