Move base_client from volume.v3 to volume

Now exists multiple inheritance when adding new interfaces in
volume v3 clients, e.g., if we want to add show_volume_summary
in volume v3 VolumesClient, we have to make volume.v3.VolumesClient
inherit from both volume.v3.base_client.BaseClient and volume.v2.
volumes_client.VolumesClient, and this situation will repeat
everytime we add new interfaces in volume v3 clients based on v2
clients.
This is to move volume.v3.base_client to volume, and if we want to
add new interfaces based on a v2 client, we can make that v2 client
inherit from volume.base_client.BaseClient to get microversion support,
and then to make the new v3 client inherit from the v2 client, thus
to avoid the multiple inheritance.

Change-Id: I645ae35daebd924c4c4523163e5419cc050bb0ed
This commit is contained in:
zhufl 2017-06-19 13:57:28 +08:00
parent 09f926310b
commit 0273652206
10 changed files with 77 additions and 37 deletions

View File

@ -0,0 +1,15 @@
features:
- |
Move base_client from tempest.lib.services.volume.v3 to
tempest.lib.services.volume, so if we want to add new
interfaces based on a v2 client, we can make that v2
client inherit from volume.base_client.BaseClient to
get microversion support, and then to make the new v3
client inherit from the v2 client, thus to avoid the
multiple inheritance.
deprecations:
- |
Deprecate class BaseClient from volume.v3.base_client
and move it to volume.base_client.
``tempest.lib.services.volume.v3.base_client.BaseClient``
(new ``tempest.lib.services.volume.base_client.BaseClient``)

View File

@ -13,7 +13,7 @@
import fixtures
from tempest.lib.services.volume.v3 import base_client
from tempest.lib.services.volume import base_client
class APIMicroversionFixture(fixtures.Fixture):

View File

@ -0,0 +1,45 @@
# Copyright 2016 Andrew Kerr
# 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.common import api_version_utils
from tempest.lib.common import rest_client
VOLUME_MICROVERSION = None
class BaseClient(rest_client.RestClient):
"""Base volume service clients class to support microversion."""
api_microversion_header_name = 'Openstack-Api-Version'
def get_headers(self, accept_type=None, send_type=None):
headers = super(BaseClient, self).get_headers(
accept_type=accept_type, send_type=send_type)
if VOLUME_MICROVERSION:
headers[self.api_microversion_header_name] = ('volume %s' %
VOLUME_MICROVERSION)
return headers
def request(self, method, url, extra_headers=False, headers=None,
body=None, chunked=False):
resp, resp_body = super(BaseClient, self).request(
method, url, extra_headers, headers, body, chunked)
if (VOLUME_MICROVERSION and
VOLUME_MICROVERSION != api_version_utils.LATEST_MICROVERSION):
api_version_utils.assert_version_header_matches_request(
self.api_microversion_header_name,
'volume %s' % VOLUME_MICROVERSION,
resp)
return resp, resp_body

View File

@ -21,10 +21,11 @@ from six.moves.urllib import parse as urllib
from tempest.lib.common import rest_client
from tempest.lib import exceptions as lib_exc
from tempest.lib.services.volume import base_client
from tempest.lib.services.volume.v2 import transfers_client
class VolumesClient(rest_client.RestClient):
class VolumesClient(base_client.BaseClient):
"""Client class to send CRUD Volume V2 API requests"""
api_version = "v2"

View File

@ -13,34 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.lib.common import api_version_utils
from tempest.lib.common import rest_client
from debtcollector import moves
VOLUME_MICROVERSION = None
from tempest.lib.services.volume import base_client
class BaseClient(rest_client.RestClient):
"""Base class to handle Cinder v3 client microversion support."""
api_version = 'v3'
api_microversion_header_name = 'Openstack-Api-Version'
def get_headers(self, accept_type=None, send_type=None):
headers = super(BaseClient, self).get_headers(
accept_type=accept_type, send_type=send_type)
if VOLUME_MICROVERSION:
headers[self.api_microversion_header_name] = ('volume %s' %
VOLUME_MICROVERSION)
return headers
def request(self, method, url, extra_headers=False, headers=None,
body=None, chunked=False):
resp, resp_body = super(BaseClient, self).request(
method, url, extra_headers, headers, body, chunked)
if (VOLUME_MICROVERSION and
VOLUME_MICROVERSION != api_version_utils.LATEST_MICROVERSION):
api_version_utils.assert_version_header_matches_request(
self.api_microversion_header_name,
'volume %s' % VOLUME_MICROVERSION,
resp)
return resp, resp_body
BaseClient = moves.moved_class(base_client.BaseClient, 'BaseClient', __name__,
version="Pike", removal_version='?')
BaseClient.api_version = 'v3'

View File

@ -16,11 +16,12 @@
from oslo_serialization import jsonutils as json
from tempest.lib.common import rest_client
from tempest.lib.services.volume.v3 import base_client
from tempest.lib.services.volume import base_client
class GroupTypesClient(base_client.BaseClient):
"""Client class to send CRUD Volume V3 Group Types API requests"""
api_version = 'v3'
@property
def resource_type(self):

View File

@ -18,11 +18,12 @@ from six.moves.urllib import parse as urllib
from tempest.lib.common import rest_client
from tempest.lib import exceptions as lib_exc
from tempest.lib.services.volume.v3 import base_client
from tempest.lib.services.volume import base_client
class GroupsClient(base_client.BaseClient):
"""Client class to send CRUD Volume Group API requests"""
api_version = 'v3'
def create_group(self, **kwargs):
"""Creates a group.

View File

@ -17,11 +17,12 @@ from oslo_serialization import jsonutils as json
from tempest.lib.common import rest_client
from tempest.lib import exceptions as lib_exc
from tempest.lib.services.volume.v3 import base_client
from tempest.lib.services.volume import base_client
class MessagesClient(base_client.BaseClient):
"""Client class to send user messages API requests."""
api_version = 'v3'
def show_message(self, message_id):
"""Show details for a single message."""

View File

@ -18,10 +18,11 @@ from oslo_serialization import jsonutils as json
from tempest.lib.api_schema.response.volume import versions as schema
from tempest.lib.common import rest_client
from tempest.lib.services.volume.v3 import base_client
from tempest.lib.services.volume import base_client
class VersionsClient(base_client.BaseClient):
api_version = 'v3'
def list_versions(self):
"""List API versions

View File

@ -18,11 +18,9 @@ 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):
class VolumesClient(volumes_client.VolumesClient):
"""Client class to send CRUD Volume V3 API requests"""
api_version = "v3"