Merge "Generic driver: ignore VolumeNotFound in deleting"

This commit is contained in:
Jenkins 2016-04-01 11:00:54 +00:00 committed by Gerrit Code Review
commit 9e06481ed5
2 changed files with 28 additions and 1 deletions

View File

@ -499,7 +499,12 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
attached_volumes = [vol.id for vol in
self.compute_api.instance_volumes_list(
self.admin_context, instance_id)]
volume = self._get_volume(context, share['id'])
try:
volume = self._get_volume(context, share['id'])
except exception.VolumeNotFound:
LOG.warning(_LW("Volume not found for share %s. "
"Possibly already deleted."), share['id'])
volume = None
if volume and volume['id'] in attached_volumes:
self.compute_api.instance_volume_detach(
self.admin_context,

View File

@ -1053,6 +1053,28 @@ class GenericShareDriverTestCase(test.TestCase):
assert_called_once_with(
self._context, self.server['backend_details'])
def test_detach_volume_with_volume_not_found(self):
fake_vol = fake_volume.FakeVolume()
fake_server_details = mock.MagicMock()
self.mock_object(self._driver.compute_api, 'instance_volumes_list',
mock.Mock(return_value=[]))
self.mock_object(self._driver, '_get_volume',
mock.Mock(side_effect=exception.VolumeNotFound(
volume_id=fake_vol['id'])))
self._driver._detach_volume(self._context,
self.share,
fake_server_details)
(self._driver.compute_api.instance_volumes_list.
assert_called_once_with(self._driver.admin_context,
fake_server_details['instance_id']))
(self._driver._get_volume.
assert_called_once_with(self._driver.admin_context,
self.share['id']))
self.assertEqual(1, self.mock_warning_log.call_count)
def test_delete_share_without_share_server(self):
self.mock_object(self._driver, '_unmount_device')
self.mock_object(self._driver, '_detach_volume')