From faece91756fd37c02e1d16e2a7f1176621d7e896 Mon Sep 17 00:00:00 2001 From: Steve Martinelli Date: Thu, 10 Sep 2015 16:10:55 -0500 Subject: [PATCH] cleanup account ids from container commands use a common function to determine account ID instead of different ways - depending on the response and command Change-Id: I95adc5dc7d5a82a2cffc570d1ded24d1fc754a11 --- openstackclient/api/object_store_v1.py | 12 ++++++------ openstackclient/tests/api/test_object_store_v1.py | 2 ++ .../tests/object/v1/test_container_all.py | 2 ++ openstackclient/tests/object/v1/test_object_all.py | 2 ++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/openstackclient/api/object_store_v1.py b/openstackclient/api/object_store_v1.py index afc5b4c163..fab470e5ab 100644 --- a/openstackclient/api/object_store_v1.py +++ b/openstackclient/api/object_store_v1.py @@ -44,9 +44,8 @@ class APIv1(api.BaseAPI): """ response = self.create(container, method='PUT') - url_parts = urlparse(self.endpoint) data = { - 'account': url_parts.path.split('/')[-1], + 'account': self._find_account_id(), 'container': container, 'x-trans-id': response.headers.get('x-trans-id', None), } @@ -154,12 +153,13 @@ class APIv1(api.BaseAPI): response = self._request('HEAD', container) data = { - 'account': response.headers.get('x-container-meta-owner', None), + 'account': self._find_account_id(), 'container': container, 'object_count': response.headers.get( 'x-container-object-count', None, ), + 'meta-owner': response.headers.get('x-container-meta-owner', None), 'bytes_used': response.headers.get('x-container-bytes-used', None), 'read_acl': response.headers.get('x-container-read', None), 'write_acl': response.headers.get('x-container-write', None), @@ -194,9 +194,8 @@ class APIv1(api.BaseAPI): method='PUT', data=f, ) - url_parts = urlparse(self.endpoint) data = { - 'account': url_parts.path.split('/')[-1], + 'account': self._find_account_id(), 'container': container, 'object': object, 'x-trans-id': response.headers.get('X-Trans-Id', None), @@ -352,10 +351,11 @@ class APIv1(api.BaseAPI): response = self._request('HEAD', "%s/%s" % (container, object)) data = { - 'account': response.headers.get('x-container-meta-owner', None), + 'account': self._find_account_id(), 'container': container, 'object': object, 'content-type': response.headers.get('content-type', None), + 'meta-owner': response.headers.get('x-container-meta-owner', None), } if 'content-length' in response.headers: data['content-length'] = response.headers.get( diff --git a/openstackclient/tests/api/test_object_store_v1.py b/openstackclient/tests/api/test_object_store_v1.py index b18a003db5..323bb8e0b5 100644 --- a/openstackclient/tests/api/test_object_store_v1.py +++ b/openstackclient/tests/api/test_object_store_v1.py @@ -157,6 +157,7 @@ class TestContainer(TestObjectAPIv1): 'container': 'qaz', 'object_count': '1', 'bytes_used': '577', + 'meta-owner': FAKE_ACCOUNT, 'read_acl': None, 'write_acl': None, 'sync_to': None, @@ -322,6 +323,7 @@ class TestObject(TestObjectAPIv1): 'content-type': 'text/alpha', 'content-length': '577', 'last-modified': '20130101', + 'meta-owner': FAKE_ACCOUNT, 'etag': 'qaz', 'wife': 'Wilma', 'x-tra-header': 'yabba-dabba-do', diff --git a/openstackclient/tests/object/v1/test_container_all.py b/openstackclient/tests/object/v1/test_container_all.py index 8b200e09e3..4477f2e03b 100644 --- a/openstackclient/tests/object/v1/test_container_all.py +++ b/openstackclient/tests/object/v1/test_container_all.py @@ -316,6 +316,7 @@ class TestContainerShow(TestContainerAll): 'account', 'bytes_used', 'container', + 'meta-owner', 'object_count', 'read_acl', 'sync_key', @@ -327,6 +328,7 @@ class TestContainerShow(TestContainerAll): object_fakes.ACCOUNT_ID, '123', 'ernie', + object_fakes.ACCOUNT_ID, '42', 'qaz', 'rfv', diff --git a/openstackclient/tests/object/v1/test_object_all.py b/openstackclient/tests/object/v1/test_object_all.py index 7a76ab76ad..41fe6324cd 100644 --- a/openstackclient/tests/object/v1/test_object_all.py +++ b/openstackclient/tests/object/v1/test_object_all.py @@ -160,6 +160,7 @@ class TestObjectShow(TestObjectAll): 'content-type', 'etag', 'last-modified', + 'meta-owner', 'object', 'x-object-manifest', ) @@ -171,6 +172,7 @@ class TestObjectShow(TestObjectAll): 'text/plain', '4c4e39a763d58392724bccf76a58783a', 'yesterday', + object_fakes.ACCOUNT_ID, object_fakes.object_name_1, 'manifest', )