From 2652832ef3594329fd0afb66ec1c5d8836987c18 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 20 Sep 2012 11:14:53 +0200 Subject: [PATCH] Don't fail to delete if VolumeAttachment not found Change-Id: If12b7ebbee2d71e39e49152d971c11f55badca18 Signed-off-by: Zane Bitter --- heat/engine/volume.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/heat/engine/volume.py b/heat/engine/volume.py index bd78bf2cb0..6a8e399f2c 100644 --- a/heat/engine/volume.py +++ b/heat/engine/volume.py @@ -18,6 +18,7 @@ from heat.openstack.common import log as logging from heat.common import exception from heat.engine.resources import Resource +from novaclient.exceptions import NotFound logger = logging.getLogger('heat.engine.volume') @@ -99,18 +100,24 @@ class VolumeAttachment(Resource): (server_id, volume_id)) volapi = self.nova().volumes - volapi.delete_server_volume(server_id, - volume_id) + try: + volapi.delete_server_volume(server_id, + volume_id) - vol = self.nova('volume').volumes.get(volume_id) - logger.info('un-attaching %s, status %s' % (volume_id, vol.status)) - while vol.status == 'in-use': - logger.info('trying to un-attach %s, but still %s' % - (volume_id, vol.status)) - eventlet.sleep(1) - try: - volapi.delete_server_volume(server_id, - volume_id) - except Exception: - pass - vol.get() + vol = self.nova('volume').volumes.get(volume_id) + + logger.info('un-attaching %s, status %s' % (volume_id, vol.status)) + while vol.status == 'in-use': + logger.info('trying to un-attach %s, but still %s' % + (volume_id, vol.status)) + eventlet.sleep(1) + try: + volapi.delete_server_volume(server_id, + volume_id) + except Exception: + pass + vol.get() + except NotFound as e: + logger.warning('Deleting VolumeAttachment %s %s - not found' % + (server_id, volume_id)) + return