Merge "Use "server_id" to judge in cinder_api when detach"

This commit is contained in:
Zuul 2018-08-16 08:37:46 +00:00 committed by Gerrit Code Review
commit 285ce733ab
4 changed files with 14 additions and 9 deletions

View File

@ -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')

View File

@ -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')

View File

@ -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

View File

@ -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