Rajaram/Santhosh|quantum manager loads plugin only once, even though both extension middleware and APIRouter calls it
This commit is contained in:
parent
b282e87f42
commit
7118905054
@ -23,7 +23,7 @@ use = egg:Paste#urlmap
|
|||||||
pipeline = extensions quantumapiapp
|
pipeline = extensions quantumapiapp
|
||||||
|
|
||||||
[filter:extensions]
|
[filter:extensions]
|
||||||
paste.filter_factory = quantum.common.extensions:ExtensionMiddleware.factory
|
paste.filter_factory = quantum.common.extensions:plugin_aware_extension_middleware_factory
|
||||||
|
|
||||||
[app:quantumversions]
|
[app:quantumversions]
|
||||||
paste.app_factory = quantum.api.versions:Versions.factory
|
paste.app_factory = quantum.api.versions:Versions.factory
|
||||||
|
@ -23,7 +23,7 @@ use = egg:Paste#urlmap
|
|||||||
pipeline = extensions quantumapiapp
|
pipeline = extensions quantumapiapp
|
||||||
|
|
||||||
[filter:extensions]
|
[filter:extensions]
|
||||||
paste.filter_factory = quantum.common.extensions:ExtensionMiddleware.factory
|
paste.filter_factory = quantum.common.extensions:plugin_aware_extension_middleware_factory
|
||||||
|
|
||||||
[app:quantumversions]
|
[app:quantumversions]
|
||||||
paste.app_factory = quantum.api.versions:Versions.factory
|
paste.app_factory = quantum.api.versions:Versions.factory
|
||||||
|
@ -18,24 +18,7 @@ api_extensions_path = unit/extensions
|
|||||||
pipeline = extensions extensions_test_app
|
pipeline = extensions extensions_test_app
|
||||||
|
|
||||||
[filter:extensions]
|
[filter:extensions]
|
||||||
paste.filter_factory = quantum.common.extensions:ExtensionMiddleware.factory
|
paste.filter_factory = quantum.common.extensions:plugin_aware_extension_middleware_factory
|
||||||
|
|
||||||
[app:extensions_test_app]
|
[app:extensions_test_app]
|
||||||
paste.app_factory = tests.unit.test_extensions:app_factory
|
paste.app_factory = tests.unit.test_extensions:app_factory
|
||||||
|
|
||||||
[composite:quantum]
|
|
||||||
use = egg:Paste#urlmap
|
|
||||||
/: quantumversions
|
|
||||||
/v0.1: quantumapi
|
|
||||||
|
|
||||||
[pipeline:quantumapi]
|
|
||||||
pipeline = extensions quantumapiapp
|
|
||||||
|
|
||||||
[filter:extensions]
|
|
||||||
paste.filter_factory = quantum.common.extensions:ExtensionMiddleware.factory
|
|
||||||
|
|
||||||
[app:quantumversions]
|
|
||||||
paste.app_factory = quantum.api.versions:Versions.factory
|
|
||||||
|
|
||||||
[app:quantumapiapp]
|
|
||||||
paste.app_factory = quantum.api:APIRouterV01.factory
|
|
||||||
|
@ -48,7 +48,7 @@ class APIRouterV01(wsgi.Router):
|
|||||||
|
|
||||||
def _setup_routes(self, mapper, options):
|
def _setup_routes(self, mapper, options):
|
||||||
# Loads the quantum plugin
|
# Loads the quantum plugin
|
||||||
plugin = manager.QuantumManager(options).get_plugin()
|
plugin = manager.QuantumManager.get_plugin(options)
|
||||||
|
|
||||||
uri_prefix = '/tenants/{tenant_id}/'
|
uri_prefix = '/tenants/{tenant_id}/'
|
||||||
mapper.resource('network', 'networks',
|
mapper.resource('network', 'networks',
|
||||||
|
@ -318,16 +318,14 @@ class ExtensionMiddleware(wsgi.Middleware):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
class PluginAwareExtensionMiddleware(ExtensionMiddleware):
|
def plugin_aware_extension_middleware_factory(global_config, **local_config):
|
||||||
|
"""Paste factory."""
|
||||||
def __init__(self, application, config_params, ext_mgr=None,
|
def _factory(app):
|
||||||
plugin_options=None):
|
extensions_path = global_config.get('api_extensions_path', '')
|
||||||
plugin_aware_extension_mgr = PluginAwareExtensionManager(
|
ext_mgr = PluginAwareExtensionManager(extensions_path,
|
||||||
config_params.get('api_extensions_path', ''),
|
QuantumManager().get_plugin())
|
||||||
plugin_options)
|
return ExtensionMiddleware(app, global_config, ext_mgr=ext_mgr)
|
||||||
ext_mgr = (ext_mgr or plugin_aware_extension_mgr)
|
return _factory
|
||||||
super(PluginAwareExtensionMiddleware, self).__init__(
|
|
||||||
application, config_params, ext_mgr)
|
|
||||||
|
|
||||||
|
|
||||||
class ExtensionManager(object):
|
class ExtensionManager(object):
|
||||||
@ -449,8 +447,8 @@ class ExtensionManager(object):
|
|||||||
|
|
||||||
class PluginAwareExtensionManager(ExtensionManager):
|
class PluginAwareExtensionManager(ExtensionManager):
|
||||||
|
|
||||||
def __init__(self, path, plugin_options=None):
|
def __init__(self, path, plugin):
|
||||||
self.plugin = QuantumManager(plugin_options).get_plugin()
|
self.plugin = plugin
|
||||||
super(PluginAwareExtensionManager, self).__init__(path)
|
super(PluginAwareExtensionManager, self).__init__(path)
|
||||||
|
|
||||||
def _check_extension(self, extension):
|
def _check_extension(self, extension):
|
||||||
@ -470,7 +468,8 @@ class PluginAwareExtensionManager(ExtensionManager):
|
|||||||
if(not hasattr(extension, "get_plugin_interface") or
|
if(not hasattr(extension, "get_plugin_interface") or
|
||||||
extension.get_plugin_interface() is None):
|
extension.get_plugin_interface() is None):
|
||||||
return True
|
return True
|
||||||
return isinstance(self.plugin, extension.get_plugin_interface())
|
return isinstance(self.plugin,
|
||||||
|
extension.get_plugin_interface())
|
||||||
|
|
||||||
|
|
||||||
class RequestExtension(object):
|
class RequestExtension(object):
|
||||||
|
@ -47,6 +47,8 @@ def find_config(basepath):
|
|||||||
|
|
||||||
class QuantumManager(object):
|
class QuantumManager(object):
|
||||||
|
|
||||||
|
_instance = None
|
||||||
|
|
||||||
def __init__(self, options=None, config_file=None):
|
def __init__(self, options=None, config_file=None):
|
||||||
if config_file == None:
|
if config_file == None:
|
||||||
self.configuration_file = find_config(
|
self.configuration_file = find_config(
|
||||||
@ -69,5 +71,8 @@ class QuantumManager(object):
|
|||||||
"All compatibility tests passed")
|
"All compatibility tests passed")
|
||||||
self.plugin = plugin_klass()
|
self.plugin = plugin_klass()
|
||||||
|
|
||||||
def get_plugin(self):
|
@classmethod
|
||||||
return self.plugin
|
def get_plugin(cls, options=None, config_file=None):
|
||||||
|
if cls._instance is None:
|
||||||
|
cls._instance = cls(options, config_file)
|
||||||
|
return cls._instance.plugin
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[DATABASE]
|
[DATABASE]
|
||||||
name = ovs_quantum
|
name = ovs_quantum
|
||||||
user = root
|
user = root
|
||||||
pass = nova
|
pass =
|
||||||
host = 127.0.0.1
|
host = 127.0.0.1
|
||||||
port = 3306
|
port = 3306
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ from quantum.common import wsgi
|
|||||||
from quantum.common import config
|
from quantum.common import config
|
||||||
from quantum.common.extensions import (ExtensionManager,
|
from quantum.common.extensions import (ExtensionManager,
|
||||||
PluginAwareExtensionManager,
|
PluginAwareExtensionManager,
|
||||||
PluginAwareExtensionMiddleware)
|
ExtensionMiddleware)
|
||||||
|
|
||||||
test_conf_file = os.path.join(os.path.dirname(__file__), os.pardir,
|
test_conf_file = os.path.join(os.path.dirname(__file__), os.pardir,
|
||||||
os.pardir, 'etc', 'quantum.conf.test')
|
os.pardir, 'etc', 'quantum.conf.test')
|
||||||
@ -288,19 +288,17 @@ class ExtensionManagerTest(unittest.TestCase):
|
|||||||
|
|
||||||
class PluginAwareExtensionManagerTest(unittest.TestCase):
|
class PluginAwareExtensionManagerTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.ext_mgr = PluginAwareExtensionManager('', plugin_options)
|
|
||||||
|
|
||||||
def test_unsupported_extensions_are_not_loaded(self):
|
def test_unsupported_extensions_are_not_loaded(self):
|
||||||
self.ext_mgr.plugin = StubPlugin(supported_extensions=["e1", "e3"])
|
stub_plugin = StubPlugin(supported_extensions=["e1", "e3"])
|
||||||
|
ext_mgr = PluginAwareExtensionManager('', stub_plugin)
|
||||||
|
|
||||||
self.ext_mgr.add_extension(StubExtension("e1"))
|
ext_mgr.add_extension(StubExtension("e1"))
|
||||||
self.ext_mgr.add_extension(StubExtension("e2"))
|
ext_mgr.add_extension(StubExtension("e2"))
|
||||||
self.ext_mgr.add_extension(StubExtension("e3"))
|
ext_mgr.add_extension(StubExtension("e3"))
|
||||||
|
|
||||||
self.assertTrue("e1" in self.ext_mgr.extensions)
|
self.assertTrue("e1" in ext_mgr.extensions)
|
||||||
self.assertFalse("e2" in self.ext_mgr.extensions)
|
self.assertFalse("e2" in ext_mgr.extensions)
|
||||||
self.assertTrue("e3" in self.ext_mgr.extensions)
|
self.assertTrue("e3" in ext_mgr.extensions)
|
||||||
|
|
||||||
def test_extensions_are_not_loaded_for_plugins_unaware_of_extensions(self):
|
def test_extensions_are_not_loaded_for_plugins_unaware_of_extensions(self):
|
||||||
class ExtensionUnawarePlugin(object):
|
class ExtensionUnawarePlugin(object):
|
||||||
@ -310,10 +308,10 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.ext_mgr.plugin = ExtensionUnawarePlugin()
|
ext_mgr = PluginAwareExtensionManager('', ExtensionUnawarePlugin())
|
||||||
self.ext_mgr.add_extension(StubExtension("e1"))
|
ext_mgr.add_extension(StubExtension("e1"))
|
||||||
|
|
||||||
self.assertFalse("e1" in self.ext_mgr.extensions)
|
self.assertFalse("e1" in ext_mgr.extensions)
|
||||||
|
|
||||||
def test_extensions_not_loaded_for_plugin_without_expected_interface(self):
|
def test_extensions_not_loaded_for_plugin_without_expected_interface(self):
|
||||||
|
|
||||||
@ -323,11 +321,12 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
supported_extension_aliases = ["supported_extension"]
|
supported_extension_aliases = ["supported_extension"]
|
||||||
|
|
||||||
self.ext_mgr.plugin = PluginWithoutExpectedInterface()
|
ext_mgr = PluginAwareExtensionManager('',
|
||||||
self.ext_mgr.add_extension(
|
PluginWithoutExpectedInterface())
|
||||||
|
ext_mgr.add_extension(
|
||||||
ExtensionExpectingPluginInterface("supported_extension"))
|
ExtensionExpectingPluginInterface("supported_extension"))
|
||||||
|
|
||||||
self.assertFalse("e1" in self.ext_mgr.extensions)
|
self.assertFalse("e1" in ext_mgr.extensions)
|
||||||
|
|
||||||
def test_extensions_are_loaded_for_plugin_with_expected_interface(self):
|
def test_extensions_are_loaded_for_plugin_with_expected_interface(self):
|
||||||
|
|
||||||
@ -339,12 +338,12 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def get_foo(self, bar=None):
|
def get_foo(self, bar=None):
|
||||||
pass
|
pass
|
||||||
|
ext_mgr = PluginAwareExtensionManager('',
|
||||||
self.ext_mgr.plugin = PluginWithExpectedInterface()
|
PluginWithExpectedInterface())
|
||||||
self.ext_mgr.add_extension(
|
ext_mgr.add_extension(
|
||||||
ExtensionExpectingPluginInterface("supported_extension"))
|
ExtensionExpectingPluginInterface("supported_extension"))
|
||||||
|
|
||||||
self.assertTrue("supported_extension" in self.ext_mgr.extensions)
|
self.assertTrue("supported_extension" in ext_mgr.extensions)
|
||||||
|
|
||||||
def test_extensions_expecting_quantum_plugin_interface_are_loaded(self):
|
def test_extensions_expecting_quantum_plugin_interface_are_loaded(self):
|
||||||
class ExtensionForQuamtumPluginInterface(StubExtension):
|
class ExtensionForQuamtumPluginInterface(StubExtension):
|
||||||
@ -353,11 +352,11 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
|
|||||||
This will work with any plugin implementing QuantumPluginBase
|
This will work with any plugin implementing QuantumPluginBase
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
stub_plugin = StubPlugin(supported_extensions=["e1"])
|
||||||
|
ext_mgr = PluginAwareExtensionManager('', stub_plugin)
|
||||||
|
ext_mgr.add_extension(ExtensionForQuamtumPluginInterface("e1"))
|
||||||
|
|
||||||
self.ext_mgr.plugin = StubPlugin(supported_extensions=["e1"])
|
self.assertTrue("e1" in ext_mgr.extensions)
|
||||||
self.ext_mgr.add_extension(ExtensionForQuamtumPluginInterface("e1"))
|
|
||||||
|
|
||||||
self.assertTrue("e1" in self.ext_mgr.extensions)
|
|
||||||
|
|
||||||
def test_extensions_without_need_for__plugin_interface_are_loaded(self):
|
def test_extensions_without_need_for__plugin_interface_are_loaded(self):
|
||||||
class ExtensionWithNoNeedForPluginInterface(StubExtension):
|
class ExtensionWithNoNeedForPluginInterface(StubExtension):
|
||||||
@ -368,10 +367,11 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
|
|||||||
def get_plugin_interface(self):
|
def get_plugin_interface(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
self.ext_mgr.plugin = StubPlugin(supported_extensions=["e1"])
|
stub_plugin = StubPlugin(supported_extensions=["e1"])
|
||||||
self.ext_mgr.add_extension(ExtensionWithNoNeedForPluginInterface("e1"))
|
ext_mgr = PluginAwareExtensionManager('', stub_plugin)
|
||||||
|
ext_mgr.add_extension(ExtensionWithNoNeedForPluginInterface("e1"))
|
||||||
|
|
||||||
self.assertTrue("e1" in self.ext_mgr.extensions)
|
self.assertTrue("e1" in ext_mgr.extensions)
|
||||||
|
|
||||||
|
|
||||||
class ExtensionControllerTest(unittest.TestCase):
|
class ExtensionControllerTest(unittest.TestCase):
|
||||||
@ -396,16 +396,6 @@ class ExtensionControllerTest(unittest.TestCase):
|
|||||||
"http://www.fox.in.socks/api/ext/pie/v1.0")
|
"http://www.fox.in.socks/api/ext/pie/v1.0")
|
||||||
|
|
||||||
|
|
||||||
class TestExtensionMiddlewareFactory(unittest.TestCase):
|
|
||||||
|
|
||||||
def test_app_configured_with_extensions_as_filter(self):
|
|
||||||
conf, quantum_app = config.load_paste_app('extensions_app_with_filter',
|
|
||||||
{"config_file": test_conf_file}, None)
|
|
||||||
|
|
||||||
response = TestApp(quantum_app).get("/extensions")
|
|
||||||
self.assertEqual(response.status_int, 200)
|
|
||||||
|
|
||||||
|
|
||||||
def app_factory(global_conf, **local_conf):
|
def app_factory(global_conf, **local_conf):
|
||||||
conf = global_conf.copy()
|
conf = global_conf.copy()
|
||||||
conf.update(local_conf)
|
conf.update(local_conf)
|
||||||
@ -421,8 +411,7 @@ def setup_base_app():
|
|||||||
def setup_extensions_middleware(extension_manager=None):
|
def setup_extensions_middleware(extension_manager=None):
|
||||||
options = {'config_file': test_conf_file}
|
options = {'config_file': test_conf_file}
|
||||||
conf, app = config.load_paste_app('extensions_test_app', options, None)
|
conf, app = config.load_paste_app('extensions_test_app', options, None)
|
||||||
return PluginAwareExtensionMiddleware(app, conf, ext_mgr=extension_manager,
|
return ExtensionMiddleware(app, conf, ext_mgr=extension_manager)
|
||||||
plugin_options=plugin_options)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_extensions_test_app(extension_manager=None):
|
def setup_extensions_test_app(extension_manager=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user