cinder: accommodate v1 cinder client in detach call

Call Cinder client's detach() with attachment_uuid only if the client
is v2.

Cinder client v2 supports passing volume_id and optionally
attachment_id to its volume manager's detach() method, but v1 does
not, only accepting volume_id.  Change I3cdc4992 indiscriminately
passes both volume_id and attachment_id to the Cinder client
regardless of its version, prompting with v1:

    TypeError: detach() takes exactly 2 arguments (3 given)

Change-Id: I2e8b5947521d659e930141b0b8e6a6353e9163bd
Closes-Bug: 1561056
This commit is contained in:
Corey Wright 2016-03-23 10:07:59 -05:00
parent 1feab84233
commit a45f5dd702
2 changed files with 20 additions and 2 deletions

View File

@ -42,7 +42,8 @@ class FakeCinderClient(object):
def __getattr__(self, item):
return None
def __init__(self):
def __init__(self, version='2'):
self.version = version
self.volumes = self.Volumes()
self.volume_snapshots = self.volumes
@ -290,6 +291,18 @@ class CinderApiTestCase(test.NoDBTestCase):
self.api.detach(self.ctx, 'id1', instance_uuid='fake_uuid')
def test_detach_v1(self):
self.cinderclient = FakeCinderClient('1')
cinder.cinderclient(self.ctx).AndReturn(self.cinderclient)
self.mox.StubOutWithMock(self.cinderclient.volumes,
'detach',
use_mock_anything=True)
self.cinderclient.volumes.detach('id1')
self.mox.ReplayAll()
self.api.detach(self.ctx, 'id1', instance_uuid='fake_uuid')
@mock.patch('nova.volume.cinder.cinderclient')
def test_initialize_connection(self, mock_cinderclient):
connection_info = {'foo': 'bar'}

View File

@ -378,6 +378,11 @@ class API(object):
@translate_volume_exception
def detach(self, context, volume_id, instance_uuid=None,
attachment_id=None):
client = cinderclient(context)
if client.version == '1':
client.volumes.detach(volume_id)
return
if attachment_id is None:
volume = self.get(context, volume_id)
if volume['multiattach']:
@ -403,7 +408,7 @@ class API(object):
"cannot perform the detach."),
{'volume_id': volume_id})
cinderclient(context).volumes.detach(volume_id, attachment_id)
client.volumes.detach(volume_id, attachment_id)
@translate_volume_exception
def initialize_connection(self, context, volume_id, connector):