From 79a1cbf2ddde03a07dd290913cc45934be691214 Mon Sep 17 00:00:00 2001 From: "jeremy.zhang" Date: Sun, 7 May 2017 16:09:17 +0800 Subject: [PATCH] Add test case for show volume summary Show volume summary is a new api implemented in volume v3. This patch is to add a simple test case for this new feature. Including: [1] Add v3 volumes_client as library [2] Add show volume summary api to v3 volumes_client [3] Add unit tests for show volume summary api [4] Add test case: test_show_volume_summary [5] Add release note Change-Id: I9904bc53896e7d58a22aef11f6a3128147c0a373 --- ...to-v3-volumes-client-96e7b01abdb5c9c3.yaml | 10 ++++ tempest/api/volume/base.py | 6 +++ tempest/api/volume/test_volumes_get.py | 14 ++++++ tempest/clients.py | 1 + tempest/lib/services/volume/v3/__init__.py | 3 +- .../lib/services/volume/v3/volumes_client.py | 42 ++++++++++++++++ .../services/volume/v3/test_volumes_client.py | 48 +++++++++++++++++++ 7 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add-show-volume-summary-api-to-v3-volumes-client-96e7b01abdb5c9c3.yaml create mode 100644 tempest/lib/services/volume/v3/volumes_client.py create mode 100644 tempest/tests/lib/services/volume/v3/test_volumes_client.py diff --git a/releasenotes/notes/add-show-volume-summary-api-to-v3-volumes-client-96e7b01abdb5c9c3.yaml b/releasenotes/notes/add-show-volume-summary-api-to-v3-volumes-client-96e7b01abdb5c9c3.yaml new file mode 100644 index 0000000000..361e387545 --- /dev/null +++ b/releasenotes/notes/add-show-volume-summary-api-to-v3-volumes-client-96e7b01abdb5c9c3.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + Define v3 volumes_client for the volume service as a library interface, + allowing other projects to use this module as a stable library without + maintenance changes. + Add show volume summary API to v3 volumes_client library, min_microversion + of this API is 3.12. + + * volumes_client(v3) diff --git a/tempest/api/volume/base.py b/tempest/api/volume/base.py index cc1e087633..3f33c7b697 100644 --- a/tempest/api/volume/base.py +++ b/tempest/api/volume/base.py @@ -80,6 +80,9 @@ class BaseVolumeTest(api_version_utils.BaseMicroversionTest, cls.messages_client = cls.os_primary.volume_v3_messages_client cls.versions_client = cls.os_primary.volume_v3_versions_client + if cls._api_version == 3: + cls.volumes_client = cls.os_primary.volumes_v3_client + def setUp(self): super(BaseVolumeTest, self).setUp() self.useFixture(api_microversion_fixture.APIMicroversionFixture( @@ -266,6 +269,9 @@ class BaseVolumeAdminTest(BaseVolumeTest): cls.os_admin.volume_scheduler_stats_v2_client cls.admin_messages_client = cls.os_admin.volume_v3_messages_client + if cls._api_version == 3: + cls.admin_volume_client = cls.os_admin.volumes_v3_client + @classmethod def resource_setup(cls): super(BaseVolumeAdminTest, cls).resource_setup() diff --git a/tempest/api/volume/test_volumes_get.py b/tempest/api/volume/test_volumes_get.py index 712254ecf6..ec9a0dd9fd 100644 --- a/tempest/api/volume/test_volumes_get.py +++ b/tempest/api/volume/test_volumes_get.py @@ -137,3 +137,17 @@ class VolumesGetTest(base.BaseVolumeTest): origin = self.create_volume() self._volume_create_get_update_delete(source_volid=origin['id'], size=CONF.volume.volume_size) + + +class VolumesSummaryTest(base.BaseVolumeTest): + + _api_version = 3 + min_microversion = '3.12' + max_microversion = 'latest' + + @decorators.idempotent_id('c4f2431e-4920-4736-9e00-4040386b6feb') + def test_show_volume_summary(self): + volume_summary = \ + self.volumes_client.show_volume_summary()['volume-summary'] + for key in ['total_size', 'total_count']: + self.assertIn(key, volume_summary) diff --git a/tempest/clients.py b/tempest/clients.py index 73a4b20282..4baa31d1e7 100644 --- a/tempest/clients.py +++ b/tempest/clients.py @@ -269,6 +269,7 @@ class Manager(clients.ServiceClients): self.volume_manage_v2_client = self.volume_v2.VolumeManageClient() self.volumes_client = self.volume_v1.VolumesClient() self.volumes_v2_client = self.volume_v2.VolumesClient() + self.volumes_v3_client = self.volume_v3.VolumesClient() self.volume_v3_messages_client = self.volume_v3.MessagesClient() self.volume_v3_versions_client = self.volume_v3.VersionsClient() self.volume_types_client = self.volume_v1.TypesClient() diff --git a/tempest/lib/services/volume/v3/__init__.py b/tempest/lib/services/volume/v3/__init__.py index 72ab785d43..07ae917625 100644 --- a/tempest/lib/services/volume/v3/__init__.py +++ b/tempest/lib/services/volume/v3/__init__.py @@ -15,5 +15,6 @@ from tempest.lib.services.volume.v3.base_client import BaseClient from tempest.lib.services.volume.v3.messages_client import MessagesClient from tempest.lib.services.volume.v3.versions_client import VersionsClient +from tempest.lib.services.volume.v3.volumes_client import VolumesClient -__all__ = ['MessagesClient', 'BaseClient', 'VersionsClient'] +__all__ = ['MessagesClient', 'BaseClient', 'VersionsClient', 'VolumesClient'] diff --git a/tempest/lib/services/volume/v3/volumes_client.py b/tempest/lib/services/volume/v3/volumes_client.py new file mode 100644 index 0000000000..aec0205aee --- /dev/null +++ b/tempest/lib/services/volume/v3/volumes_client.py @@ -0,0 +1,42 @@ +# Copyright 2017 FiberHome Telecommunication Technologies CO.,LTD +# 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 oslo_serialization import jsonutils as json +from six.moves.urllib import parse as urllib + +from tempest.lib.common import rest_client +from tempest.lib.services.volume.v2 import volumes_client +from tempest.lib.services.volume.v3 import base_client + + +class VolumesClient(base_client.BaseClient, + volumes_client.VolumesClient): + """Client class to send CRUD Volume V3 API requests""" + api_version = "v3" + + def show_volume_summary(self, **params): + """Get volumes summary. + + For a full list of available parameters, please refer to the official + API reference: + https://developer.openstack.org/api-ref/block-storage/v3/#get-volumes-summary + """ + url = 'volumes/summary' + if params: + url += '?%s' % urllib.urlencode(params) + resp, body = self.get(url) + body = json.loads(body) + self.expected_success(200, resp.status) + return rest_client.ResponseBody(resp, body) diff --git a/tempest/tests/lib/services/volume/v3/test_volumes_client.py b/tempest/tests/lib/services/volume/v3/test_volumes_client.py new file mode 100644 index 0000000000..a515fd34a3 --- /dev/null +++ b/tempest/tests/lib/services/volume/v3/test_volumes_client.py @@ -0,0 +1,48 @@ +# Copyright 2017 FiberHome Telecommunication Technologies CO.,LTD +# 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.lib.services.volume.v3 import volumes_client +from tempest.tests.lib import fake_auth_provider +from tempest.tests.lib.services import base + + +class TestVolumesClient(base.BaseServiceTest): + + FAKE_VOLUME_SUMMARY = { + "volume-summary": { + "total_size": 20, + "total_count": 5 + } + } + + def setUp(self): + super(TestVolumesClient, self).setUp() + fake_auth = fake_auth_provider.FakeAuthProvider() + self.client = volumes_client.VolumesClient(fake_auth, + 'volume', + 'regionOne') + + def _test_show_volume_summary(self, bytes_body=False): + self.check_service_client_function( + self.client.show_volume_summary, + 'tempest.lib.common.rest_client.RestClient.get', + self.FAKE_VOLUME_SUMMARY, + bytes_body) + + def test_show_volume_summary_with_str_body(self): + self._test_show_volume_summary() + + def test_show_volume_summary_with_bytes_body(self): + self._test_show_volume_summary(bytes_body=True)