]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Don't fail to delete if VolumeAttachment not found
authorZane Bitter <zbitter@redhat.com>
Thu, 20 Sep 2012 09:14:53 +0000 (11:14 +0200)
committerZane Bitter <zbitter@redhat.com>
Thu, 20 Sep 2012 14:10:46 +0000 (16:10 +0200)
Change-Id: If12b7ebbee2d71e39e49152d971c11f55badca18
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/volume.py

index bd78bf2cb0db1d4eba551805c5e2fd579c1ee930..6a8e399f2c8db8597f754bec05c6af0f2520b498 100644 (file)
@@ -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)
-
-        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()
+        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()
+        except NotFound as e:
+            logger.warning('Deleting VolumeAttachment %s %s - not found' %
+                    (server_id, volume_id))
+            return