Merge "Apply object_store delete changes"

This commit is contained in:
Jenkins
2015-04-20 17:49:17 +00:00
committed by Gerrit Code Review
2 changed files with 40 additions and 51 deletions

View File

@@ -101,18 +101,22 @@ class Proxy(proxy.BaseProxy):
container = _container.Container.from_id(container)
return container.create(self.session)
def delete_container(self, container):
"""Delete a container.
def delete_container(self, value, ignore_missing=True):
"""Delete a container
:param container: The container to delete. You can pass a container
object or the name of a container to delete.
:type container:
:class:`~openstack.object_store.v1.container.Container`
:param value: The value can be either the name of a container or a
:class:`~openstack.object_store.v1.container.Container`
instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the container does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent server.
:rtype: ``None``
:returns: ``None``
"""
container = _container.Container.from_id(container)
container.delete(self.session)
# TODO(brian): s/_container/container once other changes propogate
self._delete(_container.Container, value, ignore_missing)
def objects(self, container, limit=None, marker=None, **kwargs):
"""Return a generator that yields the Container's objects.
@@ -179,15 +183,22 @@ class Proxy(proxy.BaseProxy):
"""Copy an object."""
raise NotImplementedError
def delete_object(self, obj):
"""Delete an object.
def delete_object(self, value, ignore_missing=True):
"""Delete an object
:param obj: The object to delete.
:type obj: :class:`~openstack.object_store.v1.obj.Object`
:param value: The value can be either the name of an object or a
:class:`~openstack.object_store.v1.container.Container`
instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the object does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent server.
:rtype: ``None``
:returns: ``None``
"""
obj.delete(self.session)
# TODO(brian): s/_obj/obj once other changes propogate
self._delete(_obj.Object, value, ignore_missing)
def get_object_metadata(self, obj):
"""Get metatdata for an object.

View File

@@ -32,6 +32,20 @@ class TestObjectStoreProxy(test_proxy_base.TestProxyBase):
super(TestObjectStoreProxy, self).setUp()
self.proxy = _proxy.Proxy(self.session)
def test_container_delete(self):
self.verify_delete2(container.Container, self.proxy.delete_container,
False)
def test_container_delete_ignore(self):
self.verify_delete2(container.Container, self.proxy.delete_container,
True)
def test_object_delete(self):
self.verify_delete2(obj.Object, self.proxy.delete_object, False)
def test_object_delete_ignore(self):
self.verify_delete2(obj.Object, self.proxy.delete_object, True)
class Test_account_metadata(TestObjectStoreProxy):
@@ -209,31 +223,6 @@ class Test_create_container(TestObjectStoreProxy):
created_container.create.assert_called_once_with(self.session)
class Test_delete_container(TestObjectStoreProxy):
@mock.patch("openstack.resource.Resource.from_id")
def test_container_object(self, mock_fi):
container = mock.MagicMock()
mock_fi.return_value = container
result = self.proxy.delete_container(container)
self.assertIsNone(result)
container.delete.assert_called_once_with(self.session)
@mock.patch("openstack.resource.Resource.from_id")
def test_container_name(self, mock_fi):
name = six.text_type("my_container")
created_container = mock.MagicMock()
created_container.name = name
mock_fi.return_value = created_container
result = self.proxy.delete_container(name)
self.assertIsNone(result)
created_container.delete.assert_called_once_with(self.session)
class Test_objects(TestObjectStoreProxy, base.TestTransportBase):
TEST_URL = fakes.FakeAuthenticator.ENDPOINT
@@ -440,17 +429,6 @@ class Test_object_metadata(TestObjectStoreProxy):
ob.create.assert_called_once_with(self.session)
class Test_delete_object(TestObjectStoreProxy):
def test_delete_object(self):
ob = mock.MagicMock()
result = self.proxy.delete_object(ob)
self.assertIsNone(result)
ob.delete.assert_called_once_with(self.session)
class Test_copy_object(TestObjectStoreProxy):
def test_copy_object(self):