From 3fb34493bf361a54cd9aaa97975544461b0a21c2 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Tue, 2 Apr 2013 13:24:09 +1300 Subject: [PATCH] Catch NotFound exceptions on Volume handle_delete Currently stack delete fails if the underlying volume is already deleted. Fixes: bug #1163067 Change-Id: I9d7c009f70a0bb7274f3e19cbe10e9061c5e2d60 --- heat/engine/resources/volume.py | 14 +++++++++----- heat/tests/test_volume.py | 7 +++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index 2c20f6e504..f4daa3bce1 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 c5f1ea7ae1..28c1fef3aa 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()