Add plugin names as constants.

HostPluginInfo plugin_name field is the name of the possible
different plugins that could be used, defined in-tree or out-of-tree
this project.

To avoid typing errors, PLUGIN_NAME constant is added to each project.

Closes-Bug: #1714472
Change-Id: Ibb3b65314958ae56a2389704903c04dc985114d7
This commit is contained in:
Rodolfo Alonso Hernandez 2017-09-01 11:25:50 +01:00
parent 45fa6633d8
commit 9fbc124f7f
9 changed files with 54 additions and 29 deletions

View File

View File

@ -10,6 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from vif_plug_linux_bridge import constants as lb_constants
from vif_plug_ovs import constants as ovs_constants
from os_vif import exception
from os_vif import objects
from os_vif.tests.unit import base
@ -20,10 +23,12 @@ class TestHostInfo(base.TestCase):
def setUp(self):
super(TestHostInfo, self).setUp()
objects.register_all()
self.host_info = objects.host_info.HostInfo(
plugin_info=[
objects.host_info.HostPluginInfo(
plugin_name="linux_brige",
plugin_name=lb_constants.PLUGIN_NAME,
vif_info=[
objects.host_info.HostVIFInfo(
vif_object_name="VIFBridge",
@ -32,7 +37,7 @@ class TestHostInfo(base.TestCase):
),
]),
objects.host_info.HostPluginInfo(
plugin_name="ovs",
plugin_name=ovs_constants.PLUGIN_NAME,
vif_info=[
objects.host_info.HostVIFInfo(
vif_object_name="VIFBridge",
@ -60,24 +65,24 @@ class TestHostInfo(base.TestCase):
self.assertEqual(self.host_info, host_info)
def test_plugin_existance(self):
self.assertTrue(self.host_info.has_plugin("ovs"))
self.assertTrue(self.host_info.has_plugin(ovs_constants.PLUGIN_NAME))
self.assertFalse(self.host_info.has_plugin("fishfood"))
def test_plugin_fetch(self):
plugin = self.host_info.get_plugin("ovs")
self.assertEqual("ovs", plugin.plugin_name)
plugin = self.host_info.get_plugin(ovs_constants.PLUGIN_NAME)
self.assertEqual(ovs_constants.PLUGIN_NAME, plugin.plugin_name)
self.assertRaises(exception.NoMatchingPlugin,
self.host_info.get_plugin,
"fishfood")
def test_vif_existance(self):
plugin = self.host_info.get_plugin("ovs")
plugin = self.host_info.get_plugin(ovs_constants.PLUGIN_NAME)
self.assertTrue(plugin.has_vif("VIFOpenVSwitch"))
self.assertFalse(plugin.has_vif("VIFFishFood"))
def test_vif_fetch(self):
plugin = self.host_info.get_plugin("ovs")
plugin = self.host_info.get_plugin(ovs_constants.PLUGIN_NAME)
vif = plugin.get_vif("VIFOpenVSwitch")
self.assertEqual("VIFOpenVSwitch", vif.vif_object_name)
@ -118,7 +123,7 @@ class TestHostInfo(base.TestCase):
host_info = objects.host_info.HostInfo(
plugin_info=[
objects.host_info.HostPluginInfo(
plugin_name="linux_brige",
plugin_name=lb_constants.PLUGIN_NAME,
vif_info=[
objects.host_info.HostVIFInfo(
vif_object_name="VIFBridge",
@ -127,7 +132,7 @@ class TestHostInfo(base.TestCase):
),
]),
objects.host_info.HostPluginInfo(
plugin_name="ovs",
plugin_name=ovs_constants.PLUGIN_NAME,
vif_info=[
objects.host_info.HostVIFInfo(
vif_object_name="VIFBridge",

View File

@ -14,6 +14,8 @@ 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
@ -139,7 +141,8 @@ class TestOSVIF(base.TestCase):
self.assertEqual(len(info.plugin_info), 2)
self.assertEqual(info.plugin_info[0].plugin_name, "linux_bridge")
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")

View File

@ -0,0 +1,13 @@
# 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.
PLUGIN_NAME = 'linux_bridge'

View File

@ -21,6 +21,7 @@ from os_vif import objects
from os_vif import plugin
from oslo_config import cfg
from vif_plug_linux_bridge import constants
from vif_plug_linux_bridge import iptables
from vif_plug_linux_bridge import linux_net
@ -82,7 +83,7 @@ class LinuxBridgePlugin(plugin.PluginBase):
def describe(self):
return objects.host_info.HostPluginInfo(
plugin_name="linux_bridge",
plugin_name=constants.PLUGIN_NAME,
vif_info=[
objects.host_info.HostVIFInfo(
vif_object_name=objects.vif.VIFBridge.__name__,

View File

@ -15,6 +15,7 @@ import testtools
from os_vif import objects
from vif_plug_linux_bridge import constants
from vif_plug_linux_bridge import linux_bridge
from vif_plug_linux_bridge import linux_net
@ -45,7 +46,7 @@ class PluginTest(testtools.TestCase):
dev_name='tap-xxx-yyy-zzz',
bridge_name="br0")
plugin = linux_bridge.LinuxBridgePlugin.load("linux_bridge")
plugin = linux_bridge.LinuxBridgePlugin.load(constants.PLUGIN_NAME)
plugin.plug(vif, self.instance)
mock_ensure_bridge.assert_not_called()
@ -77,7 +78,7 @@ class PluginTest(testtools.TestCase):
has_traffic_filtering=True,
bridge_name="br0")
plugin = linux_bridge.LinuxBridgePlugin.load("linux_bridge")
plugin = linux_bridge.LinuxBridgePlugin.load(constants.PLUGIN_NAME)
plugin.plug(vif, self.instance)
mock_ensure_bridge.assert_called_with("br0", "eth0",
@ -119,7 +120,7 @@ class PluginTest(testtools.TestCase):
dev_name='tap-xxx-yyy-zzz',
bridge_name="br0")
plugin = linux_bridge.LinuxBridgePlugin.load("linux_bridge")
plugin = linux_bridge.LinuxBridgePlugin.load(constants.PLUGIN_NAME)
plugin.plug(vif, self.instance)
mock_ensure_bridge.assert_not_called()

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
PLUGIN_NAME = 'ovs'
OVS_VHOSTUSER_INTERFACE_TYPE = 'dpdkvhostuser'
OVS_VHOSTUSER_CLIENT_INTERFACE_TYPE = 'dpdkvhostuserclient'
OVS_VHOSTUSER_PREFIX = 'vhu'

View File

@ -66,7 +66,7 @@ class OvsPlugin(plugin.PluginBase):
def describe(self):
return objects.host_info.HostPluginInfo(
plugin_name="ovs",
plugin_name=constants.PLUGIN_NAME,
vif_info=[
objects.host_info.HostVIFInfo(
vif_object_name=objects.vif.VIFBridge.__name__,

View File

@ -108,7 +108,7 @@ class PluginTest(testtools.TestCase):
uuid='f0000000-0000-0000-0000-000000000001')
def test__get_vif_datapath_type(self):
plugin = ovs.OvsPlugin.load('ovs')
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
dp_type = plugin._get_vif_datapath_type(
self.vif_ovs, datapath=constants.OVS_DATAPATH_SYSTEM)
self.assertEqual(self.profile_ovs.datapath_type, dp_type)
@ -119,7 +119,7 @@ class PluginTest(testtools.TestCase):
@mock.patch.object(linux_net, 'create_ovs_vif_port')
def test_create_vif_port(self, mock_create_ovs_vif_port):
plugin = ovs.OvsPlugin.load('ovs')
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin._create_vif_port(
self.vif_ovs, mock.sentinel.vif_name, self.instance,
interface_type=constants.OVS_VHOSTUSER_INTERFACE_TYPE)
@ -134,7 +134,7 @@ class PluginTest(testtools.TestCase):
@mock.patch.object(linux_net, 'create_ovs_vif_port')
def test_create_vif_port_mtu_in_model(self, mock_create_ovs_vif_port):
self.vif_ovs.network = self.network_ovs_mtu
plugin = ovs.OvsPlugin.load('ovs')
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin._create_vif_port(
self.vif_ovs, mock.sentinel.vif_name, self.instance,
interface_type=constants.OVS_VHOSTUSER_INTERFACE_TYPE)
@ -151,7 +151,7 @@ class PluginTest(testtools.TestCase):
def test_plug_ovs(self, ensure_ovs_bridge, mock_sys):
mock_sys.platform = 'linux'
plug_bridge_mock = mock.Mock()
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin._plug_bridge = plug_bridge_mock
plugin.plug(self.vif_ovs, self.instance)
dp_type = ovs.OvsPlugin._get_vif_datapath_type(self.vif_ovs)
@ -199,7 +199,7 @@ class PluginTest(testtools.TestCase):
device_exists.return_value = False
mock_sys.platform = 'linux'
plugin = ovs.OvsPlugin.load('ovs')
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin.plug(self.vif_ovs_hybrid, self.instance)
ensure_bridge.assert_has_calls(calls['ensure_bridge'])
device_exists.assert_has_calls(calls['device_exists'])
@ -239,7 +239,7 @@ class PluginTest(testtools.TestCase):
}
mock_sys.platform = constants.PLATFORM_WIN32
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin.plug(vif, self.instance)
device_exists.assert_has_calls(calls['device_exists'])
_create_vif_port.assert_has_calls(calls['_create_vif_port'])
@ -253,7 +253,7 @@ class PluginTest(testtools.TestCase):
def test_unplug_ovs(self):
unplug_bridge_mock = mock.Mock()
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin._unplug_bridge = unplug_bridge_mock
plugin.unplug(self.vif_ovs, self.instance)
unplug_bridge_mock.assert_not_called()
@ -269,7 +269,7 @@ class PluginTest(testtools.TestCase):
timeout=120)]
}
mock_sys.platform = 'linux'
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin.unplug(self.vif_ovs_hybrid, self.instance)
delete_bridge.assert_has_calls(calls['delete_bridge'])
delete_ovs_vif_port.assert_has_calls(calls['delete_ovs_vif_port'])
@ -278,7 +278,7 @@ class PluginTest(testtools.TestCase):
@mock.patch.object(ovs, 'sys')
def _check_unplug_ovs_windows(self, vif, mock_sys, delete_ovs_vif_port):
mock_sys.platform = constants.PLATFORM_WIN32
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin.unplug(vif, self.instance)
delete_ovs_vif_port.assert_called_once_with('br0', vif.id, timeout=120)
@ -301,7 +301,7 @@ class PluginTest(testtools.TestCase):
'ensure_ovs_bridge': [mock.call('br0', dp_type)]
}
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin.plug(self.vif_vhostuser, self.instance)
_create_vif_port.assert_has_calls(calls['_create_vif_port'])
ensure_ovs_bridge.assert_has_calls(calls['ensure_ovs_bridge'])
@ -325,7 +325,7 @@ class PluginTest(testtools.TestCase):
'ensure_ovs_bridge': [mock.call('br0', dp_type)]
}
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin.plug(self.vif_vhostuser_client, self.instance)
create_ovs_vif_port.assert_has_calls(calls['create_ovs_vif_port'])
ensure_ovs_bridge.assert_has_calls(calls['ensure_ovs_bridge'])
@ -336,7 +336,7 @@ class PluginTest(testtools.TestCase):
'delete_ovs_vif_port': [mock.call('br0', 'vhub679325f-ca',
timeout=120)]
}
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin.unplug(self.vif_vhostuser, self.instance)
delete_ovs_vif_port.assert_has_calls(calls['delete_ovs_vif_port'])
@ -371,7 +371,7 @@ class PluginTest(testtools.TestCase):
self.instance)]
}
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin.plug(self.vif_ovs_vf_passthrough, self.instance)
ensure_ovs_bridge.assert_has_calls(calls['ensure_ovs_bridge'])
get_ifname_by_pci_address.assert_has_calls(
@ -408,7 +408,7 @@ class PluginTest(testtools.TestCase):
get_ifname_by_pci_address.return_value = 'eth0'
get_vf_num_by_pci_address.return_value = '2'
get_representor_port.return_value = 'eth0_2'
plugin = ovs.OvsPlugin.load("ovs")
plugin = ovs.OvsPlugin.load(constants.PLUGIN_NAME)
plugin.unplug(self.vif_ovs_vf_passthrough, self.instance)
get_ifname_by_pci_address.assert_has_calls(
calls['get_ifname_by_pci_address'])