Skip to content

Commit

Permalink
handle updated qemu-img info output
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Pádraig Brady committed May 16, 2012
1 parent dc9c3cb commit 0624b7a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions nova/virt/libvirt/utils.py
Expand Up @@ -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


Expand Down

0 comments on commit 0624b7a

Please sign in to comment.