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: