tests: Add ability to configure fake server API version
This beats the horrible mess of mocks we have created for ourselves. Change-Id: I8af3ce0a0b10f52e2124ec86f306327ff3474982 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
3f624295ec
commit
88fffeabd7
@ -15,9 +15,11 @@
|
||||
|
||||
import copy
|
||||
import random
|
||||
import re
|
||||
from unittest import mock
|
||||
import uuid
|
||||
|
||||
from keystoneauth1 import discover
|
||||
from novaclient import api_versions
|
||||
from openstack.compute.v2 import _proxy
|
||||
from openstack.compute.v2 import aggregate as _aggregate
|
||||
@ -143,8 +145,6 @@ class FakeComputev2Client:
|
||||
|
||||
self.management_url = kwargs['endpoint']
|
||||
|
||||
self.api_version = api_versions.APIVersion('2.1')
|
||||
|
||||
|
||||
class FakeClientMixin:
|
||||
def setUp(self):
|
||||
@ -169,6 +169,26 @@ class FakeClientMixin:
|
||||
self.compute_sdk_client = (
|
||||
self.app.client_manager.sdk_connection.compute
|
||||
)
|
||||
self.set_compute_api_version() # default to the lowest
|
||||
|
||||
def set_compute_api_version(self, version: str = '2.1'):
|
||||
"""Set a fake server version.
|
||||
|
||||
:param version: The fake microversion to "support". This should be a
|
||||
string of format '2.xx'.
|
||||
:returns: None
|
||||
"""
|
||||
assert re.match(r'2.\d+', version)
|
||||
|
||||
self.compute_client.api_version = api_versions.APIVersion(version)
|
||||
|
||||
self.compute_sdk_client.default_microversion = version
|
||||
self.compute_sdk_client.get_endpoint_data.return_value = (
|
||||
discover.EndpointData(
|
||||
min_microversion='2.1', # nova has not bumped this yet
|
||||
max_microversion=version,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TestComputev2(
|
||||
|
@ -14,11 +14,13 @@
|
||||
|
||||
import copy
|
||||
import random
|
||||
import typing as ty
|
||||
from unittest import mock
|
||||
import uuid
|
||||
|
||||
# FIXME(stephenfin): We are using v3 resource versions despite being v2 fakes
|
||||
from cinderclient import api_versions
|
||||
from keystoneauth1 import discover
|
||||
from openstack.block_storage.v2 import _proxy as block_storage_v2_proxy
|
||||
from openstack.block_storage.v2 import backup as _backup
|
||||
from openstack.block_storage.v3 import capabilities as _capabilities
|
||||
@ -105,6 +107,26 @@ class FakeClientMixin:
|
||||
spec=block_storage_v2_proxy.Proxy,
|
||||
)
|
||||
self.volume_sdk_client = self.app.client_manager.sdk_connection.volume
|
||||
self.set_volume_api_version() # default to the lowest
|
||||
|
||||
def set_volume_api_version(self, version: ty.Optional[str] = None):
|
||||
"""Set a fake block storage API version.
|
||||
|
||||
:param version: The fake microversion to "support". This must be None
|
||||
since cinder v2 didn't support microversions.
|
||||
:returns: None
|
||||
"""
|
||||
assert version is None
|
||||
|
||||
self.volume_client.api_version = None
|
||||
|
||||
self.volume_sdk_client.default_microversion = None
|
||||
self.volume_sdk_client.get_endpoint_data.return_value = (
|
||||
discover.EndpointData(
|
||||
min_microversion=None,
|
||||
max_microversion=None,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TestVolume(
|
||||
|
@ -12,10 +12,12 @@
|
||||
|
||||
import copy
|
||||
import random
|
||||
import re
|
||||
from unittest import mock
|
||||
import uuid
|
||||
|
||||
from cinderclient import api_versions
|
||||
from keystoneauth1 import discover
|
||||
from openstack.block_storage.v3 import _proxy
|
||||
from openstack.block_storage.v3 import availability_zone as _availability_zone
|
||||
from openstack.block_storage.v3 import backup as _backup
|
||||
@ -97,6 +99,26 @@ class FakeClientMixin:
|
||||
spec=_proxy.Proxy,
|
||||
)
|
||||
self.volume_sdk_client = self.app.client_manager.sdk_connection.volume
|
||||
self.set_volume_api_version() # default to the lowest
|
||||
|
||||
def set_volume_api_version(self, version: str = '3.0'):
|
||||
"""Set a fake block storage API version.
|
||||
|
||||
:param version: The fake microversion to "support". This should be a
|
||||
string of format '3.xx'.
|
||||
:returns: None
|
||||
"""
|
||||
assert re.match(r'3.\d+', version)
|
||||
|
||||
self.volume_client.api_version = api_versions.APIVersion(version)
|
||||
|
||||
self.volume_sdk_client.default_microversion = version
|
||||
self.volume_sdk_client.get_endpoint_data.return_value = (
|
||||
discover.EndpointData(
|
||||
min_microversion='3.0', # cinder has not bumped this yet
|
||||
max_microversion=version,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TestVolume(
|
||||
@ -126,6 +148,7 @@ class TestVolume(
|
||||
|
||||
# TODO(stephenfin): Check if the responses are actually the same
|
||||
create_one_snapshot = volume_v2_fakes.create_one_snapshot
|
||||
create_one_service = volume_v2_fakes.create_one_service
|
||||
|
||||
|
||||
def create_one_availability_zone(attrs=None):
|
||||
|
@ -16,12 +16,11 @@ from cinderclient import api_versions
|
||||
from osc_lib import exceptions
|
||||
|
||||
from openstackclient.tests.unit import utils as tests_utils
|
||||
from openstackclient.tests.unit.volume.v2 import fakes as v2_volume_fakes
|
||||
from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes
|
||||
from openstackclient.volume.v3 import block_storage_manage
|
||||
|
||||
|
||||
class TestBlockStorageManage(v2_volume_fakes.TestVolume):
|
||||
class TestBlockStorageManage(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
from cinderclient import api_versions
|
||||
|
||||
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
|
||||
from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes
|
||||
from openstackclient.volume.v3 import service
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user