From 03eca41e2c770fd46052fa152327690709529d3e Mon Sep 17 00:00:00 2001 From: Markus Zoeller Date: Mon, 30 May 2016 11:43:47 +0200 Subject: [PATCH] libvirt: virtlogd: use "log" element in char devices This change introduces the usage of the domain XML element for char devices. A follow up change will use this object to store the boot messages of an instance when the parent char device uses the virtlogd as backend for its stdout/stderr output. blueprint libvirt-virtlogd Change-Id: I3fc83cfe20dc5facea2aff3e7a7dc795952999f4 --- nova/tests/unit/virt/libvirt/test_config.py | 53 +++++++++++++++++++++ nova/virt/libvirt/config.py | 25 ++++++++++ 2 files changed, 78 insertions(+) diff --git a/nova/tests/unit/virt/libvirt/test_config.py b/nova/tests/unit/virt/libvirt/test_config.py index 09c4512a2b7b..d0c8ccffcac9 100644 --- a/nova/tests/unit/virt/libvirt/test_config.py +++ b/nova/tests/unit/virt/libvirt/test_config.py @@ -1202,6 +1202,23 @@ class LibvirtConfigGuestHostdevPCI(LibvirtConfigBaseTest): self.assertEqual(obj.type, 'usb') +class LibvirtConfigGuestCharDeviceLog(LibvirtConfigBaseTest): + + def test_config_log(self): + obj = config.LibvirtConfigGuestCharDeviceLog() + obj.file = "/tmp/guestname-logd.log" + obj.append = "on" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + """) + + # create a new object from the XML and check it again + obj2 = config.LibvirtConfigGuestCharDeviceLog() + obj2.parse_str(xml) + self.assertXmlEqual(xml, obj2.to_xml()) + + class LibvirtConfigGuestSerialTest(LibvirtConfigBaseTest): def test_config_file(self): @@ -1227,6 +1244,24 @@ class LibvirtConfigGuestSerialTest(LibvirtConfigBaseTest): """) + def test_config_log(self): + log = config.LibvirtConfigGuestCharDeviceLog() + log.file = "/tmp/guestname-logd.log" + log.append = "off" + + device = config.LibvirtConfigGuestSerial() + device.type = "tcp" + device.listen_port = 11111 + device.listen_host = "0.0.0.0" + device.log = log + + xml = device.to_xml() + self.assertXmlEqual(xml, """ + + + + """) + class LibvirtConfigGuestConsoleTest(LibvirtConfigBaseTest): def test_config_pty(self): @@ -1274,6 +1309,24 @@ class LibvirtConfigGuestConsoleTest(LibvirtConfigBaseTest): """) + def test_config_log(self): + log = config.LibvirtConfigGuestCharDeviceLog() + log.file = "/tmp/guestname-logd.log" + log.append = "off" + + device = config.LibvirtConfigGuestConsole() + device.type = "tcp" + device.listen_port = 11111 + device.listen_host = "0.0.0.0" + device.log = log + + xml = device.to_xml() + self.assertXmlEqual(xml, """ + + + + """) + class LibvirtConfigGuestChannelTest(LibvirtConfigBaseTest): def test_config_spice_minimal(self): diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index e3d5209b3686..25971e73841c 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -1602,6 +1602,7 @@ class LibvirtConfigGuestCharBase(LibvirtConfigGuestDevice): self.source_path = None self.listen_port = None self.listen_host = None + self.log = None def format_dom(self): dev = super(LibvirtConfigGuestCharBase, self).format_dom() @@ -1618,6 +1619,9 @@ class LibvirtConfigGuestCharBase(LibvirtConfigGuestDevice): host=self.listen_host, service=str(self.listen_port))) + if self.log: + dev.append(self.log.format_dom()) + return dev @@ -1643,6 +1647,27 @@ class LibvirtConfigGuestChar(LibvirtConfigGuestCharBase): return dev +class LibvirtConfigGuestCharDeviceLog(LibvirtConfigObject): + """Represents a sub-element to a character device.""" + + def __init__(self, **kwargs): + super(LibvirtConfigGuestCharDeviceLog, self).__init__(root_name="log", + **kwargs) + self.file = None + self.append = "off" + + def parse_dom(self, xmldoc): + super(LibvirtConfigGuestCharDeviceLog, self).parse_dom(xmldoc) + self.file = xmldoc.get("file") + self.append = xmldoc.get("append") + + def format_dom(self): + log = super(LibvirtConfigGuestCharDeviceLog, self).format_dom() + log.set("file", self.file) + log.set("append", self.append) + return log + + class LibvirtConfigGuestSerial(LibvirtConfigGuestChar): def __init__(self, **kwargs):