From ba61a981171b3514219eb6ecf306e421f99ce127 Mon Sep 17 00:00:00 2001 From: Sean Mooney Date: Fri, 11 May 2018 16:50:45 +0000 Subject: [PATCH] add noop plugin - This change adds a noop plugin for use with backends that auto connect to VIFs. Change-Id: I4317ac2294526863d88be16ac54ecafc85ca9e1b --- doc/source/index.rst | 3 +- doc/source/user/plugins/linux-bridge.rst | 4 +- doc/source/user/plugins/noop.rst | 23 +++++++++ doc/source/user/plugins/ovs.rst | 4 +- os_vif/tests/unit/test_os_vif.py | 34 +++++++------ .../add-no-op-plugin-763a6703e7328a24.yaml | 7 +++ setup.cfg | 1 + vif_plug_noop/__init__.py | 0 vif_plug_noop/noop.py | 48 +++++++++++++++++++ vif_plug_noop/tests/__init__.py | 0 vif_plug_noop/tests/unit/__init__.py | 0 vif_plug_noop/tests/unit/test_plugin.py | 37 ++++++++++++++ 12 files changed, 141 insertions(+), 20 deletions(-) create mode 100644 doc/source/user/plugins/noop.rst create mode 100644 releasenotes/notes/add-no-op-plugin-763a6703e7328a24.yaml create mode 100644 vif_plug_noop/__init__.py create mode 100644 vif_plug_noop/noop.py create mode 100644 vif_plug_noop/tests/__init__.py create mode 100644 vif_plug_noop/tests/unit/__init__.py create mode 100644 vif_plug_noop/tests/unit/test_plugin.py diff --git a/doc/source/index.rst b/doc/source/index.rst index c5df9fa7..ddd315b9 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -25,8 +25,9 @@ Usage Guide user/usage user/vif-types user/host-info - user/plugins/ovs user/plugins/linux-bridge + user/plugins/noop + user/plugins/ovs Reference --------- diff --git a/doc/source/user/plugins/linux-bridge.rst b/doc/source/user/plugins/linux-bridge.rst index 43c215f2..f9e4c1ba 100644 --- a/doc/source/user/plugins/linux-bridge.rst +++ b/doc/source/user/plugins/linux-bridge.rst @@ -3,8 +3,8 @@ Linux Bridge ============ The Linux Bridge plugin, ``vif_plug_linux_bridge``, is an `os-vif` VIF plugin -for the Linux Bridge network backend. It is one of two plugins provided as part -of `os-vif` itself, the other being :doc:`ovs`. +for the Linux Bridge network backend. It is one of three plugins provided as part +of `os-vif` itself, the others being :doc:`ovs` and :doc:`noop`. Supported VIF Types =================== diff --git a/doc/source/user/plugins/noop.rst b/doc/source/user/plugins/noop.rst new file mode 100644 index 00000000..b1bce47f --- /dev/null +++ b/doc/source/user/plugins/noop.rst @@ -0,0 +1,23 @@ +===== +no-op +===== + +The no-op plugin, ``vif_plug_noop``, is an `os-vif` VIF plugin +for use with network backends that do not require pluging of network interfaces. +It is one of three plugins provided as part of `os-vif` itself, the others +being :doc:`ovs` and :doc:`linux-bridge`. + +Supported VIF Types +=================== + +The no-op plugin provides support for the following VIF types: + +`VIFVHostUser` + + Configuration where a guest exposes a UNIX socket for its control plane. This + configuration is used with a userspace dataplane such as vpp or snabb switch. + + Refer to :ref:`vif-vhostuser` for more information. + +For information on the VIF type objects, refer to :doc:`/user/vif-types`. Note +that only the above VIF types are supported by this plugin. diff --git a/doc/source/user/plugins/ovs.rst b/doc/source/user/plugins/ovs.rst index 61693d76..60968236 100644 --- a/doc/source/user/plugins/ovs.rst +++ b/doc/source/user/plugins/ovs.rst @@ -3,8 +3,8 @@ Open vSwitch ============ The Open vSwitch plugin, `vif_plug_ovs`, is an `os-vif` VIF plugin for the Open -vSwitch network backend. It is one of two plugins provided as part of `os-vif` -itself, the other being :doc:`linux-bridge`. +vSwitch network backend. It is one of three plugins provided as part of `os-vif` +itself, the others being :doc:`linux-bridge` and :doc:`noop`. Supported VIF Types ------------------- diff --git a/os_vif/tests/unit/test_os_vif.py b/os_vif/tests/unit/test_os_vif.py index 5b347c62..91c2e272 100644 --- a/os_vif/tests/unit/test_os_vif.py +++ b/os_vif/tests/unit/test_os_vif.py @@ -14,8 +14,6 @@ import mock from oslo_config import cfg from stevedore import extension -from vif_plug_linux_bridge import constants as lb_constants - import os_vif from os_vif import exception from os_vif import objects @@ -138,22 +136,28 @@ class TestOSVIF(base.TestCase): def test_host_info_all(self): os_vif.initialize() info = os_vif.host_info() + # NOTE(sean-k-mooney): as out of tree plugins could be + # visable in path assert only at at least all the in + # intree plugins are loaded instead of an exact match. + self.assertTrue(len(info.plugin_info) >= 3) - self.assertEqual(len(info.plugin_info), 2) + plugins = {p.plugin_name: p for p in info.plugin_info} + in_tree_plugin_names = ("linux_bridge", "ovs", "noop") + self.assertTrue(all(name in plugins for name in in_tree_plugin_names)) + lb = plugins["linux_bridge"] + self.assertTrue(any("VIFBridge" == vif.vif_object_name + for vif in lb.vif_info)) - self.assertEqual(info.plugin_info[0].plugin_name, - lb_constants.PLUGIN_NAME) - vif_info = info.plugin_info[0].vif_info - self.assertEqual(len(vif_info), 1) - self.assertEqual(vif_info[0].vif_object_name, "VIFBridge") + ovs = plugins["ovs"] + self.assertTrue(len(ovs.vif_info) >= 4) + vif_names = (vif.vif_object_name for vif in ovs.vif_info) + ovs_vifs = ("VIFBridge", "VIFOpenVSwitch", + "VIFVHostUser", "VIFHostDevice") + self.assertTrue(all(name in ovs_vifs for name in vif_names)) - self.assertEqual(info.plugin_info[1].plugin_name, "ovs") - vif_info = info.plugin_info[1].vif_info - self.assertEqual(len(vif_info), 4) - self.assertEqual(vif_info[0].vif_object_name, "VIFBridge") - self.assertEqual(vif_info[1].vif_object_name, "VIFOpenVSwitch") - self.assertEqual(vif_info[2].vif_object_name, "VIFVHostUser") - self.assertEqual(vif_info[3].vif_object_name, "VIFHostDevice") + noop = plugins["noop"] + self.assertTrue(any("VIFVHostUser" == vif.vif_object_name + for vif in noop.vif_info)) def test_host_info_filtered(self): os_vif.initialize() diff --git a/releasenotes/notes/add-no-op-plugin-763a6703e7328a24.yaml b/releasenotes/notes/add-no-op-plugin-763a6703e7328a24.yaml new file mode 100644 index 00000000..7189d049 --- /dev/null +++ b/releasenotes/notes/add-no-op-plugin-763a6703e7328a24.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + A new VIF plugin, ``vif_plug_noop``, has been added which can be used with + network backends that do not require any action to be performed when a + network interface is plugged. This plugin allow for use of, for example, + the generic vhost user VIF type without OVS. diff --git a/setup.cfg b/setup.cfg index e0342c85..a00feb4f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -60,3 +60,4 @@ output_file = os_vif/locale/os-vif.pot os_vif = linux_bridge = vif_plug_linux_bridge.linux_bridge:LinuxBridgePlugin ovs = vif_plug_ovs.ovs:OvsPlugin + noop = vif_plug_noop.noop:NoOpPlugin diff --git a/vif_plug_noop/__init__.py b/vif_plug_noop/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vif_plug_noop/noop.py b/vif_plug_noop/noop.py new file mode 100644 index 00000000..98801668 --- /dev/null +++ b/vif_plug_noop/noop.py @@ -0,0 +1,48 @@ +# Copyright (C) 2011 Midokura KK +# Copyright (C) 2011 Nicira, Inc +# Copyright 2011 OpenStack Foundation +# Copyright 2018 Intel Corporation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from os_vif import objects +from os_vif import plugin + + +class NoOpPlugin(plugin.PluginBase): + """A no op plugin + + The no op plugin can be used for any vif type that requires + no action to be performed on the backend network when a vif + is plugged. Currently only the VIFVHostUser VIF type is supported. + This pluggin allows for the use of generic vhost user without ovs. + + """ + + def describe(self): + return objects.host_info.HostPluginInfo( + plugin_name="noop", + vif_info=[ + objects.host_info.HostVIFInfo( + vif_object_name=objects.vif.VIFVHostUser.__name__, + min_version="1.0", + max_version="1.0", + supported_port_profiles=[]) + ]) + + def plug(self, vif, instance_info): + pass + + def unplug(self, vif, instance_info): + pass diff --git a/vif_plug_noop/tests/__init__.py b/vif_plug_noop/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vif_plug_noop/tests/unit/__init__.py b/vif_plug_noop/tests/unit/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vif_plug_noop/tests/unit/test_plugin.py b/vif_plug_noop/tests/unit/test_plugin.py new file mode 100644 index 00000000..bbb00989 --- /dev/null +++ b/vif_plug_noop/tests/unit/test_plugin.py @@ -0,0 +1,37 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import testtools + +from os_vif import objects + +from vif_plug_noop import noop + + +class PluginTest(testtools.TestCase): + + def __init__(self, *args, **kwargs): + super(PluginTest, self).__init__(*args, **kwargs) + objects.register_all() + self.plugin = noop.NoOpPlugin.load("noop") + + def test_plug_noop(self): + self.assertIn("plug", dir(self.plugin)) + self.plugin.plug(None, None) + + def test_unplug_noop(self): + self.assertIn("unplug", dir(self.plugin)) + self.plugin.unplug(None, None) + + def test_describe_noop(self): + self.assertIn("describe", dir(self.plugin)) + self.assertTrue(len(self.plugin.describe().vif_info) > 0)