diff --git a/releasenotes/notes/move-volume-v3-base_client-to-volume-1edbz0f207c3b283.yaml b/releasenotes/notes/move-volume-v3-base_client-to-volume-1edbz0f207c3b283.yaml new file mode 100644 index 0000000000..ec81dc5300 --- /dev/null +++ b/releasenotes/notes/move-volume-v3-base_client-to-volume-1edbz0f207c3b283.yaml @@ -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``) diff --git a/tempest/api/volume/api_microversion_fixture.py b/tempest/api/volume/api_microversion_fixture.py index 64bc537545..7bbe67497d 100644 --- a/tempest/api/volume/api_microversion_fixture.py +++ b/tempest/api/volume/api_microversion_fixture.py @@ -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): diff --git a/tempest/lib/services/volume/base_client.py b/tempest/lib/services/volume/base_client.py new file mode 100644 index 0000000000..c7fb21a975 --- /dev/null +++ b/tempest/lib/services/volume/base_client.py @@ -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 diff --git a/tempest/lib/services/volume/v2/volumes_client.py b/tempest/lib/services/volume/v2/volumes_client.py index 86e3836cd0..cfff16a083 100644 --- a/tempest/lib/services/volume/v2/volumes_client.py +++ b/tempest/lib/services/volume/v2/volumes_client.py @@ -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" diff --git a/tempest/lib/services/volume/v3/base_client.py b/tempest/lib/services/volume/v3/base_client.py index 958212a6ca..e78380bb78 100644 --- a/tempest/lib/services/volume/v3/base_client.py +++ b/tempest/lib/services/volume/v3/base_client.py @@ -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' diff --git a/tempest/lib/services/volume/v3/group_types_client.py b/tempest/lib/services/volume/v3/group_types_client.py index 390d44d43b..a6edbf5c09 100644 --- a/tempest/lib/services/volume/v3/group_types_client.py +++ b/tempest/lib/services/volume/v3/group_types_client.py @@ -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): diff --git a/tempest/lib/services/volume/v3/groups_client.py b/tempest/lib/services/volume/v3/groups_client.py index c06997a842..9b53bb7da3 100644 --- a/tempest/lib/services/volume/v3/groups_client.py +++ b/tempest/lib/services/volume/v3/groups_client.py @@ -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. diff --git a/tempest/lib/services/volume/v3/messages_client.py b/tempest/lib/services/volume/v3/messages_client.py index 8a01864fda..0127271379 100644 --- a/tempest/lib/services/volume/v3/messages_client.py +++ b/tempest/lib/services/volume/v3/messages_client.py @@ -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.""" diff --git a/tempest/lib/services/volume/v3/versions_client.py b/tempest/lib/services/volume/v3/versions_client.py index e2941c4b9b..5702f9521c 100644 --- a/tempest/lib/services/volume/v3/versions_client.py +++ b/tempest/lib/services/volume/v3/versions_client.py @@ -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 diff --git a/tempest/lib/services/volume/v3/volumes_client.py b/tempest/lib/services/volume/v3/volumes_client.py index aec0205aee..5f4b278e80 100644 --- a/tempest/lib/services/volume/v3/volumes_client.py +++ b/tempest/lib/services/volume/v3/volumes_client.py @@ -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"