From 1027d02977812064b688fe0748c46663c1627cf2 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Fri, 24 Jan 2014 19:43:54 +0000 Subject: [PATCH] Base ML2 bulk support on the loaded drivers Changes the ML2 plugin bulk support flag to be based on the bulk support of the underlying drivers. Closes-Bug: #1272490 Change-Id: I28281c9ecc1696b929c7e0125d02a37946948744 --- neutron/plugins/ml2/managers.py | 4 ++++ neutron/plugins/ml2/plugin.py | 2 ++ .../unit/ml2/drivers/mechanism_bulkless.py | 23 +++++++++++++++++++ neutron/tests/unit/ml2/test_ml2_plugin.py | 18 ++++++++++++++- setup.cfg | 1 + 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 neutron/tests/unit/ml2/drivers/mechanism_bulkless.py diff --git a/neutron/plugins/ml2/managers.py b/neutron/plugins/ml2/managers.py index dec707bad..a60e20987 100644 --- a/neutron/plugins/ml2/managers.py +++ b/neutron/plugins/ml2/managers.py @@ -133,9 +133,13 @@ class MechanismManager(stevedore.named.NamedExtensionManager): [driver.name for driver in self.ordered_mech_drivers]) def initialize(self): + # For ML2 to support bulk operations, each driver must support them + self.native_bulk_support = True for driver in self.ordered_mech_drivers: LOG.info(_("Initializing mechanism driver '%s'"), driver.name) driver.obj.initialize() + self.native_bulk_support &= getattr(driver.obj, + 'native_bulk_support', True) def _call_on_drivers(self, method_name, context, continue_on_failure=False): diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 7b78ac1f0..9e0c6a0ba 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -103,6 +103,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, db.initialize() self.type_manager.initialize() self.mechanism_manager.initialize() + # bulk support depends on the underlying drivers + self.__native_bulk_support = self.mechanism_manager.native_bulk_support self._setup_rpc() diff --git a/neutron/tests/unit/ml2/drivers/mechanism_bulkless.py b/neutron/tests/unit/ml2/drivers/mechanism_bulkless.py new file mode 100644 index 000000000..0a0d3de93 --- /dev/null +++ b/neutron/tests/unit/ml2/drivers/mechanism_bulkless.py @@ -0,0 +1,23 @@ +# Copyright (c) 2014 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.plugins.ml2 import driver_api as api + + +class BulklessMechanismDriver(api.MechanismDriver): + """Test mechanism driver for testing bulk emulation.""" + + def initialize(self): + self.native_bulk_support = False diff --git a/neutron/tests/unit/ml2/test_ml2_plugin.py b/neutron/tests/unit/ml2/test_ml2_plugin.py index 5334262a7..61d26f9d5 100644 --- a/neutron/tests/unit/ml2/test_ml2_plugin.py +++ b/neutron/tests/unit/ml2/test_ml2_plugin.py @@ -29,6 +29,7 @@ PLUGIN_NAME = 'neutron.plugins.ml2.plugin.Ml2Plugin' class Ml2PluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): _plugin_name = PLUGIN_NAME + _mechanism_drivers = ['logger', 'test'] def setUp(self): # We need a L3 service plugin @@ -39,7 +40,7 @@ class Ml2PluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): # we can successfully call through to all mechanism # driver apis. config.cfg.CONF.set_override('mechanism_drivers', - ['logger', 'test'], + self._mechanism_drivers, group='ml2') self.physnet = 'physnet1' self.vlan_range = '1:100' @@ -52,6 +53,21 @@ class Ml2PluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): self.port_create_status = 'DOWN' +class TestMl2BulkToggle(Ml2PluginV2TestCase): + + def test_bulk_disable_with_bulkless_driver(self): + self.tearDown() + self._mechanism_drivers = ['logger', 'test', 'bulkless'] + self.setUp() + self.assertTrue(self._skip_native_bulk) + + def test_bulk_enabled_with_bulk_drivers(self): + self.tearDown() + self._mechanism_drivers = ['logger', 'test'] + self.setUp() + self.assertFalse(self._skip_native_bulk) + + class TestMl2BasicGet(test_plugin.TestBasicGet, Ml2PluginV2TestCase): pass diff --git a/setup.cfg b/setup.cfg index fc1eb6e05..d8c21da15 100644 --- a/setup.cfg +++ b/setup.cfg @@ -150,6 +150,7 @@ neutron.ml2.type_drivers = neutron.ml2.mechanism_drivers = logger = neutron.tests.unit.ml2.drivers.mechanism_logger:LoggerMechanismDriver test = neutron.tests.unit.ml2.drivers.mechanism_test:TestMechanismDriver + bulkless = neutron.tests.unit.ml2.drivers.mechanism_bulkless:BulklessMechanismDriver linuxbridge = neutron.plugins.ml2.drivers.mech_linuxbridge:LinuxbridgeMechanismDriver openvswitch = neutron.plugins.ml2.drivers.mech_openvswitch:OpenvswitchMechanismDriver hyperv = neutron.plugins.ml2.drivers.mech_hyperv:HypervMechanismDriver -- 2.45.2