Exemplo n.º 1
0
    def test_remove_location_for_store_pop_failures(self, mock_log):
        class TestList(list):
            def pop(self):
                pass

        self.image.locations = TestList([{'metadata': {'store': 'foo'}}])
        with mock.patch.object(self.image.locations,
                               'pop',
                               new_callable=mock.PropertyMock) as mock_pop:

            mock_pop.side_effect = store_exceptions.NotFound(image='image')
            self.actions.remove_location_for_store('foo')
            mock_log.warning.assert_called_once_with(
                _('Error deleting from store foo when reverting.'))
            mock_log.warning.reset_mock()

            mock_pop.side_effect = store_exceptions.Forbidden()
            self.actions.remove_location_for_store('foo')
            mock_log.warning.assert_called_once_with(
                _('Error deleting from store foo when reverting.'))
            mock_log.warning.reset_mock()

            mock_pop.side_effect = Exception
            self.actions.remove_location_for_store('foo')
            mock_log.warning.assert_called_once_with(
                _('Unexpected exception when deleting from store foo.'))
            mock_log.warning.reset_mock()
Exemplo n.º 2
0
    def create(self, size):
        """
        Create this image in the Sheepdog cluster with size 'size'.

        Sheepdog Usage: collie vdi create -a address -p port image size
        """
        if not isinstance(size, (six.integer_types, float)):
            raise exceptions.Forbidden("Size is not a number")
        self._run_command("create", None, str(size))
Exemplo n.º 3
0
    def delete_image_file(self, full_data_path):
        """
        Deletes image file or returns Exception
        """

        try:
            LOG.debug("opening file %s" % full_data_path)
            file_object = self.irods_conn_object.data_objects.get(
                full_data_path)
        except:
            LOG.error("file not found")
            raise exceptions.NotFound(msg)

        try:
            file_object.unlink()
            self.irods_conn_object.cleanup()
        except:
            LOG.error("cannot delete file")
            raise exceptions.Forbidden(store_name="irods", reason=reason)
        LOG.debug("delete success")
Exemplo n.º 4
0
    def delete(self, location, context=None):
        """
        Takes a `glance_store.location.Location` object that indicates
        where to find the image file to delete

        :location `glance_store.location.Location` object, supplied
                  from glance_store.location.get_location_from_uri()

        :raises NotFound if image does not exist
        :raises Forbidden if cannot delete because of permissions
        """
        loc = location.store_location
        fn = loc.path
        if os.path.exists(fn):
            try:
                LOG.debug(_("Deleting image at %(fn)s"), {'fn': fn})
                os.unlink(fn)
            except OSError:
                raise exceptions.Forbidden(_("You cannot delete file %s") % fn)
        else:
            raise exceptions.NotFound(image=fn)