From 0624b7aab0c0fe4869111ad8e302151548d6ba20 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Wed, 16 May 2012 13:44:46 +0100 Subject: handle updated qemu-img info output Originally `qemu-img info` always output an (actual path: ...) even if it was duplicated with that already on the line. $ instances=/var/lib/nova/instances/ $ qemu-img info $instances/instance-00000017/disk | grep 'backing' backing file: $instances/_base/24083... (actual path: $the_same) Whereas after the change referenced at: https://lists.gnu.org/archive/html/qemu-devel/2012-05/msg01468.html It suppresses a duplicate (actual path:) $ instances=/var/lib/nova/instances/ $ qemu-img info $instances/instance-00000017/disk | grep 'backing' backing file: $instances/_base/24083... * nova/virt/libvirt/utils.py (get_disk_backing_file): Avoid an indexError exception when parsing the newer format. Fixes bug 1000261 Change-Id: Ie2889b6da8a5c93e0e874e7a330529f6e6e71b0b --- nova/virt/libvirt/utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'nova') diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 948b6dfb8..9f63c13c1 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -110,10 +110,18 @@ def get_disk_backing_file(path): :returns: a path to the image's backing store """ out, err = execute('qemu-img', 'info', path) - backing_file = [i.split('actual path:')[1].strip()[:-1] - for i in out.split('\n') if 0 <= i.find('backing file')] + backing_file = None + + for line in out.split('\n'): + if line.startswith('backing file: '): + if 'actual path: ' in line: + backing_file = line.split('actual path: ')[1][:-1] + else: + backing_file = line.split('backing file: ')[1] + break if backing_file: - backing_file = os.path.basename(backing_file[0]) + backing_file = os.path.basename(backing_file) + return backing_file -- cgit