From 848450abb6569187d811631cb7dd5ed1fba4f547 Mon Sep 17 00:00:00 2001 From: Everett Toews Date: Sun, 17 Jan 2016 16:10:01 -0600 Subject: [PATCH] download_object/get_object must have the same API Change-Id: Iff8d6e906c5d82259627e4bbc01295b0d011ca70 Closes-Bug: #1513679 --- openstack/object_store/v1/_proxy.py | 18 ++++++++++++------ .../tests/unit/object_store/v1/test_proxy.py | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/openstack/object_store/v1/_proxy.py b/openstack/object_store/v1/_proxy.py index b9e46543a..a576ec0ee 100644 --- a/openstack/object_store/v1/_proxy.py +++ b/openstack/object_store/v1/_proxy.py @@ -142,9 +142,9 @@ class Proxy(proxy.BaseProxy): def get_object(self, object, container=None): """Get the data associated with an object - :param object: The value can be the ID of an object or a + :param object: The value can be the name of an object or a :class:`~openstack.object_store.v1.obj.Object` instance. - :param container: The value can be the ID of a container or a + :param container: The value can be the name of a container or a :class:`~openstack.object_store.v1.container.Container` instance. @@ -159,15 +159,21 @@ class Proxy(proxy.BaseProxy): return self._get(_obj.Object, object, path_args={"container": container_name}) - def download_object(self, object, path): + def download_object(self, object, container=None, path=None): """Download the data contained inside an object to disk. - :param object: The object to save to disk. - :type object: :class:`~openstack.object_store.v1.obj.Object` + :param object: The value can be the name of an object or a + :class:`~openstack.object_store.v1.obj.Object` instance. + :param container: The value can be the name of a container or a + :class:`~openstack.object_store.v1.container.Container` + instance. :param path str: Location to write the object contents. + + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. """ with open(path, "w") as out: - out.write(self.get_object(object)) + out.write(self.get_object(object, container)) def upload_object(self, **attrs): """Upload a new object from attributes diff --git a/openstack/tests/unit/object_store/v1/test_proxy.py b/openstack/tests/unit/object_store/v1/test_proxy.py index 71e8ec474..5fa85c76b 100644 --- a/openstack/tests/unit/object_store/v1/test_proxy.py +++ b/openstack/tests/unit/object_store/v1/test_proxy.py @@ -264,7 +264,7 @@ class Test_download_object(TestObjectStoreProxy): file_path = "blarga/somefile" with mock.patch("openstack.object_store.v1._proxy.open", fake_open, create=True): - self.proxy.download_object(ob, file_path) + self.proxy.download_object(ob, container="tainer", path=file_path) fake_open.assert_called_once_with(file_path, "w") fake_handle = fake_open()