diff --git a/nova/tests/test_libvirt_config.py b/nova/tests/test_libvirt_config.py index 5eafba841cd1..56719de11c69 100644 --- a/nova/tests/test_libvirt_config.py +++ b/nova/tests/test_libvirt_config.py @@ -539,6 +539,29 @@ class LibvirtConfigGuestConsoleTest(LibvirtConfigBaseTest): """) +class LibvirtConfigGuestChannelTest(LibvirtConfigBaseTest): + def test_config_spice_minimal(self): + obj = config.LibvirtConfigGuestChannel() + obj.type = "spicevmc" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + + """) + + def test_config_spice_full(self): + obj = config.LibvirtConfigGuestChannel() + obj.type = "spicevmc" + obj.target_name = "com.redhat.spice.0" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + + """) + + class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): def test_config_ethernet(self): obj = config.LibvirtConfigGuestInterface() diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index 6785c8823b11..ed5b21c794be 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -648,21 +648,34 @@ class LibvirtConfigGuestGraphics(LibvirtConfigGuestDevice): return dev -class LibvirtConfigGuestChar(LibvirtConfigGuestDevice): +class LibvirtConfigGuestCharBase(LibvirtConfigGuestDevice): + + def __init__(self, **kwargs): + super(LibvirtConfigGuestCharBase, self).__init__(**kwargs) + + self.type = "pty" + self.source_path = None + + def format_dom(self): + dev = super(LibvirtConfigGuestCharBase, self).format_dom() + + dev.set("type", self.type) + if self.type == "file": + dev.append(etree.Element("source", path=self.source_path)) + + return dev + + +class LibvirtConfigGuestChar(LibvirtConfigGuestCharBase): def __init__(self, **kwargs): super(LibvirtConfigGuestChar, self).__init__(**kwargs) - self.type = "pty" - self.source_path = None self.target_port = None def format_dom(self): dev = super(LibvirtConfigGuestChar, self).format_dom() - dev.set("type", self.type) - if self.type == "file": - dev.append(etree.Element("source", path=self.source_path)) if self.target_port is not None: dev.append(etree.Element("target", port=str(self.target_port))) @@ -683,6 +696,26 @@ class LibvirtConfigGuestConsole(LibvirtConfigGuestChar): **kwargs) +class LibvirtConfigGuestChannel(LibvirtConfigGuestCharBase): + + def __init__(self, **kwargs): + super(LibvirtConfigGuestChannel, self).__init__(root_name="channel", + **kwargs) + + self.target_type = "virtio" + self.target_name = None + + def format_dom(self): + dev = super(LibvirtConfigGuestChannel, self).format_dom() + + target = etree.Element("target", type=self.target_type) + if self.target_name is not None: + target.set("name", self.target_name) + dev.append(target) + + return dev + + class LibvirtConfigGuest(LibvirtConfigObject): def __init__(self, **kwargs):