]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
fix stale libvirt images on download failure. Bug 801412
authorPádraig Brady <pbrady@redhat.com>
Thu, 2 Feb 2012 14:56:54 +0000 (14:56 +0000)
committerPádraig Brady <pbrady@redhat.com>
Thu, 2 Feb 2012 15:12:58 +0000 (15:12 +0000)
If we've just truncated/created the file to receive
the download, but the download fails, then delete the file.
Otherwise subsequent downloads would not be attempted.

Change-Id: Ibe9ba199b2f424d570ce7aedfb768ce283816a3b

nova/virt/images.py

index b884e51243c31883ade4777df4d0a0474d6aefbc..25f968185c7ef51ea60dc9ec4320f8325ec40371 100644 (file)
@@ -41,8 +41,12 @@ def fetch(context, image_href, path, _user_id, _project_id):
     #             checked before we got here.
     (image_service, image_id) = nova.image.get_image_service(context,
                                                              image_href)
-    with open(path, "wb") as image_file:
-        metadata = image_service.get(context, image_id, image_file)
+    try:
+        with open(path, "wb") as image_file:
+            metadata = image_service.get(context, image_id, image_file)
+    except Exception:
+        os.unlink(path)
+        raise
     return metadata