summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2012-03-12 21:27:19 +0000
committerChris Behrens <cbehrens@codestud.com>2012-03-12 21:28:29 +0000
commit625c5e45db62c59691b16fadde464a192af3ac3f (patch)
tree336a0ac92b0181f79f81c8c06c91b8e93098092c
parente18996253ccde16aaf65866d85d05372b75b3a1f (diff)
downloadnova-625c5e45db62c59691b16fadde464a192af3ac3f.tar.gz
nova-625c5e45db62c59691b16fadde464a192af3ac3f.tar.xz
nova-625c5e45db62c59691b16fadde464a192af3ac3f.zip
Fix libvirt get_console_output for Python < 2.7
Fixes bug 953410 Unit tests fail when using Python 2.6. This fixes it. Change-Id: Ic53d16a75f5e4e134a92f27597a77404dd78d0f6
-rw-r--r--nova/virt/libvirt/connection.py41
1 files changed, 31 insertions, 10 deletions
diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py
index 9be1f9c62..8fd00457c 100644
--- a/nova/virt/libvirt/connection.py
+++ b/nova/virt/libvirt/connection.py
@@ -908,18 +908,39 @@ class LibvirtConnection(driver.ComputeDriver):
xml = virt_dom.XMLDesc(0)
tree = ElementTree.fromstring(xml)
+ console_types = {}
+
+ # NOTE(comstud): We want to try 'file' types first, then try 'pty'
+ # types. We can't use Python 2.7 syntax of:
+ # tree.find("./devices/console[@type='file']/source")
+ # because we need to support 2.6.
+ console_nodes = tree.findall('./devices/console')
+ for console_node in console_nodes:
+ console_type = console_node.get('type')
+ console_types.setdefault(console_type, [])
+ console_types[console_type].append(console_node)
+
# If the guest has a console logging to a file prefer to use that
- node = tree.find("./devices/console[@type='file']/source")
- if node is not None:
- fpath = node.get("path")
- return libvirt_utils.load_file(fpath)
-
- # else if there is a PTY, then try to read latest data from that
- node = tree.find("./devices/console[@type='pty']/source")
- if node is None:
- raise exception.Error(_("Guest does not have a console available"))
+ for file_console in console_types.get('file'):
+ source_node = file_console.find('./source')
+ if source_node is None:
+ continue
+ path = source_node.get("path")
+ if not path:
+ continue
+ return libvirt_utils.load_file(path)
- pty = node.get("path")
+ # Try 'pty' types
+ for pty_console in console_types.get('pty'):
+ source_node = pty_console.find('./source')
+ if source_node is None:
+ continue
+ pty = source_node.get("path")
+ if not pty:
+ continue
+ break
+ else:
+ raise exception.Error(_("Guest does not have a console available"))
console_log = os.path.join(FLAGS.instances_path, instance['name'],
'console.log')