Blob Blame History Raw
From 4099a82112d192ba01cb3c5fb3a71b5ef8bb7683 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <pbrady@redhat.com>
Date: Wed, 16 May 2012 13:44:46 +0100
Subject: [PATCH] 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 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py
index db7e11b..977eda8 100644
--- a/nova/virt/libvirt/utils.py
+++ b/nova/virt/libvirt/utils.py
@@ -92,10 +92,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