From 4a11f754e4140e2baa3d689d905a3a1f99b05a39 Mon Sep 17 00:00:00 2001 From: Itsuro Oda Date: Mon, 6 Jan 2014 15:03:14 +0900 Subject: [PATCH] Make metaplugin be used with a router service plugin "l3_plugin_list" configuration parameter of the metaplugin is permitted blank now. If "l3_plugin_list" is blank, router extension and extensions which extend the router extension don't be included in "supported-extension-aliases" of the metaplugin. This makes the metaplugin be able to be used with a router service plugin. Note that if "l3_plugin_list" is not blank, a router service plugin must not be specified, otherwise the error of the bug report still occurs. This patch removes some router extension related meaningless codes also. (e.g. external-net extension belongs to L2 functionality and be handled by core plugins properly.) Closes-bug: 1266347 DocImpact Change-Id: I0454bc0a4bd7eda5dad18b0538fb7baebe0b9f91 --- etc/neutron/plugins/metaplugin/metaplugin.ini | 3 ++ .../plugins/metaplugin/meta_neutron_plugin.py | 53 +++++++------------ neutron/tests/unit/metaplugin/fake_plugin.py | 3 ++ .../tests/unit/metaplugin/test_metaplugin.py | 24 +++++++-- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/etc/neutron/plugins/metaplugin/metaplugin.ini b/etc/neutron/plugins/metaplugin/metaplugin.ini index 5d4994b87..c5fdb9930 100644 --- a/etc/neutron/plugins/metaplugin/metaplugin.ini +++ b/etc/neutron/plugins/metaplugin/metaplugin.ini @@ -2,6 +2,9 @@ [meta] ## This is list of flavor:neutron_plugins # extension method is used in the order of this list +# If you use a router service plugin, set 'l3_plugin_list' blank. +# If 'l3_plugin_list' is not blank, must not specify a router service +# plugin in 'service_plugins' of neutron.conf. plugin_list= 'openvswitch:neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2,linuxbridge:neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2' l3_plugin_list= 'openvswitch:neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2,linuxbridge:neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2' diff --git a/neutron/plugins/metaplugin/meta_neutron_plugin.py b/neutron/plugins/metaplugin/meta_neutron_plugin.py index 1f1a38606..4657d4670 100644 --- a/neutron/plugins/metaplugin/meta_neutron_plugin.py +++ b/neutron/plugins/metaplugin/meta_neutron_plugin.py @@ -52,9 +52,7 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2, def __init__(self, configfile=None): super(MetaPluginV2, self).__init__() LOG.debug(_("Start initializing metaplugin")) - self.supported_extension_aliases = ['flavor', 'external-net', - 'router', 'ext-gw-mode', - 'extraroute'] + self.supported_extension_aliases = ['flavor', 'external-net'] if cfg.CONF.META.supported_extension_aliases: cfg_aliases = cfg.CONF.META.supported_extension_aliases.split(',') self.supported_extension_aliases += cfg_aliases @@ -80,25 +78,30 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2, self.plugins[flavor] = self._load_plugin(plugin_provider) self.l3_plugins = {} - l3_plugin_list = [plugin_set.split(':') - for plugin_set - in cfg.CONF.META.l3_plugin_list.split(',')] - for flavor, plugin_provider in l3_plugin_list: - if flavor in self.plugins: - self.l3_plugins[flavor] = self.plugins[flavor] - else: - # For l3 only plugin - self.l3_plugins[flavor] = self._load_plugin(plugin_provider) + if cfg.CONF.META.l3_plugin_list: + l3_plugin_list = [plugin_set.split(':') + for plugin_set + in cfg.CONF.META.l3_plugin_list.split(',')] + for flavor, plugin_provider in l3_plugin_list: + if flavor in self.plugins: + self.l3_plugins[flavor] = self.plugins[flavor] + else: + # For l3 only plugin + self.l3_plugins[flavor] = self._load_plugin( + plugin_provider) self.default_flavor = cfg.CONF.META.default_flavor if self.default_flavor not in self.plugins: raise exc.Invalid(_('default_flavor %s is not plugin list') % self.default_flavor) - self.default_l3_flavor = cfg.CONF.META.default_l3_flavor - if self.default_l3_flavor not in self.l3_plugins: - raise exc.Invalid(_('default_l3_flavor %s is not plugin list') % - self.default_l3_flavor) + if self.l3_plugins: + self.default_l3_flavor = cfg.CONF.META.default_l3_flavor + if self.default_l3_flavor not in self.l3_plugins: + raise exc.Invalid(_('default_l3_flavor %s is not plugin list') + % self.default_l3_flavor) + self.supported_extension_aliases += ['router', 'ext-gw-mode', + 'extraroute'] self.extension_map = {} if not cfg.CONF.META.extension_map == '': @@ -108,8 +111,6 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2, for method_name, flavor in extension_list: self.extension_map[method_name] = flavor - self.default_flavor = cfg.CONF.META.default_flavor - def _load_plugin(self, plugin_provider): LOG.debug(_("Plugin location: %s"), plugin_provider) plugin_klass = importutils.import_class(plugin_provider) @@ -146,11 +147,6 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2, flavor = self._get_flavor_by_network_id(context, network['id']) network[FLAVOR_NETWORK] = flavor - def _is_l3_plugin(self, plugin): - if hasattr(plugin, 'supported_extension_aliases'): - return 'router' in plugin.supported_extension_aliases - return False - def create_network(self, context, network): n = network['network'] flavor = n.get(FLAVOR_NETWORK) @@ -159,8 +155,6 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2, plugin = self._get_plugin(flavor) with context.session.begin(subtransactions=True): net = plugin.create_network(context, network) - if not self._is_l3_plugin(plugin): - self._process_l3_create(context, net, network['network']) LOG.debug(_("Created network: %(net_id)s with flavor " "%(flavor)s"), {'net_id': net['id'], 'flavor': flavor}) try: @@ -178,11 +172,7 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2, def update_network(self, context, id, network): flavor = meta_db_v2.get_flavor_by_network(context.session, id) plugin = self._get_plugin(flavor) - with context.session.begin(subtransactions=True): - net = plugin.update_network(context, id, network) - if not self._is_l3_plugin(plugin): - self._process_l3_update(context, net, network['network']) - return net + return plugin.update_network(context, id, network) def delete_network(self, context, id): flavor = meta_db_v2.get_flavor_by_network(context.session, id) @@ -251,9 +241,6 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2, port_in_db = self.get_port(context, id) plugin = self._get_plugin_by_network_id(context, port_in_db['network_id']) - if l3_port_check: - self.prevent_l3_port_deletion(context, id) - self.disassociate_floatingips(context, id) return plugin.delete_port(context, id, l3_port_check) def create_subnet(self, context, subnet): diff --git a/neutron/tests/unit/metaplugin/fake_plugin.py b/neutron/tests/unit/metaplugin/fake_plugin.py index aaa08a5ca..6653ea25b 100644 --- a/neutron/tests/unit/metaplugin/fake_plugin.py +++ b/neutron/tests/unit/metaplugin/fake_plugin.py @@ -58,6 +58,9 @@ class Fake1(db_base_plugin_v2.NeutronDbPluginV2, return port def delete_port(self, context, id, l3_port_check=True): + if l3_port_check: + self.prevent_l3_port_deletion(context, id) + self.disassociate_floatingips(context, id) return super(Fake1, self).delete_port(context, id) diff --git a/neutron/tests/unit/metaplugin/test_metaplugin.py b/neutron/tests/unit/metaplugin/test_metaplugin.py index a15c0f80c..6e70703d3 100644 --- a/neutron/tests/unit/metaplugin/test_metaplugin.py +++ b/neutron/tests/unit/metaplugin/test_metaplugin.py @@ -47,7 +47,7 @@ def etcdir(*p): return os.path.join(ETCDIR, *p) -def setup_metaplugin_conf(): +def setup_metaplugin_conf(has_l3=True): cfg.CONF.set_override('auth_url', 'http://localhost:35357/v2.0', 'PROXY') cfg.CONF.set_override('auth_region', 'RegionOne', 'PROXY') @@ -55,7 +55,10 @@ def setup_metaplugin_conf(): cfg.CONF.set_override('admin_password', 'password', 'PROXY') cfg.CONF.set_override('admin_tenant_name', 'service', 'PROXY') cfg.CONF.set_override('plugin_list', PLUGIN_LIST, 'META') - cfg.CONF.set_override('l3_plugin_list', L3_PLUGIN_LIST, 'META') + if has_l3: + cfg.CONF.set_override('l3_plugin_list', L3_PLUGIN_LIST, 'META') + else: + cfg.CONF.set_override('l3_plugin_list', "", 'META') cfg.CONF.set_override('default_flavor', 'fake2', 'META') cfg.CONF.set_override('default_l3_flavor', 'fake1', 'META') cfg.CONF.set_override('base_mac', "12:34:56:78:90:ab") @@ -68,6 +71,8 @@ def setup_metaplugin_conf(): class MetaNeutronPluginV2Test(base.BaseTestCase): """Class conisting of MetaNeutronPluginV2 unit tests.""" + has_l3 = True + def setUp(self): super(MetaNeutronPluginV2Test, self).setUp() db._ENGINE = None @@ -78,7 +83,7 @@ class MetaNeutronPluginV2Test(base.BaseTestCase): db.configure_db() self.addCleanup(db.clear_db) - setup_metaplugin_conf() + setup_metaplugin_conf(self.has_l3) self.client_cls_p = mock.patch('neutronclient.v2_0.client.Client') client_cls = self.client_cls_p.start() @@ -303,3 +308,16 @@ class MetaNeutronPluginV2Test(base.BaseTestCase): self.fail("AttributeError Error is not raised") self.fail("No Error is not raised") + + +class MetaNeutronPluginV2TestWithoutL3(MetaNeutronPluginV2Test): + """Tests without l3_plugin_list configration.""" + + has_l3 = False + + def test_supported_extension_aliases(self): + self.assertEqual(self.plugin.supported_extension_aliases, + ['flavor', 'external-net']) + + def test_create_delete_router(self): + self.skipTest("Test case without router") -- 2.45.2