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 <sfinucan@redhat.com>
Closes-bug: #1797146
(cherry picked from commit a235451578)
This commit is contained in:
Stephen Finucane 2018-10-10 16:29:40 +01:00 committed by Stephen Finucane
parent b01bc2fd32
commit d78310e67a
2 changed files with 20 additions and 14 deletions

View File

@ -866,8 +866,10 @@ class LibvirtVifTestCase(test.NoDBTestCase):
mock_set.assert_called_once_with(mock.ANY, 'ca:fe:de:ad:be:ef', mock_set.assert_called_once_with(mock.ANY, 'ca:fe:de:ad:be:ef',
'virtio', None, None, None) 'virtio', None, None, None)
@mock.patch.object(vif.designer, 'set_vif_guest_frontend_config') @mock.patch.object(vif.designer, 'set_vif_guest_frontend_config',
def test_model_sriov_direct_multi_queue_not_set(self, mock_set): 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, self.flags(use_virtio_for_bridges=True,
virt_type='kvm', virt_type='kvm',
group='libvirt') group='libvirt')
@ -876,8 +878,8 @@ class LibvirtVifTestCase(test.NoDBTestCase):
fakelibosinfo)) fakelibosinfo))
d = vif.LibvirtGenericVIFDriver() d = vif.LibvirtGenericVIFDriver()
hostimpl = host.Host("qemu:///system") hostimpl = host.Host("qemu:///system")
image_meta = {'properties': {'os_name': 'fedora22'}} image_meta = objects.ImageMeta.from_dict(
image_meta = objects.ImageMeta.from_dict(image_meta) {'properties': {'hw_vif_model': 'virtio'}})
conf = d.get_base_config(None, 'ca:fe:de:ad:be:ef', image_meta, conf = d.get_base_config(None, 'ca:fe:de:ad:be:ef', image_meta,
None, 'kvm', network_model.VNIC_TYPE_DIRECT, None, 'kvm', network_model.VNIC_TYPE_DIRECT,
hostimpl) hostimpl)
@ -885,6 +887,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
None, None, None, None) None, None, None, None)
self.assertIsNone(conf.vhost_queues) self.assertIsNone(conf.vhost_queues)
self.assertIsNone(conf.driver_name) self.assertIsNone(conf.driver_name)
self.assertIsNone(conf.model)
def _test_model_qemu(self, *vif_objs, **kw): def _test_model_qemu(self, *vif_objs, **kw):
libvirt_version = kw.get('libvirt_version') libvirt_version = kw.get('libvirt_version')

View File

@ -145,19 +145,23 @@ class LibvirtGenericVIFDriver(object):
model = None model = None
driver = None driver = None
vhost_queues = 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 # If the user has specified a 'vif_model' against the
# image then honour that model # image then honour that model
if image_meta: if image_meta:
model = osinfo.HardwareProperties(image_meta).network_model model = osinfo.HardwareProperties(image_meta).network_model
# Note(moshele): Skip passthough vnic_types as they don't support # If the virt type is KVM/QEMU/VZ(Parallels), then use virtio according
# virtio model. # to the global config parameter
if vnic_type not in network_model.VNIC_TYPES_DIRECT_PASSTHROUGH: if (model is None and virt_type in ('kvm', 'qemu', 'parallels') and
# 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): CONF.libvirt.use_virtio_for_bridges):
model = network_model.VIF_MODEL_VIRTIO model = network_model.VIF_MODEL_VIRTIO
@ -184,7 +188,6 @@ class LibvirtGenericVIFDriver(object):
# use vhost and not None. # use vhost and not None.
driver = vhost_drv or driver driver = vhost_drv or driver
rx_queue_size = None
# Note(moshele): rx_queue_size is support only for virtio model # Note(moshele): rx_queue_size is support only for virtio model
if model == network_model.VIF_MODEL_VIRTIO: if model == network_model.VIF_MODEL_VIRTIO:
if driver == 'vhost' or driver is None: if driver == 'vhost' or driver is None: