From d78310e67a8fcf59465907eddecba4f5145a0a6f Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 10 Oct 2018 16:29:40 +0100 Subject: [PATCH] Ignore hw_vif_type for direct, direct-physical vNIC types As part of the fix for bug #1789074, we stopped setting the VIF model to virtio for a vif_type of 'direct' or 'direct-physical'. However, if users configured the 'hw_vif_type' image metadata property, the VIF model would be unconditionally set to whatever the user provided. This would result in bug #1789074 recurring. Given that the model attribute is unnecessary for these vNIC types, we can resolve this issue by simply ignoring the image metadata property when configuring such VIFs. Change-Id: I3bf5587c3a49c807bb14533dbbea8f72dca2f02b Signed-off-by: Stephen Finucane Closes-bug: #1797146 (cherry picked from commit a235451578ad7af25268e82500dff5ba6a64ea4e) --- nova/tests/unit/virt/libvirt/test_vif.py | 11 +++++++---- nova/virt/libvirt/vif.py | 23 +++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/test_vif.py b/nova/tests/unit/virt/libvirt/test_vif.py index 9d36f9fa7d0c..41e9853e0ff9 100644 --- a/nova/tests/unit/virt/libvirt/test_vif.py +++ b/nova/tests/unit/virt/libvirt/test_vif.py @@ -866,8 +866,10 @@ class LibvirtVifTestCase(test.NoDBTestCase): mock_set.assert_called_once_with(mock.ANY, 'ca:fe:de:ad:be:ef', 'virtio', None, None, None) - @mock.patch.object(vif.designer, 'set_vif_guest_frontend_config') - def test_model_sriov_direct_multi_queue_not_set(self, mock_set): + @mock.patch.object(vif.designer, 'set_vif_guest_frontend_config', + wraps=vif.designer.set_vif_guest_frontend_config) + def test_model_sriov_direct(self, mock_set): + """Direct attach vNICs shouldn't retrieve info from image_meta.""" self.flags(use_virtio_for_bridges=True, virt_type='kvm', group='libvirt') @@ -876,8 +878,8 @@ class LibvirtVifTestCase(test.NoDBTestCase): fakelibosinfo)) d = vif.LibvirtGenericVIFDriver() hostimpl = host.Host("qemu:///system") - image_meta = {'properties': {'os_name': 'fedora22'}} - image_meta = objects.ImageMeta.from_dict(image_meta) + image_meta = objects.ImageMeta.from_dict( + {'properties': {'hw_vif_model': 'virtio'}}) conf = d.get_base_config(None, 'ca:fe:de:ad:be:ef', image_meta, None, 'kvm', network_model.VNIC_TYPE_DIRECT, hostimpl) @@ -885,6 +887,7 @@ class LibvirtVifTestCase(test.NoDBTestCase): None, None, None, None) self.assertIsNone(conf.vhost_queues) self.assertIsNone(conf.driver_name) + self.assertIsNone(conf.model) def _test_model_qemu(self, *vif_objs, **kw): libvirt_version = kw.get('libvirt_version') diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py index b1cdc8c98f0e..209647b062ed 100644 --- a/nova/virt/libvirt/vif.py +++ b/nova/virt/libvirt/vif.py @@ -145,21 +145,25 @@ class LibvirtGenericVIFDriver(object): model = None driver = None vhost_queues = None + rx_queue_size = None + + # NOTE(stephenfin): Skip most things here as only apply to virtio + # devices + if vnic_type in network_model.VNIC_TYPES_DIRECT_PASSTHROUGH: + designer.set_vif_guest_frontend_config( + conf, mac, model, driver, vhost_queues, rx_queue_size) + return conf # If the user has specified a 'vif_model' against the # image then honour that model if image_meta: model = osinfo.HardwareProperties(image_meta).network_model - # Note(moshele): Skip passthough vnic_types as they don't support - # virtio model. - if vnic_type not in network_model.VNIC_TYPES_DIRECT_PASSTHROUGH: - # Else if the virt type is KVM/QEMU/VZ(Parallels), then use virtio - # according to the global config parameter - if (model is None and - virt_type in ('kvm', 'qemu', 'parallels') and - CONF.libvirt.use_virtio_for_bridges): - model = network_model.VIF_MODEL_VIRTIO + # If the virt type is KVM/QEMU/VZ(Parallels), then use virtio according + # to the global config parameter + if (model is None and virt_type in ('kvm', 'qemu', 'parallels') and + CONF.libvirt.use_virtio_for_bridges): + model = network_model.VIF_MODEL_VIRTIO # Workaround libvirt bug, where it mistakenly # enables vhost mode, even for non-KVM guests @@ -184,7 +188,6 @@ class LibvirtGenericVIFDriver(object): # use vhost and not None. driver = vhost_drv or driver - rx_queue_size = None # Note(moshele): rx_queue_size is support only for virtio model if model == network_model.VIF_MODEL_VIRTIO: if driver == 'vhost' or driver is None: