Skip to content

Commit 651f0c3

Browse files
committed
Handle not having cinderclient.v1 available
The Cinder v1 API was deprecated several years ago and may be removed from python-cinderclient in the near future. To handle the case where v1 is no longer present, this updates cinderclient initialization to work without it and give an appropriate error if v1 is requested with a version where it is no longer available. Change-Id: I277d7b48b8ad4cce383ec3722f8117938378f615 Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
1 parent e3dc30f commit 651f0c3

4 files changed

Lines changed: 19 additions & 21 deletions

File tree

openstackclient/tests/unit/volume/test_find_resource.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
import mock
1717

18-
from cinderclient.v1 import volume_snapshots
19-
from cinderclient.v1 import volumes
18+
from cinderclient.v3 import volume_snapshots
19+
from cinderclient.v3 import volumes
2020
from osc_lib import exceptions
2121
from osc_lib import utils
2222

openstackclient/tests/unit/volume/v2/test_volume.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def test_volume_create_min_options(self):
131131
imageRef=None,
132132
source_volid=None,
133133
consistencygroup_id=None,
134-
multiattach=False,
135134
scheduler_hints=None,
136135
)
137136

@@ -149,7 +148,6 @@ def test_volume_create_options(self):
149148
'--availability-zone', self.new_volume.availability_zone,
150149
'--consistency-group', consistency_group.id,
151150
'--hint', 'k=v',
152-
'--multi-attach',
153151
self.new_volume.name,
154152
]
155153
verifylist = [
@@ -159,7 +157,6 @@ def test_volume_create_options(self):
159157
('availability_zone', self.new_volume.availability_zone),
160158
('consistency_group', consistency_group.id),
161159
('hint', {'k': 'v'}),
162-
('multi_attach', True),
163160
('name', self.new_volume.name),
164161
]
165162
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -180,7 +177,6 @@ def test_volume_create_options(self):
180177
imageRef=None,
181178
source_volid=None,
182179
consistencygroup_id=consistency_group.id,
183-
multiattach=True,
184180
scheduler_hints={'k': 'v'},
185181
)
186182

@@ -251,7 +247,6 @@ def test_volume_create_properties(self):
251247
imageRef=None,
252248
source_volid=None,
253249
consistencygroup_id=None,
254-
multiattach=False,
255250
scheduler_hints=None,
256251
)
257252

@@ -290,7 +285,6 @@ def test_volume_create_image_id(self):
290285
imageRef=image.id,
291286
source_volid=None,
292287
consistencygroup_id=None,
293-
multiattach=False,
294288
scheduler_hints=None,
295289
)
296290

@@ -329,7 +323,6 @@ def test_volume_create_image_name(self):
329323
imageRef=image.id,
330324
source_volid=None,
331325
consistencygroup_id=None,
332-
multiattach=False,
333326
scheduler_hints=None,
334327
)
335328

@@ -367,7 +360,6 @@ def test_volume_create_with_snapshot(self):
367360
imageRef=None,
368361
source_volid=None,
369362
consistencygroup_id=None,
370-
multiattach=False,
371363
scheduler_hints=None,
372364
)
373365

@@ -406,7 +398,6 @@ def test_volume_create_with_bootable_and_readonly(self):
406398
imageRef=None,
407399
source_volid=None,
408400
consistencygroup_id=None,
409-
multiattach=False,
410401
scheduler_hints=None,
411402
)
412403

@@ -449,7 +440,6 @@ def test_volume_create_with_nonbootable_and_readwrite(self):
449440
imageRef=None,
450441
source_volid=None,
451442
consistencygroup_id=None,
452-
multiattach=False,
453443
scheduler_hints=None,
454444
)
455445

@@ -501,7 +491,6 @@ def test_volume_create_with_bootable_and_readonly_fail(
501491
imageRef=None,
502492
source_volid=None,
503493
consistencygroup_id=None,
504-
multiattach=False,
505494
scheduler_hints=None,
506495
)
507496

openstackclient/volume/client.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ def make_client(instance):
3737

3838
# Defer client imports until we actually need them
3939
from cinderclient import extension
40-
from cinderclient.v1.contrib import list_extensions
41-
from cinderclient.v1 import volume_snapshots
42-
from cinderclient.v1 import volumes
43-
44-
# Monkey patch for v1 cinderclient
45-
volumes.Volume.NAME_ATTR = 'display_name'
46-
volume_snapshots.Snapshot.NAME_ATTR = 'display_name'
40+
from cinderclient.v3.contrib import list_extensions
41+
from cinderclient.v3 import volume_snapshots
42+
from cinderclient.v3 import volumes
43+
44+
# Try a small import to check if cinderclient v1 is supported
45+
try:
46+
from cinderclient.v1 import services # noqa
47+
except Exception:
48+
del API_VERSIONS['1']
49+
50+
if instance._api_version[API_NAME] == '1':
51+
# Monkey patch for v1 cinderclient
52+
volumes.Volume.NAME_ATTR = 'display_name'
53+
volume_snapshots.Snapshot.NAME_ATTR = 'display_name'
4754

4855
volume_client = utils.get_client_class(
4956
API_NAME,

openstackclient/volume/v2/volume.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ def take_action(self, parsed_args):
212212
raise exceptions.CommandError(
213213
_("ERROR: --user is deprecated, please use"
214214
" --os-username instead."))
215+
if parsed_args.multi_attach:
216+
LOG.warning(_("'--multi-attach' option is no longer supported by "
217+
"the block storage service."))
215218

216219
volume = volume_client.volumes.create(
217220
size=size,
@@ -224,7 +227,6 @@ def take_action(self, parsed_args):
224227
imageRef=image,
225228
source_volid=source_volume,
226229
consistencygroup_id=consistency_group,
227-
multiattach=parsed_args.multi_attach,
228230
scheduler_hints=parsed_args.hint,
229231
)
230232

0 commit comments

Comments
 (0)