def _setup_routes(self, mapper):
# Loads the quantum plugin
- plugin = manager.QuantumManager().get_plugin()
+ plugin = manager.QuantumManager.get_plugin()
uri_prefix = '/tenants/{tenant_id}/'
mapper.resource('network', 'networks',
controller=networks.Controller(plugin),
self.ext_mgr = (ext_mgr
or ExtensionManager(
config_params.get('api_extensions_path',
- ''), QuantumManager().plugin))
+ ''), QuantumManager.get_plugin()))
mapper = routes.Mapper()
LOG.debug(_('Ext description: %s'), extension.get_description())
LOG.debug(_('Ext namespace: %s'), extension.get_namespace())
LOG.debug(_('Ext updated: %s'), extension.get_updated())
- return self.plugin.supports_extension(extension)
+ return self._plugin_supports(extension)
except AttributeError as ex:
LOG.exception(_("Exception loading extension: %s"), unicode(ex))
return False
+ def _plugin_supports(self, extension):
+ return (hasattr(self.plugin, "supports_extension") and
+ self.plugin.supports_extension(extension))
+
def _load_all_extensions(self):
"""Load extensions from the configured path.
class QuantumManager(object):
+
+ _instance = None
+
def __init__(self, config=None):
if config == None:
self.configuration_file = find_config(
"All compatibility tests passed\n")
self.plugin = plugin_klass()
- def get_plugin(self):
- return self.plugin
+ @classmethod
+ def get_plugin(cls):
+ if(cls._instance is None):
+ cls._instance = QuantumManager()
+ return cls._instance.plugin
"""
pass
- @abstractmethod
def supports_extension(self, extension):
"""
- Returns if the extension is suppoorted
+ Returns if the extension is supported.
+ If this method is not implemented, extensions will not be loaded.
:returns: True or False
"""
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC.
+# 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.
+
+import logging
+logging.basicConfig()
self.assertFalse("e2" in ext_mgr.extensions)
self.assertTrue("e3" in ext_mgr.extensions)
+ def test_extensions_are_not_loaded_for_extensions_unaware_plugins(self):
+ class ExtensionUnawarePlugin(object):
+ """
+ This plugin does not implement supports_extension method.
+ Extensions will not be loaded when this plugin is used.
+ """
+ pass
+
+ ext_mgr = setup_extensions_middleware().ext_mgr
+ ext_mgr.plugin = ExtensionUnawarePlugin()
+
+ ext_mgr.add_extension(StubExtension("e1"))
+
+ self.assertFalse("e1" in ext_mgr.extensions)
+
class ActionExtensionTest(unittest.TestCase):