Merge "Fix race condition in deleting volumes"
This commit is contained in:
commit
75c62a9fa6
@ -24,6 +24,7 @@ from dogpile import cache
|
||||
import requestsexceptions
|
||||
|
||||
import cinderclient.client
|
||||
import cinderclient.exceptions as cinder_exceptions
|
||||
import glanceclient
|
||||
import glanceclient.exc
|
||||
import heatclient.client
|
||||
@ -2429,8 +2430,14 @@ class OpenStackCloud(object):
|
||||
return False
|
||||
|
||||
with _utils.shade_exceptions("Error in deleting volume"):
|
||||
self.manager.submitTask(
|
||||
_tasks.VolumeDelete(volume=volume['id']))
|
||||
try:
|
||||
self.manager.submitTask(
|
||||
_tasks.VolumeDelete(volume=volume['id']))
|
||||
except cinder_exceptions.NotFound:
|
||||
self.log.debug(
|
||||
"Volume {id} not found when deleting. Ignoring.".format(
|
||||
id=volume['id']))
|
||||
return False
|
||||
|
||||
self.list_volumes.invalidate(self)
|
||||
if wait:
|
||||
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
import cinderclient.exceptions as cinder_exc
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
@ -188,3 +189,20 @@ class TestVolume(base.TestCase):
|
||||
"Error in detaching volume %s" % errored_volume['id']
|
||||
):
|
||||
self.cloud.detach_volume(server, volume)
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'get_volume')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'cinder_client')
|
||||
def test_delete_volume_deletes(self, mock_cinder, mock_get):
|
||||
volume = dict(id='volume001', status='attached')
|
||||
mock_get.side_effect = iter([volume, None])
|
||||
|
||||
self.assertTrue(self.cloud.delete_volume(volume['id']))
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'get_volume')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'cinder_client')
|
||||
def test_delete_volume_gone_away(self, mock_cinder, mock_get):
|
||||
volume = dict(id='volume001', status='attached')
|
||||
mock_get.side_effect = iter([volume])
|
||||
mock_cinder.volumes.delete.side_effect = cinder_exc.NotFound('N/A')
|
||||
|
||||
self.assertFalse(self.cloud.delete_volume(volume['id']))
|
||||
|
Loading…
x
Reference in New Issue
Block a user