Merge "cinder: accommodate v1 cinder client in detach call"

This commit is contained in:
Jenkins 2016-07-08 15:29:55 +00:00 committed by Gerrit Code Review
commit 536ce4f021
2 changed files with 20 additions and 2 deletions

View File

@ -45,7 +45,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
@ -295,6 +296,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

@ -338,6 +338,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']:
@ -363,7 +368,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):