Skip to content

Commit a7e2f31

Browse files
committed
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>
1 parent de4e119 commit a7e2f31

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

openstackclient/tests/unit/volume/test_find_resource.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@
2121
from osc_lib import utils
2222

2323
from openstackclient.tests.unit import utils as test_utils
24-
from openstackclient.volume import client # noqa
25-
26-
27-
# Monkey patch for v1 cinderclient
28-
# NOTE(dtroyer): Do here because openstackclient.volume.client
29-
# doesn't do it until the client object is created now.
30-
volumes.Volume.NAME_ATTR = 'display_name'
31-
volume_snapshots.Snapshot.NAME_ATTR = 'display_name'
32-
3324

3425
ID = '1after909'
3526
NAME = 'PhilSpector'
@@ -42,14 +33,14 @@ def setUp(self):
4233
api.client = mock.Mock()
4334
api.client.get = mock.Mock()
4435
resp = mock.Mock()
45-
body = {"volumes": [{"id": ID, 'display_name': NAME}]}
36+
body = {"volumes": [{"id": ID, 'name': NAME}]}
4637
api.client.get.side_effect = [Exception("Not found"), (resp, body)]
4738
self.manager = volumes.VolumeManager(api)
4839

4940
def test_find(self):
5041
result = utils.find_resource(self.manager, NAME)
5142
self.assertEqual(ID, result.id)
52-
self.assertEqual(NAME, result.display_name)
43+
self.assertEqual(NAME, result.name)
5344

5445
def test_not_find(self):
5546
self.assertRaises(
@@ -67,14 +58,14 @@ def setUp(self):
6758
api.client = mock.Mock()
6859
api.client.get = mock.Mock()
6960
resp = mock.Mock()
70-
body = {"snapshots": [{"id": ID, 'display_name': NAME}]}
61+
body = {"snapshots": [{"id": ID, 'name': NAME}]}
7162
api.client.get.side_effect = [Exception("Not found"), (resp, body)]
7263
self.manager = volume_snapshots.SnapshotManager(api)
7364

7465
def test_find(self):
7566
result = utils.find_resource(self.manager, NAME)
7667
self.assertEqual(ID, result.id)
77-
self.assertEqual(NAME, result.display_name)
68+
self.assertEqual(NAME, result.name)
7869

7970
def test_not_find(self):
8071
self.assertRaises(

openstackclient/volume/client.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@
2020

2121
from openstackclient.i18n import _
2222

23-
2423
LOG = logging.getLogger(__name__)
2524

2625
DEFAULT_API_VERSION = '3'
2726
API_VERSION_OPTION = 'os_volume_api_version'
28-
API_NAME = "volume"
27+
API_NAME = 'volume'
2928
API_VERSIONS = {
30-
"1": "cinderclient.v1.client.Client",
31-
"2": "cinderclient.v2.client.Client",
32-
"3": "cinderclient.v3.client.Client",
29+
'2': 'cinderclient.v2.client.Client',
30+
'3': 'cinderclient.v3.client.Client',
3331
}
3432

3533
# Save the microversion if in use
@@ -45,11 +43,6 @@ def make_client(instance):
4543
from cinderclient.v3 import volume_snapshots
4644
from cinderclient.v3 import volumes
4745

48-
# Check whether the available cinderclient supports v1 or v2
49-
try:
50-
from cinderclient.v1 import services # noqa
51-
except Exception:
52-
del API_VERSIONS['1']
5346
try:
5447
from cinderclient.v2 import services # noqa
5548
except Exception:
@@ -127,21 +120,18 @@ def check_api_version(check_version):
127120

128121
global _volume_api_version
129122

130-
# Copy some logic from novaclient 3.3.0 for basic version detection
131-
# NOTE(dtroyer): This is only enough to resume operations using API
132-
# version 3.0 or any valid version supplied by the user.
133123
_volume_api_version = api_versions.get_api_version(check_version)
134124

135125
# Bypass X.latest format microversion
136126
if not _volume_api_version.is_latest():
137-
if _volume_api_version > api_versions.APIVersion("3.0"):
127+
if _volume_api_version > api_versions.APIVersion('3.0'):
138128
if not _volume_api_version.matches(
139129
api_versions.MIN_VERSION,
140130
api_versions.MAX_VERSION,
141131
):
142-
msg = _("versions supported by client: %(min)s - %(max)s") % {
143-
"min": api_versions.MIN_VERSION,
144-
"max": api_versions.MAX_VERSION,
132+
msg = _('versions supported by client: %(min)s - %(max)s') % {
133+
'min': api_versions.MIN_VERSION,
134+
'max': api_versions.MAX_VERSION,
145135
}
146136
raise exceptions.CommandError(msg)
147137

0 commit comments

Comments
 (0)