From 1ba834c0e48c85bf84ff3ec62fce0d5cb5c39c6d Mon Sep 17 00:00:00 2001 From: Michael Henkel Date: Fri, 3 Mar 2017 16:23:01 +0100 Subject: [PATCH] contrail: add vrouter VIF plugin type support The VIF plugin will provide support OpenContrail SDN Controller driver in nova. It will initially be used for OpenContrail dpdk driver. The plugin is located here: https://github.com/Juniper/contrail-nova-vif-driver Implements: blueprint opencontrail-nova-vif-plugin Change-Id: Ic23effc05c901575f608f2b4c5ccd2b1fb3c2d5a --- nova/network/model.py | 4 ++ nova/network/os_vif_util.py | 6 ++ nova/tests/unit/network/test_os_vif_util.py | 56 +++++++++++++++++++ ...rail-nova-vif-plugin-b132102ad79ebf90.yaml | 9 +++ 4 files changed, 75 insertions(+) create mode 100644 releasenotes/notes/bp-opencontrail-nova-vif-plugin-b132102ad79ebf90.yaml diff --git a/nova/network/model.py b/nova/network/model.py index 11fd371253d5..8c861830debf 100644 --- a/nova/network/model.py +++ b/nova/network/model.py @@ -82,6 +82,10 @@ VIF_DETAILS_VHOSTUSER_OVS_PLUG = 'vhostuser_ovs_plug' # Specifies whether vhost-user socket should be used to # create a fp netdevice interface. VIF_DETAILS_VHOSTUSER_FP_PLUG = 'vhostuser_fp_plug' +# Specifies whether vhost-user socket should be used to +# create a vrouter netdevice interface +# TODO(mhenkel): Consider renaming this to be contrail-specific. +VIF_DETAILS_VHOSTUSER_VROUTER_PLUG = 'vhostuser_vrouter_plug' # ovs vhost user interface type name OVS_VHOSTUSER_INTERFACE_TYPE = 'dpdkvhostuser' diff --git a/nova/network/os_vif_util.py b/nova/network/os_vif_util.py index bc75fbe231b0..cf142c131264 100644 --- a/nova/network/os_vif_util.py +++ b/nova/network/os_vif_util.py @@ -333,6 +333,12 @@ def _nova_to_osvif_vif_vhostuser(vif): obj.bridge_name = vif["network"]["bridge"] _set_vhostuser_settings(vif, obj) return obj + elif vif['details'].get(model.VIF_DETAILS_VHOSTUSER_VROUTER_PLUG, False): + obj = _get_vif_instance(vif, objects.vif.VIFVHostUser, + plugin="contrail_vrouter", + vif_name=_get_vif_name(vif)) + _set_vhostuser_settings(vif, obj) + return obj else: raise NotImplementedError() diff --git a/nova/tests/unit/network/test_os_vif_util.py b/nova/tests/unit/network/test_os_vif_util.py index d426e7e25eb9..2e54057daeb8 100644 --- a/nova/tests/unit/network/test_os_vif_util.py +++ b/nova/tests/unit/network/test_os_vif_util.py @@ -816,3 +816,59 @@ class OSVIFUtilTestCase(test.NoDBTestCase): self.assertRaises(exception.NovaException, os_vif_util.nova_to_osvif_vif, vif) + + def test_nova_to_osvif_vhostuser_vrouter(self): + vif = model.VIF( + id="dc065497-3c8d-4f44-8fb4-e1d33c16a536", + type=model.VIF_TYPE_VHOSTUSER, + address="22:52:25:62:e2:aa", + network=model.Network( + id="b82c1929-051e-481d-8110-4669916c7915", + label="Demo Net", + subnets=[]), + details={ + model.VIF_DETAILS_VHOSTUSER_MODE: 'client', + model.VIF_DETAILS_VHOSTUSER_VROUTER_PLUG: True, + model.VIF_DETAILS_VHOSTUSER_SOCKET: '/fake/socket', + } + ) + + 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="contrail_vrouter", + 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", + subnets=osv_objects.subnet.SubnetList( + objects=[]))) + + self.assertObjEqual(expect, actual) + + def test_nova_to_osvif_vhostuser_vrouter_no_socket_path(self): + vif = model.VIF( + id="dc065497-3c8d-4f44-8fb4-e1d33c16a536", + type=model.VIF_TYPE_VHOSTUSER, + address="22:52:25:62:e2:aa", + network=model.Network( + id="b82c1929-051e-481d-8110-4669916c7915", + label="Demo Net", + subnets=[]), + details={ + model.VIF_DETAILS_VHOSTUSER_MODE: 'client', + model.VIF_DETAILS_VHOSTUSER_VROUTER_PLUG: True, + } + ) + + self.assertRaises(exception.VifDetailsMissingVhostuserSockPath, + os_vif_util.nova_to_osvif_vif, + vif) diff --git a/releasenotes/notes/bp-opencontrail-nova-vif-plugin-b132102ad79ebf90.yaml b/releasenotes/notes/bp-opencontrail-nova-vif-plugin-b132102ad79ebf90.yaml new file mode 100644 index 000000000000..048175f9f1fa --- /dev/null +++ b/releasenotes/notes/bp-opencontrail-nova-vif-plugin-b132102ad79ebf90.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + The model name vhostuser_vrouter_plug is set by the neutron contrail + plugin during a VM (network port) creation. + The libvirt compute driver now supports plugging virtual interfaces + of type "contrail_vrouter" which are provided by + the contrail-nova-vif-driver plugin [1]. + [1] https://github.com/Juniper/contrail-nova-vif-driver