summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-09-20 05:40:18 -0400
committerScott Moser <smoser@ubuntu.com>2011-09-20 05:40:18 -0400
commit382f1dc728c2503e28237e9b2b455d46570943e6 (patch)
treecd5baf965be93578406e69d15ab6b0c034f294a5 /nova
parent2eb2120f98cfe70ce67325ffe26cfb5cc86c6356 (diff)
Address Soren's comments:
* clean up temp files if an ImageUnacceptable is going to be raised Note, a qemu-img execution error will not clean up the image, but I think thats reasonable. We leave the image on disk so the user can easily investigate. * Change final 2 arguments to fetch_to_raw to not start with an _ * use 'env' utility to change environment variables LC_ALL and LANG so that qemu-img output parsing is not locale dependent. Note, I considered the following, but found using 'env' more readable out, err = utils.execute('sh', '-c', 'export LC_ALL=C LANG=C && exec "$@"', 'qemu-img', 'info', path)
Diffstat (limited to 'nova')
-rw-r--r--nova/virt/images.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/nova/virt/images.py b/nova/virt/images.py
index ea04377c5..968fe1692 100644
--- a/nova/virt/images.py
+++ b/nova/virt/images.py
@@ -47,13 +47,14 @@ def fetch(context, image_href, path, _user_id, _project_id):
return metadata
-def fetch_to_raw(context, image_href, path, _user_id, _project_id):
+def fetch_to_raw(context, image_href, path, user_id, project_id):
path_tmp = "%s.part" % path
- metadata = fetch(context, image_href, path_tmp, _user_id, _project_id)
+ metadata = fetch(context, image_href, path_tmp, user_id, project_id)
def _qemu_img_info(path):
- out, err = utils.execute('qemu-img', 'info', path)
+ out, err = utils.execute('env', 'LC_ALL=C', 'LANG=C',
+ 'qemu-img', 'info', path)
# output of qemu-img is 'field: value'
# the fields of interest are 'file format' and 'backing file'
@@ -70,6 +71,7 @@ def fetch_to_raw(context, image_href, path, _user_id, _project_id):
fmt = data.get("file format", None)
if fmt == None:
+ os.unlink(path_tmp)
raise exception.ImageUnacceptable(
reason=_("'qemu-img info' parsing failed."), image_id=image_href)
@@ -77,6 +79,7 @@ def fetch_to_raw(context, image_href, path, _user_id, _project_id):
staged = "%s.converted" % path
if "backing file" in data:
backing_file = data['backing file']
+ os.unlink(path_tmp)
raise exception.ImageUnacceptable(image_id=image_href,
reason=_("fmt=%(fmt)s backed by: %(backing_file)s") % locals())
@@ -87,6 +90,7 @@ def fetch_to_raw(context, image_href, path, _user_id, _project_id):
data = _qemu_img_info(staged)
if data.get('file format', None) != "raw":
+ os.unlink(staged)
raise exception.ImageUnacceptable(image_id=image_href,
reason=_("Converted to raw, but format is now %s") %
data.get('file format', None))