Catch NotFound exceptions on Volume handle_delete
Currently stack delete fails if the underlying volume is already deleted. Fixes: bug #1163067 Change-Id: I9d7c009f70a0bb7274f3e19cbe10e9061c5e2d60
This commit is contained in:
parent
d388e48fa3
commit
3fb34493bf
@ -17,6 +17,7 @@ import eventlet
|
|||||||
from heat.openstack.common import log as logging
|
from heat.openstack.common import log as logging
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
|
from heat.engine import clients
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -51,13 +52,16 @@ class Volume(resource.Resource):
|
|||||||
|
|
||||||
def handle_delete(self):
|
def handle_delete(self):
|
||||||
if self.resource_id is not None:
|
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':
|
if vol.status == 'in-use':
|
||||||
logger.warn('cant delete volume when in-use')
|
logger.warn('cant delete volume when in-use')
|
||||||
raise exception.Error("Volume 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):
|
class VolumeAttachment(resource.Resource):
|
||||||
|
@ -103,6 +103,8 @@ class VolumeTest(unittest.TestCase):
|
|||||||
self.fc.volumes.get('vol-123').AndReturn(fv)
|
self.fc.volumes.get('vol-123').AndReturn(fv)
|
||||||
self.fc.volumes.delete('vol-123').AndReturn(None)
|
self.fc.volumes.delete('vol-123').AndReturn(None)
|
||||||
|
|
||||||
|
self.fc.volumes.get('vol-123').AndRaise(
|
||||||
|
clients.cinder_exceptions.NotFound('Not found'))
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
t = self.load_template()
|
t = self.load_template()
|
||||||
@ -114,8 +116,13 @@ class VolumeTest(unittest.TestCase):
|
|||||||
self.assertEqual(resource.handle_update({}), vol.Volume.UPDATE_REPLACE)
|
self.assertEqual(resource.handle_update({}), vol.Volume.UPDATE_REPLACE)
|
||||||
|
|
||||||
fv.status = 'in-use'
|
fv.status = 'in-use'
|
||||||
|
resource.state = 'CREATE_COMPLETE'
|
||||||
self.assertEqual(resource.delete(), 'Volume in use')
|
self.assertEqual(resource.delete(), 'Volume in use')
|
||||||
fv.status = 'available'
|
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.assertEqual(resource.delete(), None)
|
||||||
|
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
Loading…
Reference in New Issue
Block a user