From 3db5b1e7099e1c10d557577350dc28e323c70af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Thu, 2 Feb 2012 14:56:54 +0000 Subject: [PATCH] fix stale libvirt images on download failure. Bug 801412 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nova/virt/images.py b/nova/virt/images.py index b884e51243c3..25f968185c7e 100644 --- a/nova/virt/images.py +++ b/nova/virt/images.py @@ -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