Merge "refactor get_console_output() for console logfiles"
This commit is contained in:
@@ -3119,43 +3119,33 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||||||
xml = guest.get_xml_desc()
|
xml = guest.get_xml_desc()
|
||||||
tree = etree.fromstring(xml)
|
tree = etree.fromstring(xml)
|
||||||
|
|
||||||
# If the guest has a console logging to a file prefer to use that
|
# check for different types of consoles
|
||||||
file_consoles = tree.findall("./devices/console[@type='file']")
|
path_sources = [
|
||||||
if file_consoles:
|
('file', "./devices/console[@type='file']/source[@path]", 'path'),
|
||||||
for file_console in file_consoles:
|
('pty', "./devices/console[@type='pty']/source[@path]", 'path')]
|
||||||
source_node = file_console.find('./source')
|
console_type = ""
|
||||||
if source_node is None:
|
console_path = ""
|
||||||
continue
|
for c_type, epath, attrib in path_sources:
|
||||||
path = source_node.get("path")
|
node = tree.find(epath)
|
||||||
if not path:
|
if (node is not None) and node.get(attrib):
|
||||||
continue
|
console_type = c_type
|
||||||
|
console_path = node.get(attrib)
|
||||||
|
break
|
||||||
|
|
||||||
if not os.path.exists(path):
|
# instance has no console at all
|
||||||
LOG.info('Instance is configured with a file console, '
|
if not console_path:
|
||||||
'but the backing file is not (yet?) present',
|
raise exception.ConsoleNotAvailable()
|
||||||
|
|
||||||
|
# instance has a console, but file doesn't exist (yet?)
|
||||||
|
if not os.path.exists(console_path):
|
||||||
|
LOG.info('console logfile for instance does not exist',
|
||||||
instance=instance)
|
instance=instance)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
return self._get_console_output_file(instance, path)
|
# pty consoles need special handling
|
||||||
|
if console_type == 'pty':
|
||||||
# Try 'pty' types
|
|
||||||
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
|
|
||||||
pty = source_node.get("path")
|
|
||||||
if not pty:
|
|
||||||
continue
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise exception.ConsoleNotAvailable()
|
|
||||||
else:
|
|
||||||
raise exception.ConsoleNotAvailable()
|
|
||||||
|
|
||||||
console_log = self._get_console_log_path(instance)
|
console_log = self._get_console_log_path(instance)
|
||||||
data = nova.privsep.libvirt.readpty(pty)
|
data = nova.privsep.libvirt.readpty(console_path)
|
||||||
|
|
||||||
# NOTE(markus_z): The virt_types kvm and qemu are the only ones
|
# NOTE(markus_z): The virt_types kvm and qemu are the only ones
|
||||||
# which create a dedicated file device for the console logging.
|
# which create a dedicated file device for the console logging.
|
||||||
@@ -3164,7 +3154,12 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||||||
# that a series of "get_console_output" calls return the complete
|
# that a series of "get_console_output" calls return the complete
|
||||||
# content even after rebooting a guest.
|
# content even after rebooting a guest.
|
||||||
nova.privsep.path.writefile(console_log, 'a+', data)
|
nova.privsep.path.writefile(console_log, 'a+', data)
|
||||||
return self._get_console_output_file(instance, console_log)
|
|
||||||
|
# set console path to logfile, not to pty device
|
||||||
|
console_path = console_log
|
||||||
|
|
||||||
|
# return logfile content
|
||||||
|
return self._get_console_output_file(instance, console_path)
|
||||||
|
|
||||||
def get_host_ip_addr(self):
|
def get_host_ip_addr(self):
|
||||||
ips = compute_utils.get_machine_ips()
|
ips = compute_utils.get_machine_ips()
|
||||||
|
|||||||
Reference in New Issue
Block a user