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
This commit is contained in:
jeremy.zhang 2017-05-07 16:09:17 +08:00
parent a99cba9ea6
commit 79a1cbf2dd
7 changed files with 123 additions and 1 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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()

View File

@ -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']

View File

@ -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)

View File

@ -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)