diff --git a/zun/tests/unit/volume/test_cinder_api.py b/zun/tests/unit/volume/test_cinder_api.py index 54ecd4c83..82543be66 100644 --- a/zun/tests/unit/volume/test_cinder_api.py +++ b/zun/tests/unit/volume/test_cinder_api.py @@ -118,32 +118,37 @@ class CinderApiTestCase(base.TestCase): @mock.patch('zun.common.clients.OpenStackClients.cinder') def test_detach(self, mock_cinderclient): - attachment = {'host_name': 'fake_host', + attachment = {'server_id': 'fake_server', 'attachment_id': 'fakeid'} mock_volumes = mock.MagicMock() mock_cinderclient.return_value = mock.MagicMock(volumes=mock_volumes) mock_cinderclient.return_value.volumes.get.return_value = \ FakeVolume('id1', attachments=[attachment]) + volume = mock.MagicMock() + volume.volume_id = 'id1' self.api = cinder_api.CinderAPI(self.context) - self.api.detach('id1') + self.api.detach(volume) mock_cinderclient.assert_called_with() mock_volumes.detach.assert_called_once_with('id1', None) @mock.patch('zun.common.clients.OpenStackClients.cinder') def test_detach_multiattach(self, mock_cinderclient): - attachment = {'host_name': CONF.host, + attachment = {'server_id': 'fake_server_id', 'attachment_id': 'fakeid'} mock_volumes = mock.MagicMock() mock_cinderclient.return_value = mock.MagicMock(volumes=mock_volumes) mock_cinderclient.return_value.volumes.get.return_value = \ FakeVolume('id1', attachments=[attachment], multiattach=True) + volume = mock.MagicMock() + volume.volume_id = 'id1' + volume.container_uuid = 'fake_server_id' self.api = cinder_api.CinderAPI(self.context) - self.api.detach('id1') + self.api.detach(volume) mock_cinderclient.assert_called_with() mock_volumes.detach.assert_called_once_with('id1', 'fakeid') diff --git a/zun/tests/unit/volume/test_cinder_workflow.py b/zun/tests/unit/volume/test_cinder_workflow.py index b320d0e75..793057f5b 100644 --- a/zun/tests/unit/volume/test_cinder_workflow.py +++ b/zun/tests/unit/volume/test_cinder_workflow.py @@ -236,8 +236,7 @@ class CinderWorkflowTestCase(base.TestCase): self.fake_conn_info['data'], None) mock_cinder_api.terminate_connection.assert_called_once_with( self.fake_volume_id, self.fake_conn_prprts) - mock_cinder_api.detach.assert_called_once_with( - self.fake_volume_id) + mock_cinder_api.detach.assert_called_once_with(volume) mock_cinder_api.roll_detaching.assert_not_called() @mock.patch('zun.volume.cinder_workflow.get_volume_connector') diff --git a/zun/volume/cinder_api.py b/zun/volume/cinder_api.py index d885b9d8e..8590dcb44 100644 --- a/zun/volume/cinder_api.py +++ b/zun/volume/cinder_api.py @@ -113,12 +113,13 @@ class CinderAPI(object): mountpoint=mountpoint, host_name=hostname) - def detach(self, volume_id): + def detach(self, volume_map): + volume_id = volume_map.volume_id attachment_id = None volume = self.get(volume_id) attachments = volume.attachments or {} for am in attachments: - if am['host_name'].lower() == CONF.host.lower(): + if am['server_id'] == volume_map.container_uuid: attachment_id = am['attachment_id'] break diff --git a/zun/volume/cinder_workflow.py b/zun/volume/cinder_workflow.py index 58f117b36..a19570a3d 100644 --- a/zun/volume/cinder_workflow.py +++ b/zun/volume/cinder_workflow.py @@ -167,7 +167,7 @@ class CinderWorkflow(object): self.cinder_api.terminate_connection( volume_id, get_volume_connector_properties()) - self.cinder_api.detach(volume_id) + self.cinder_api.detach(volume) def delete_volume(self, volume): volume_id = volume.volume_id