volume: Remove negotiation for v1 API
Change Ibe1cd6461d2cb78826467078aa17272f171746aa removed support for the v1 volume API. We should have removed this check at the same time. We also remove some god-awful monkey patching that references v1 cinderclient but in practice modified all clients. Change-Id: I3727fd9238df966b3bc59812c5efcf3398da5c72 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
@@ -21,15 +21,6 @@ from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
|
||||
from openstackclient.tests.unit import utils as test_utils
|
||||
from openstackclient.volume import client # noqa
|
||||
|
||||
|
||||
# Monkey patch for v1 cinderclient
|
||||
# NOTE(dtroyer): Do here because openstackclient.volume.client
|
||||
# doesn't do it until the client object is created now.
|
||||
volumes.Volume.NAME_ATTR = 'display_name'
|
||||
volume_snapshots.Snapshot.NAME_ATTR = 'display_name'
|
||||
|
||||
|
||||
ID = '1after909'
|
||||
NAME = 'PhilSpector'
|
||||
@@ -42,14 +33,14 @@ class TestFindResourceVolumes(test_utils.TestCase):
|
||||
api.client = mock.Mock()
|
||||
api.client.get = mock.Mock()
|
||||
resp = mock.Mock()
|
||||
body = {"volumes": [{"id": ID, 'display_name': NAME}]}
|
||||
body = {"volumes": [{"id": ID, 'name': NAME}]}
|
||||
api.client.get.side_effect = [Exception("Not found"), (resp, body)]
|
||||
self.manager = volumes.VolumeManager(api)
|
||||
|
||||
def test_find(self):
|
||||
result = utils.find_resource(self.manager, NAME)
|
||||
self.assertEqual(ID, result.id)
|
||||
self.assertEqual(NAME, result.display_name)
|
||||
self.assertEqual(NAME, result.name)
|
||||
|
||||
def test_not_find(self):
|
||||
self.assertRaises(
|
||||
@@ -67,14 +58,14 @@ class TestFindResourceVolumeSnapshots(test_utils.TestCase):
|
||||
api.client = mock.Mock()
|
||||
api.client.get = mock.Mock()
|
||||
resp = mock.Mock()
|
||||
body = {"snapshots": [{"id": ID, 'display_name': NAME}]}
|
||||
body = {"snapshots": [{"id": ID, 'name': NAME}]}
|
||||
api.client.get.side_effect = [Exception("Not found"), (resp, body)]
|
||||
self.manager = volume_snapshots.SnapshotManager(api)
|
||||
|
||||
def test_find(self):
|
||||
result = utils.find_resource(self.manager, NAME)
|
||||
self.assertEqual(ID, result.id)
|
||||
self.assertEqual(NAME, result.display_name)
|
||||
self.assertEqual(NAME, result.name)
|
||||
|
||||
def test_not_find(self):
|
||||
self.assertRaises(
|
||||
|
||||
@@ -20,16 +20,14 @@ from osc_lib import utils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_API_VERSION = '3'
|
||||
API_VERSION_OPTION = 'os_volume_api_version'
|
||||
API_NAME = "volume"
|
||||
API_NAME = 'volume'
|
||||
API_VERSIONS = {
|
||||
"1": "cinderclient.v1.client.Client",
|
||||
"2": "cinderclient.v2.client.Client",
|
||||
"3": "cinderclient.v3.client.Client",
|
||||
'2': 'cinderclient.v2.client.Client',
|
||||
'3': 'cinderclient.v3.client.Client',
|
||||
}
|
||||
|
||||
# Save the microversion if in use
|
||||
@@ -45,11 +43,6 @@ def make_client(instance):
|
||||
from cinderclient.v3 import volume_snapshots
|
||||
from cinderclient.v3 import volumes
|
||||
|
||||
# Check whether the available cinderclient supports v1 or v2
|
||||
try:
|
||||
from cinderclient.v1 import services # noqa
|
||||
except Exception:
|
||||
del API_VERSIONS['1']
|
||||
try:
|
||||
from cinderclient.v2 import services # noqa
|
||||
except Exception:
|
||||
@@ -127,21 +120,18 @@ def check_api_version(check_version):
|
||||
|
||||
global _volume_api_version
|
||||
|
||||
# Copy some logic from novaclient 3.3.0 for basic version detection
|
||||
# NOTE(dtroyer): This is only enough to resume operations using API
|
||||
# version 3.0 or any valid version supplied by the user.
|
||||
_volume_api_version = api_versions.get_api_version(check_version)
|
||||
|
||||
# Bypass X.latest format microversion
|
||||
if not _volume_api_version.is_latest():
|
||||
if _volume_api_version > api_versions.APIVersion("3.0"):
|
||||
if _volume_api_version > api_versions.APIVersion('3.0'):
|
||||
if not _volume_api_version.matches(
|
||||
api_versions.MIN_VERSION,
|
||||
api_versions.MAX_VERSION,
|
||||
):
|
||||
msg = _("versions supported by client: %(min)s - %(max)s") % {
|
||||
"min": api_versions.MIN_VERSION,
|
||||
"max": api_versions.MAX_VERSION,
|
||||
msg = _('versions supported by client: %(min)s - %(max)s') % {
|
||||
'min': api_versions.MIN_VERSION,
|
||||
'max': api_versions.MAX_VERSION,
|
||||
}
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user