From: Steve Baker Date: Tue, 2 Apr 2013 00:24:09 +0000 (+1300) Subject: Catch NotFound exceptions on Volume handle_delete X-Git-Tag: 2014.1~736 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3fb34493bf361a54cd9aaa97975544461b0a21c2;p=openstack-build%2Fheat-build.git Catch NotFound exceptions on Volume handle_delete Currently stack delete fails if the underlying volume is already deleted. Fixes: bug #1163067 Change-Id: I9d7c009f70a0bb7274f3e19cbe10e9061c5e2d60 --- diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index 2c20f6e5..f4daa3bc 100644 --- a/heat/engine/resources/volume.py +++ b/heat/engine/resources/volume.py @@ -17,6 +17,7 @@ import eventlet from heat.openstack.common import log as logging from heat.common import exception +from heat.engine import clients from heat.engine import resource logger = logging.getLogger(__name__) @@ -51,13 +52,16 @@ class Volume(resource.Resource): def handle_delete(self): if self.resource_id is not None: - vol = self.cinder().volumes.get(self.resource_id) + try: + vol = self.cinder().volumes.get(self.resource_id) - if vol.status == 'in-use': - logger.warn('cant delete volume when in-use') - raise exception.Error("Volume in use") + if vol.status == 'in-use': + logger.warn('cant delete volume when in-use') + raise exception.Error("Volume in use") - self.cinder().volumes.delete(self.resource_id) + self.cinder().volumes.delete(self.resource_id) + except clients.cinder_exceptions.NotFound: + pass class VolumeAttachment(resource.Resource): diff --git a/heat/tests/test_volume.py b/heat/tests/test_volume.py index c5f1ea7a..28c1fef3 100644 --- a/heat/tests/test_volume.py +++ b/heat/tests/test_volume.py @@ -103,6 +103,8 @@ class VolumeTest(unittest.TestCase): self.fc.volumes.get('vol-123').AndReturn(fv) self.fc.volumes.delete('vol-123').AndReturn(None) + self.fc.volumes.get('vol-123').AndRaise( + clients.cinder_exceptions.NotFound('Not found')) self.m.ReplayAll() t = self.load_template() @@ -114,8 +116,13 @@ class VolumeTest(unittest.TestCase): self.assertEqual(resource.handle_update({}), vol.Volume.UPDATE_REPLACE) fv.status = 'in-use' + resource.state = 'CREATE_COMPLETE' self.assertEqual(resource.delete(), 'Volume in use') fv.status = 'available' + resource.state = 'CREATE_COMPLETE' + self.assertEqual(resource.delete(), None) + fv.status = 'available' + resource.state = 'CREATE_COMPLETE' self.assertEqual(resource.delete(), None) self.m.VerifyAll()