Santhosh/Deepak | Made supports_extension method optional for plugin, plugin will be loaded only once
This commit is contained in:
parent
cba26a3e7e
commit
61e4811468
|
@ -48,7 +48,7 @@ class APIRouterV01(wsgi.Router):
|
|||
|
||||
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),
|
||||
|
|
|
@ -234,7 +234,7 @@ class ExtensionMiddleware(wsgi.Middleware):
|
|||
self.ext_mgr = (ext_mgr
|
||||
or ExtensionManager(
|
||||
config_params.get('api_extensions_path',
|
||||
''), QuantumManager().plugin))
|
||||
''), QuantumManager.get_plugin()))
|
||||
|
||||
mapper = routes.Mapper()
|
||||
|
||||
|
@ -352,11 +352,15 @@ class ExtensionManager(object):
|
|||
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.
|
||||
|
||||
|
|
|
@ -44,6 +44,9 @@ def find_config(basepath):
|
|||
|
||||
|
||||
class QuantumManager(object):
|
||||
|
||||
_instance = None
|
||||
|
||||
def __init__(self, config=None):
|
||||
if config == None:
|
||||
self.configuration_file = find_config(
|
||||
|
@ -60,5 +63,8 @@ class QuantumManager(object):
|
|||
"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
|
||||
|
|
|
@ -230,10 +230,10 @@ class QuantumPluginBase(object):
|
|||
"""
|
||||
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
|
||||
"""
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# 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()
|
|
@ -128,6 +128,21 @@ class ExtensionManagerTest(unittest.TestCase):
|
|||
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):
|
||||
|
||||
|
|
Loading…
Reference in New Issue