diff --git a/nova/tests/unit/volume/test_cinder.py b/nova/tests/unit/volume/test_cinder.py index 218fa337e86b..2864ad7df6e7 100644 --- a/nova/tests/unit/volume/test_cinder.py +++ b/nova/tests/unit/volume/test_cinder.py @@ -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'} diff --git a/nova/volume/cinder.py b/nova/volume/cinder.py index 8d4011bdfe2d..d40803311f4d 100644 --- a/nova/volume/cinder.py +++ b/nova/volume/cinder.py @@ -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):