Skip to content

Commit

Permalink
fix stale libvirt images on download failure. Bug 801412
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Pádraig Brady committed Feb 2, 2012
1 parent 638ea66 commit 3db5b1e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nova/virt/images.py
Expand Up @@ -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


Expand Down

0 comments on commit 3db5b1e

Please sign in to comment.