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
This commit is contained in:
Stephen Finucane 2018-10-10 16:29:40 +01:00
parent 74aebe0d4e
commit a235451578
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',
'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')

View File

@ -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: