From 46f7adadaf1d75f36a4544cb9c011056fd6d0e3a Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Tue, 14 Feb 2012 16:47:00 +0000 Subject: improve stale libvirt images handling fix. Bug 801412 If the unlink fails (because the path wasn't even created for example), then that will shroud the original failure. Instead log failure to remove the stale image, and raise the original exception. Change-Id: I36c6968823bcf81d704319739b3a992dae75266a --- nova/virt/images.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'nova') diff --git a/nova/virt/images.py b/nova/virt/images.py index 9a5a9e1b2..463c5417e 100644 --- a/nova/virt/images.py +++ b/nova/virt/images.py @@ -21,6 +21,7 @@ Handling of VM disk images. """ +import errno import os from nova import exception @@ -45,8 +46,13 @@ def fetch(context, image_href, path, _user_id, _project_id): with open(path, "wb") as image_file: metadata = image_service.get(context, image_id, image_file) except Exception: - os.unlink(path) - raise + with utils.save_and_reraise_exception(): + try: + os.unlink(path) + except OSError, e: + if e.errno != errno.ENOENT: + LOG.warn("unable to remove stale image '%s': %s" % + (path, e.strerror)) return metadata -- cgit