Example #1
0
 def test_http_schedule_delete_swallows_error(self):
     uri = "https://netloc/path/to/file.tar.gz"
     ctx = context.RequestContext()
     stub_out_registry_image_update(self.stubs)
     try:
         safe_delete_from_backend(ctx, uri, 'image_id')
     except exception.StoreDeleteNotSupported:
         self.fail('StoreDeleteNotSupported should be swallowed')
Example #2
0
    def delete(self, req, id):
        """
        Deletes the image and all its chunks from the Glance

        :param req: The WSGI/Webob Request object
        :param id: The opaque image identifier

        :raises HttpBadRequest if image registry is invalid
        :raises HttpNotFound if image or any chunk is not available
        :raises HttpUnauthorized if image or any chunk is not
                deleteable by the requesting user
        """
        self._enforce(req, 'delete_image')

        image = self.get_image_meta_or_404(req, id)
        if image['protected']:
            msg = _("Image is protected")
            LOG.debug(msg)
            raise HTTPForbidden(explanation=msg,
                                request=req,
                                content_type="text/plain")

        if image['status'] == 'deleted':
            msg = _("Forbidden to delete a deleted image.")
            LOG.debug(msg)
            raise HTTPForbidden(explanation=msg, request=req,
                                content_type="text/plain")

        if image['location'] and CONF.delayed_delete:
            status = 'pending_delete'
        else:
            status = 'deleted'

        try:
            # Delete the image from the registry first, since we rely on it
            # for authorization checks.
            # See https://bugs.launchpad.net/glance/+bug/1065187
            registry.update_image_metadata(req.context, id, {'status': status})
            registry.delete_image_metadata(req.context, id)

            # The image's location field may be None in the case
            # of a saving or queued image, therefore don't ask a backend
            # to delete the image if the backend doesn't yet store it.
            # See https://bugs.launchpad.net/glance/+bug/747799
            if image['location']:
                if CONF.delayed_delete:
                    schedule_delayed_delete_from_backend(image['location'], id)
                else:
                    safe_delete_from_backend(image['location'],
                                             req.context, id)
        except exception.NotFound, e:
            msg = (_("Failed to find image to delete: %(e)s") % locals())
            for line in msg.split('\n'):
                LOG.info(line)
            raise HTTPNotFound(explanation=msg,
                               request=req,
                               content_type="text/plain")
Example #3
0
    def delete(self, req, id):
        """
        Deletes the image and all its chunks from the Glance

        :param req: The WSGI/Webob Request object
        :param id: The opaque image identifier

        :raises HttpBadRequest if image registry is invalid
        :raises HttpNotFound if image or any chunk is not available
        :raises HttpUnauthorized if image or any chunk is not
                deleteable by the requesting user
        """
        self._enforce(req, 'delete_image')

        image = self.get_image_meta_or_404(req, id)
        if image['protected']:
            msg = _("Image is protected")
            LOG.debug(msg)
            raise HTTPForbidden(explanation=msg,
                                request=req,
                                content_type="text/plain")

        # The image's location field may be None in the case
        # of a saving or queued image, therefore don't ask a backend
        # to delete the image if the backend doesn't yet store it.
        # See https://bugs.launchpad.net/glance/+bug/747799
        try:
            if image['location']:
                if CONF.delayed_delete:
                    schedule_delayed_delete_from_backend(image['location'], id)
                    registry.update_image_metadata(
                        req.context, id, {'status': 'pending_delete'})
                else:
                    safe_delete_from_backend(image['location'], req.context,
                                             id)
                    registry.update_image_metadata(req.context, id,
                                                   {'status': 'deleted'})
            registry.delete_image_metadata(req.context, id)
        except exception.NotFound, e:
            msg = ("Failed to find image to delete: %(e)s" % locals())
            for line in msg.split('\n'):
                LOG.info(line)
            self.notifier.info('image.delete', msg)
            raise HTTPNotFound(explanation=msg,
                               request=req,
                               content_type="text/plain")
Example #4
0
 def _initiate_deletion(req, location, id):
     if CONF.delayed_delete:
         schedule_delayed_delete_from_backend(location, id)
     else:
         safe_delete_from_backend(location, req.context, id)
Example #5
0
 def _initiate_deletion(req, location, id):
     if CONF.delayed_delete:
         schedule_delayed_delete_from_backend(location, id)
     else:
         safe_delete_from_backend(location, req.context, id)
Example #6
0
 def test_http_schedule_delete_swallows_error(self):
     uri = "https://netloc/path/to/file.tar.gz"
     try:
         safe_delete_from_backend(uri, 'image_id', {})
     except exceptions.StoreDeleteNotSupported:
         self.fail('StoreDeleteNotSupported should be swallowed')