Remove get_config_vhostuser

The 'get_config' in 'nova.virt.libvirt.vif' has two potential code
paths: the os-vif code path or the legacy code path. The former is tried
first, via a call to 'nova_to_osvif_vif' in 'nova.network.ovs_vif_util'.
This in turn looks for a function called '_nova_to_osvif_vif_XYZ', where
'XYZ' is the 'type' field from the VIF object. If this is found then the
relevant os-vif object is generated from nova's VIF objects and this is
used to call another function, '_set_config_XYZ', where 'XYZ' is the
type of the os-vif object. The legacy code path, by comparison, uses the
VIF object directly and simply attempts to call to 'get_config_XYZ' in
'nova.virt.libvirt.vif'. Assuming this is found, it is used to configure
both the VIF object and the libvirt XML.

For VIF types of 'vhostuser', the os-vif code path would attempt to
resolve '_nova_to_osvif_vif_vhostuser' in 'nova.network.os_vif_util'
followed by '_set_config_VIFVHostUser' in the same file. While both of
these exist, the former raises a 'NotImplementedError' for generic
vhost-user interfaces so the 'get_config_vhostuser' function is used,
for which we need to keep a lot of duplicated code around. Simplify this
by simply handling those generic vhost-user interfaces, allowing us to
resolve this issue.

Here's a mapping of the functions along with their os-vif calls:

  nova.virt.libvirt.vif._get_vhostuser_settings
    -> nova.network.os_vif_util._set_vhostuser_settings
  nova.virt.libvirt.vif.get_config_vhostuser
    -> nova.virt.libvirt.vif._set_config_VIFVHostUser

Change-Id: Ifab3006454708ab290b93f02d82b794c334c3946
This commit is contained in:
Stephen Finucane 2018-05-01 11:05:04 +01:00 committed by Stephen Finucane
parent f651ebc0ce
commit a36aec75b4
3 changed files with 26 additions and 30 deletions

View File

@ -440,7 +440,11 @@ def _nova_to_osvif_vif_vhostuser(vif):
_set_vhostuser_settings(vif, obj)
return obj
else:
raise NotImplementedError()
obj = _get_vif_instance(vif, objects.vif.VIFVHostUser,
plugin="noop",
vif_name=_get_vif_name(vif))
_set_vhostuser_settings(vif, obj)
return obj
# VIF_TYPE_IVS = 'ivs'

View File

@ -802,7 +802,27 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
}
)
self.assertIsNone(os_vif_util.nova_to_osvif_vif(vif))
actual = os_vif_util.nova_to_osvif_vif(vif)
expect = osv_objects.vif.VIFVHostUser(
id="dc065497-3c8d-4f44-8fb4-e1d33c16a536",
active=False,
address="22:52:25:62:e2:aa",
plugin="noop",
vif_name="nicdc065497-3c",
path='/fake/socket',
mode='client',
has_traffic_filtering=False,
preserve_on_delete=False,
network=osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915",
bridge_interface=None,
label="Demo Net",
mtu=None,
subnets=osv_objects.subnet.SubnetList(
objects=[])))
self.assertObjEqual(expect, actual)
def test_nova_to_osvif_vhostuser_fp_ovs_hybrid(self):
vif = model.VIF(

View File

@ -417,34 +417,6 @@ class LibvirtGenericVIFDriver(object):
return conf
def _get_vhostuser_settings(self, vif):
vif_details = vif['details']
mode = vif_details.get(network_model.VIF_DETAILS_VHOSTUSER_MODE,
'server')
sock_path = vif_details.get(network_model.VIF_DETAILS_VHOSTUSER_SOCKET)
if sock_path is None:
raise exception.VifDetailsMissingVhostuserSockPath(
vif_id=vif['id'])
return mode, sock_path
def get_config_vhostuser(self, instance, vif, image_meta,
inst_type, virt_type, host):
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)
rx_queue_size, tx_queue_size = self._get_virtio_queue_sizes(host)
designer.set_vif_host_backend_vhostuser_config(
conf, mode, sock_path, rx_queue_size, tx_queue_size)
return conf
def _get_virtio_queue_sizes(self, host):
"""Returns rx/tx queue sizes configured or (None, None)