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:
Stephen Finucane
2025-11-28 16:47:52 +00:00
parent de4e119272
commit a7e2f31ecc
2 changed files with 11 additions and 30 deletions

View File

@@ -21,15 +21,6 @@ from osc_lib import exceptions
from osc_lib import utils from osc_lib import utils
from openstackclient.tests.unit import utils as test_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' ID = '1after909'
NAME = 'PhilSpector' NAME = 'PhilSpector'
@@ -42,14 +33,14 @@ class TestFindResourceVolumes(test_utils.TestCase):
api.client = mock.Mock() api.client = mock.Mock()
api.client.get = mock.Mock() api.client.get = mock.Mock()
resp = 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)] api.client.get.side_effect = [Exception("Not found"), (resp, body)]
self.manager = volumes.VolumeManager(api) self.manager = volumes.VolumeManager(api)
def test_find(self): def test_find(self):
result = utils.find_resource(self.manager, NAME) result = utils.find_resource(self.manager, NAME)
self.assertEqual(ID, result.id) self.assertEqual(ID, result.id)
self.assertEqual(NAME, result.display_name) self.assertEqual(NAME, result.name)
def test_not_find(self): def test_not_find(self):
self.assertRaises( self.assertRaises(
@@ -67,14 +58,14 @@ class TestFindResourceVolumeSnapshots(test_utils.TestCase):
api.client = mock.Mock() api.client = mock.Mock()
api.client.get = mock.Mock() api.client.get = mock.Mock()
resp = 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)] api.client.get.side_effect = [Exception("Not found"), (resp, body)]
self.manager = volume_snapshots.SnapshotManager(api) self.manager = volume_snapshots.SnapshotManager(api)
def test_find(self): def test_find(self):
result = utils.find_resource(self.manager, NAME) result = utils.find_resource(self.manager, NAME)
self.assertEqual(ID, result.id) self.assertEqual(ID, result.id)
self.assertEqual(NAME, result.display_name) self.assertEqual(NAME, result.name)
def test_not_find(self): def test_not_find(self):
self.assertRaises( self.assertRaises(

View File

@@ -20,16 +20,14 @@ from osc_lib import utils
from openstackclient.i18n import _ from openstackclient.i18n import _
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
DEFAULT_API_VERSION = '3' DEFAULT_API_VERSION = '3'
API_VERSION_OPTION = 'os_volume_api_version' API_VERSION_OPTION = 'os_volume_api_version'
API_NAME = "volume" API_NAME = 'volume'
API_VERSIONS = { API_VERSIONS = {
"1": "cinderclient.v1.client.Client", '2': 'cinderclient.v2.client.Client',
"2": "cinderclient.v2.client.Client", '3': 'cinderclient.v3.client.Client',
"3": "cinderclient.v3.client.Client",
} }
# Save the microversion if in use # Save the microversion if in use
@@ -45,11 +43,6 @@ def make_client(instance):
from cinderclient.v3 import volume_snapshots from cinderclient.v3 import volume_snapshots
from cinderclient.v3 import volumes 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: try:
from cinderclient.v2 import services # noqa from cinderclient.v2 import services # noqa
except Exception: except Exception:
@@ -127,21 +120,18 @@ def check_api_version(check_version):
global _volume_api_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) _volume_api_version = api_versions.get_api_version(check_version)
# Bypass X.latest format microversion # Bypass X.latest format microversion
if not _volume_api_version.is_latest(): 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( if not _volume_api_version.matches(
api_versions.MIN_VERSION, api_versions.MIN_VERSION,
api_versions.MAX_VERSION, api_versions.MAX_VERSION,
): ):
msg = _("versions supported by client: %(min)s - %(max)s") % { msg = _('versions supported by client: %(min)s - %(max)s') % {
"min": api_versions.MIN_VERSION, 'min': api_versions.MIN_VERSION,
"max": api_versions.MAX_VERSION, 'max': api_versions.MAX_VERSION,
} }
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)