From 17d8a483ea94df2052a2d2aac3bc98aaee4eb43b Mon Sep 17 00:00:00 2001 From: ghanshyam Date: Fri, 21 Jul 2017 03:10:48 +0000 Subject: [PATCH] Fix object storage capabilities client return value All service clients methods return their response wrapped in ResponseBody, ResponseBodyData or ResponseBodyList. But object storage service clients were left out of this because response from object storage APIs are not same way other service return. Some APIs return is as string etc. This commit makes capabilities_client to return ResponseBody object with consistency to other service clients. Also add unit tests for that. This is step to move these clients to lib. Partially implements blueprint consistent-service-method-names Change-Id: Ida85033c06a50011b2cd9a86941089fb1ea7bedd --- tempest/api/object_storage/base.py | 2 +- .../object_storage/test_account_services.py | 2 +- .../test_container_services_negative.py | 2 +- tempest/cmd/verify_tempest_config.py | 2 +- .../object_storage/capabilities_client.py | 2 +- .../tests/cmd/test_verify_tempest_config.py | 16 +++--- .../test_capabilities_client.py | 54 +++++++++++++++++++ 7 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 tempest/tests/services/object_storage/test_capabilities_client.py diff --git a/tempest/api/object_storage/base.py b/tempest/api/object_storage/base.py index 13614cba1..11273e459 100644 --- a/tempest/api/object_storage/base.py +++ b/tempest/api/object_storage/base.py @@ -98,7 +98,7 @@ class BaseObjectTest(tempest.test.BaseTestCase): cls.policies = None if CONF.object_storage_feature_enabled.discoverability: - _, body = cls.capabilities_client.list_capabilities() + body = cls.capabilities_client.list_capabilities() if 'swift' in body and 'policies' in body['swift']: cls.policies = body['swift']['policies'] diff --git a/tempest/api/object_storage/test_account_services.py b/tempest/api/object_storage/test_account_services.py index 9e620465f..2fb676fe3 100644 --- a/tempest/api/object_storage/test_account_services.py +++ b/tempest/api/object_storage/test_account_services.py @@ -135,7 +135,7 @@ class AccountTest(base.BaseObjectTest): not CONF.object_storage_feature_enabled.discoverability, 'Discoverability function is disabled') def test_list_extensions(self): - resp, _ = self.capabilities_client.list_capabilities() + resp = self.capabilities_client.list_capabilities() self.assertThat(resp, custom_matchers.AreAllWellFormatted()) diff --git a/tempest/api/object_storage/test_container_services_negative.py b/tempest/api/object_storage/test_container_services_negative.py index a8d70c561..387b7b61b 100644 --- a/tempest/api/object_storage/test_container_services_negative.py +++ b/tempest/api/object_storage/test_container_services_negative.py @@ -32,7 +32,7 @@ class ContainerNegativeTest(base.BaseObjectTest): if CONF.object_storage_feature_enabled.discoverability: # use /info to get default constraints - _, body = cls.capabilities_client.list_capabilities() + body = cls.capabilities_client.list_capabilities() cls.constraints = body['swift'] @decorators.attr(type=["negative"]) diff --git a/tempest/cmd/verify_tempest_config.py b/tempest/cmd/verify_tempest_config.py index 2f4d120fc..8e71ecca1 100644 --- a/tempest/cmd/verify_tempest_config.py +++ b/tempest/cmd/verify_tempest_config.py @@ -200,7 +200,7 @@ def verify_extensions(os, service, results): if service != 'swift': resp = extensions_client.list_extensions() else: - __, resp = extensions_client.list_capabilities() + resp = extensions_client.list_capabilities() # For Nova, Cinder and Neutron we use the alias name rather than the # 'name' field because the alias is considered to be the canonical # name. diff --git a/tempest/services/object_storage/capabilities_client.py b/tempest/services/object_storage/capabilities_client.py index 0fe437fa2..d31bbc299 100644 --- a/tempest/services/object_storage/capabilities_client.py +++ b/tempest/services/object_storage/capabilities_client.py @@ -28,4 +28,4 @@ class CapabilitiesClient(rest_client.RestClient): self.reset_path() body = json.loads(body) self.expected_success(200, resp.status) - return resp, body + return rest_client.ResponseBody(resp, body) diff --git a/tempest/tests/cmd/test_verify_tempest_config.py b/tempest/tests/cmd/test_verify_tempest_config.py index b0e74fbed..1415111cc 100644 --- a/tempest/tests/cmd/test_verify_tempest_config.py +++ b/tempest/tests/cmd/test_verify_tempest_config.py @@ -392,10 +392,10 @@ class TestDiscovery(base.TestCase): def test_verify_extensions_swift(self): def fake_list_extensions(): - return (None, {'fake1': 'metadata', - 'fake2': 'metadata', - 'not_fake': 'metadata', - 'swift': 'metadata'}) + return {'fake1': 'metadata', + 'fake2': 'metadata', + 'not_fake': 'metadata', + 'swift': 'metadata'} fake_os = mock.MagicMock() fake_os.capabilities_client.list_capabilities = fake_list_extensions self.useFixture(fixtures.MockPatchObject( @@ -414,10 +414,10 @@ class TestDiscovery(base.TestCase): def test_verify_extensions_swift_all(self): def fake_list_extensions(): - return (None, {'fake1': 'metadata', - 'fake2': 'metadata', - 'not_fake': 'metadata', - 'swift': 'metadata'}) + return {'fake1': 'metadata', + 'fake2': 'metadata', + 'not_fake': 'metadata', + 'swift': 'metadata'} fake_os = mock.MagicMock() fake_os.capabilities_client.list_capabilities = fake_list_extensions self.useFixture(fixtures.MockPatchObject( diff --git a/tempest/tests/services/object_storage/test_capabilities_client.py b/tempest/tests/services/object_storage/test_capabilities_client.py new file mode 100644 index 000000000..5279bf474 --- /dev/null +++ b/tempest/tests/services/object_storage/test_capabilities_client.py @@ -0,0 +1,54 @@ +# Copyright 2016 IBM Corp. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +from tempest.services.object_storage import capabilities_client +from tempest.tests.lib import fake_auth_provider +from tempest.tests.lib.services import base + + +class TestCapabilitiesClient(base.BaseServiceTest): + + def setUp(self): + super(TestCapabilitiesClient, self).setUp() + self.fake_auth = fake_auth_provider.FakeAuthProvider() + self.url = self.fake_auth.base_url(None) + self.client = capabilities_client.CapabilitiesClient( + self.fake_auth, 'swift', 'region1') + + def _test_list_capabilities(self, bytes_body=False): + resp = { + "swift": { + "version": "1.11.0" + }, + "slo": { + "max_manifest_segments": 1000, + "max_manifest_size": 2097152, + "min_segment_size": 1 + }, + "staticweb": {}, + "tempurl": {} + } + self.check_service_client_function( + self.client.list_capabilities, + 'tempest.lib.common.rest_client.RestClient.get', + resp, + bytes_body) + + def test_list_capabilities_with_str_body(self): + self._test_list_capabilities() + + def test_list_capabilities_with_bytes_body(self): + self._test_list_capabilities(True)