From b05a32e7f66ab80b6b4623e6b22bac7450c357bc Mon Sep 17 00:00:00 2001 From: Markus Zoeller Date: Mon, 7 Nov 2016 14:36:28 +0100 Subject: [PATCH] libvirt: remove py26 compat code in "get_console_output" The "get_console_output" interface had code for python2.6 compatibility. As we need at least python2.7, we can drop that code, which makes the method (a little) easier to read. The unit tests don't need any change, as the expected result is the same. Change-Id: Ic3c22b96937a836dbc50b7ce3b2ba1a864450180 --- nova/virt/libvirt/driver.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index f9225de9d2ad..9a305dd521ae 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -2652,21 +2652,10 @@ class LibvirtDriver(driver.ComputeDriver): xml = guest.get_xml_desc() tree = etree.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 - if console_types.get('file'): - for file_console in console_types.get('file'): + file_consoles = tree.findall("./devices/console[@type='file']") + if file_consoles: + for file_console in file_consoles: source_node = file_console.find('./source') if source_node is None: continue @@ -2692,8 +2681,9 @@ class LibvirtDriver(driver.ComputeDriver): return log_data # Try 'pty' types - if console_types.get('pty'): - for pty_console in console_types.get('pty'): + pty_consoles = tree.findall("./devices/console[@type='pty']") + if pty_consoles: + for pty_console in pty_consoles: source_node = pty_console.find('./source') if source_node is None: continue