diff --git a/nova/tests/unit/virt/libvirt/test_config.py b/nova/tests/unit/virt/libvirt/test_config.py index 358e68608147..92d7090fe83f 100644 --- a/nova/tests/unit/virt/libvirt/test_config.py +++ b/nova/tests/unit/virt/libvirt/test_config.py @@ -1933,6 +1933,32 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): obj2.parse_str(xml) self.assertXmlEqual(xml, obj2.to_xml()) + def test_config_vhostuser_ensure_driver_never_set(self): + obj = config.LibvirtConfigGuestInterface() + # Even if 'driver_name' attribute is set we should never set + # it in the domain XML for vhostuser interface. + obj.driver_name = "vhost-user" + + obj.net_type = "vhostuser" + obj.vhostuser_type = "unix" + obj.vhostuser_mode = "server" + obj.mac_addr = "DE:AD:BE:EF:CA:FE" + obj.vhostuser_path = "/vhost-user/test.sock" + obj.model = "virtio" + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + + + + """) + + # parse the xml from the first object into a new object and make sure + # they are the same + obj2 = config.LibvirtConfigGuestInterface() + obj2.parse_str(xml) + self.assertXmlEqual(xml, obj2.to_xml()) + def test_config_interface_address(self): xml = """ diff --git a/nova/tests/unit/virt/libvirt/test_vif.py b/nova/tests/unit/virt/libvirt/test_vif.py index cb30be17bf0d..baf2fce4fb67 100644 --- a/nova/tests/unit/virt/libvirt/test_vif.py +++ b/nova/tests/unit/virt/libvirt/test_vif.py @@ -672,7 +672,7 @@ class LibvirtVifTestCase(test.NoDBTestCase): d._set_config_VIFVHostUser(self.instance, self.os_vif_vhostuser, conf, hostimpl) self.assertEqual(4, conf.vhost_queues) - self.assertEqual('vhost', conf.driver_name) + self.assertIsNone(conf.driver_name) has_min_version.assert_called_once_with(MIN_LIBVIRT_VHOSTUSER_MQ) has_min_version.return_value = False diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index d193553a5e0c..bd194cf0d6b7 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -1339,11 +1339,21 @@ class LibvirtConfigGuestInterface(LibvirtConfigGuestDevice): if self.model: dev.append(etree.Element("model", type=self.model)) + drv_elem = None if self.driver_name: drv_elem = etree.Element("driver", name=self.driver_name) + if self.net_type == "vhostuser": + # For vhostuser interface we should not set the driver + # name. + drv_elem = etree.Element("driver") + if drv_elem is not None: if self.vhost_queues is not None: drv_elem.set('queues', str(self.vhost_queues)) - dev.append(drv_elem) + + if drv_elem.get('name') or drv_elem.get('queues'): + # Append the driver element into the dom only if name + # or queues attributes are set. + dev.append(drv_elem) if self.net_type == "ethernet": if self.script is not None: diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py index cb5f8dc16824..348f435e6939 100644 --- a/nova/virt/libvirt/vif.py +++ b/nova/virt/libvirt/vif.py @@ -431,13 +431,18 @@ class LibvirtGenericVIFDriver(object): conf = self.get_base_config(instance, vif['address'], image_meta, inst_type, virt_type, vif['vnic_type'], host) + # TODO(sahid): We should never configure a driver backend for + # vhostuser interface. Specifically override driver to use + # None. This can be removed when get_base_config will be fixed + # and rewrite to set the correct backend. + conf.driver_name = None + mode, sock_path = self._get_vhostuser_settings(vif) designer.set_vif_host_backend_vhostuser_config(conf, mode, sock_path) # (vladikr) Not setting up driver and queues for vhostuser # as queues are not supported in Libvirt until version 1.2.17 if not host.has_min_version(MIN_LIBVIRT_VHOSTUSER_MQ): LOG.debug('Queues are not a vhostuser supported feature.') - conf.driver_name = None conf.vhost_queues = None return conf @@ -474,11 +479,16 @@ class LibvirtGenericVIFDriver(object): self._set_config_VIFPortProfile(instance, vif, conf) def _set_config_VIFVHostUser(self, instance, vif, conf, host=None): + # TODO(sahid): We should never configure a driver backend for + # vhostuser interface. Specifically override driver to use + # None. This can be removed when get_base_config will be fixed + # and rewrite to set the correct backend. + conf.driver_name = None + designer.set_vif_host_backend_vhostuser_config( conf, vif.mode, vif.path) if not host.has_min_version(MIN_LIBVIRT_VHOSTUSER_MQ): LOG.debug('Queues are not a vhostuser supported feature.') - conf.driver_name = None conf.vhost_queues = None def _set_config_VIFHostDevice(self, instance, vif, conf, host=None):