]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
test_l2population: Use a fake mech driver instead of ofagent
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>
Tue, 27 Jan 2015 02:03:47 +0000 (11:03 +0900)
committerYAMAMOTO Takashi <yamamoto@valinux.co.jp>
Mon, 23 Feb 2015 01:48:52 +0000 (10:48 +0900)
As ofagent mech driver is subject to be moved out of neutron tree
for vendor code decomposition, use a fake mech driver for UTs
instead.

An alternative to remove the relevant test cases was considered.
But it's still nice to have test cases involving multiple drivers.

Anyway using fake drivers rather than real ones for UTs like this
is a good thing.

Partial-Bug: #1412653
Related: blueprint core-vendor-decomposition
Change-Id: I4b0d344da9ccbda79482f64535396fcc1a495d0f

neutron/tests/unit/ml2/drivers/mech_fake_agent.py [new file with mode: 0644]
neutron/tests/unit/ml2/drivers/test_l2population.py
setup.cfg

diff --git a/neutron/tests/unit/ml2/drivers/mech_fake_agent.py b/neutron/tests/unit/ml2/drivers/mech_fake_agent.py
new file mode 100644 (file)
index 0000000..9a66e0b
--- /dev/null
@@ -0,0 +1,65 @@
+# Copyright (C) 2014,2015 VA Linux Systems Japan K.K.
+# Copyright (C) 2014 Fumihiko Kakuma <kakuma at valinux co jp>
+# Copyright (C) 2014,2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
+# All Rights Reserved.
+#
+# Based on openvswitch mechanism driver.
+#
+# Copyright (c) 2013 OpenStack Foundation
+# 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 neutron.agent import securitygroups_rpc
+from neutron.common import constants
+from neutron.extensions import portbindings
+from neutron.openstack.common import log
+from neutron.plugins.common import constants as p_constants
+from neutron.plugins.ml2.drivers import mech_agent
+
+LOG = log.getLogger(__name__)
+
+
+class FakeAgentMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase):
+    """ML2 mechanism driver for testing.
+
+    This is a ML2 mechanism driver used by UTs in test_l2population.
+    This driver implements minimum requirements for L2pop mech driver.
+    As there are some agent-based mechanism drivers and OVS agent
+    mech driver is not the only one to support L2pop, it is useful to
+    test L2pop with multiple drivers like this to check the minimum
+    requirements.
+
+    NOTE(yamamoto): This is a modified copy of ofagent mechanism driver as
+    of writing this.  There's no need to keep this synced with the "real"
+    ofagent mechansim driver or its agent.
+    """
+
+    def __init__(self):
+        sg_enabled = securitygroups_rpc.is_firewall_enabled()
+        vif_details = {portbindings.CAP_PORT_FILTER: sg_enabled,
+                       portbindings.OVS_HYBRID_PLUG: sg_enabled}
+        super(FakeAgentMechanismDriver, self).__init__(
+            # NOTE(yamamoto): l2pop driver has a hardcoded list of
+            # supported agent types.
+            constants.AGENT_TYPE_OFA,
+            portbindings.VIF_TYPE_OVS,
+            vif_details)
+
+    def get_allowed_network_types(self, agent):
+        return (agent['configurations'].get('tunnel_types', []) +
+                [p_constants.TYPE_LOCAL, p_constants.TYPE_FLAT,
+                 p_constants.TYPE_VLAN])
+
+    def get_mappings(self, agent):
+        return dict(agent['configurations'].get('interface_mappings', {}))
index 479df6cfd3aed813909f166274ff0a51678f2cb6..5b57c9e41d5110efcb08482992e15d326487883f 100644 (file)
@@ -83,13 +83,15 @@ L2_AGENT_4 = {
 }
 
 L2_AGENT_5 = {
-    'binary': 'neutron-ofagent-agent',
+    'binary': 'neutron-fake-agent',
     'host': HOST + '_5',
     'topic': constants.L2_AGENT_TOPIC,
     'configurations': {'tunneling_ip': '20.0.0.5',
                        'tunnel_types': [],
                        'interface_mappings': {'physnet1': 'eth9'},
                        'l2pop_network_types': ['vlan']},
+    # NOTE(yamamoto): mech_fake_agent has a comment to explain why
+    # OFA is used here.
     'agent_type': constants.AGENT_TYPE_OFA,
     'tunnel_type': [],
     'start_flag': True
@@ -100,7 +102,7 @@ DEVICE_OWNER_COMPUTE = 'compute:None'
 
 
 class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase):
-    _mechanism_drivers = ['openvswitch', 'ofagent', 'l2population']
+    _mechanism_drivers = ['openvswitch', 'fake_agent', 'l2population']
 
     def setUp(self):
         super(TestL2PopulationRpcTestCase, self).setUp()
index 6cb1a5d46195744fc8d3581b63f77e300e8b9990..6a5a5e5d472e0b28f9e29bcac715c3c7bf6c397a 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -184,6 +184,7 @@ neutron.ml2.mechanism_drivers =
     fslsdn = neutron.plugins.ml2.drivers.freescale.mechanism_fslsdn:FslsdnMechanismDriver
     sriovnicswitch = neutron.plugins.ml2.drivers.mech_sriov.mech_driver:SriovNicSwitchMechanismDriver
     nuage = neutron.plugins.ml2.drivers.mech_nuage.driver:NuageMechanismDriver
+    fake_agent = neutron.tests.unit.ml2.drivers.mech_fake_agent:FakeAgentMechanismDriver
 neutron.ml2.extension_drivers =
     test = neutron.tests.unit.ml2.test_extension_driver_api:TestExtensionDriver
 neutron.openstack.common.cache.backends =