]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Rajaram/Santhosh|quantum manager loads plugin only once, even though both extension...
authorRajaram Mallya <rajarammallya@gmail.com>
Mon, 25 Jul 2011 13:15:21 +0000 (18:45 +0530)
committerRajaram Mallya <rajarammallya@gmail.com>
Mon, 25 Jul 2011 13:15:21 +0000 (18:45 +0530)
etc/quantum.conf
etc/quantum.conf.sample
etc/quantum.conf.test
quantum/api/__init__.py
quantum/common/extensions.py
quantum/manager.py
quantum/plugins/openvswitch/ovs_quantum_plugin.ini
tests/unit/test_extensions.py

index d527c83870ca08d759ccfd53e21dc01fae29820f..e4d910b400c5b662de1790fb14af269f62dbfcf3 100644 (file)
@@ -23,7 +23,7 @@ use = egg:Paste#urlmap
 pipeline = extensions quantumapiapp
 
 [filter:extensions]
-paste.filter_factory = quantum.common.extensions:ExtensionMiddleware.factory
+paste.filter_factory = quantum.common.extensions:plugin_aware_extension_middleware_factory
 
 [app:quantumversions]
 paste.app_factory = quantum.api.versions:Versions.factory
index 502503468fed4a29643d0ea3f3d35d6e74cc5670..eccde5f05954cd672a40603abf23c61fc8fd6941 100644 (file)
@@ -23,7 +23,7 @@ use = egg:Paste#urlmap
 pipeline = extensions quantumapiapp
 
 [filter:extensions]
-paste.filter_factory = quantum.common.extensions:ExtensionMiddleware.factory
+paste.filter_factory = quantum.common.extensions:plugin_aware_extension_middleware_factory
 
 [app:quantumversions]
 paste.app_factory = quantum.api.versions:Versions.factory
index f3199cd888f88b9eb9f92403ac2da88738e6f58b..a7134d2848f78c3262792bc5b0bb9a61a33c2fe4 100644 (file)
@@ -18,24 +18,7 @@ api_extensions_path = unit/extensions
 pipeline = extensions extensions_test_app
 
 [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]
 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
index e0f0d0101d05e6ec1bae5480c01aed5f7c276102..e2b0013868ba764513eadf1f6b261cf6513146ef 100644 (file)
@@ -48,7 +48,7 @@ class APIRouterV01(wsgi.Router):
 
     def _setup_routes(self, mapper, options):
         # Loads the quantum plugin
-        plugin = manager.QuantumManager(options).get_plugin()
+        plugin = manager.QuantumManager.get_plugin(options)
 
         uri_prefix = '/tenants/{tenant_id}/'
         mapper.resource('network', 'networks',
index 521543a40d3de6eca6106682d255dd09c583ef3b..79d3cfb153e6f79e5e8b8e632730315d9b25d8af 100644 (file)
@@ -318,16 +318,14 @@ class ExtensionMiddleware(wsgi.Middleware):
         return app
 
 
-class PluginAwareExtensionMiddleware(ExtensionMiddleware):
-
-    def __init__(self, application, config_params, ext_mgr=None,
-                 plugin_options=None):
-        plugin_aware_extension_mgr = PluginAwareExtensionManager(
-                      config_params.get('api_extensions_path', ''),
-                      plugin_options)
-        ext_mgr = (ext_mgr or plugin_aware_extension_mgr)
-        super(PluginAwareExtensionMiddleware, self).__init__(
-            application, config_params, ext_mgr)
+def plugin_aware_extension_middleware_factory(global_config, **local_config):
+    """Paste factory."""
+    def _factory(app):
+        extensions_path = global_config.get('api_extensions_path', '')
+        ext_mgr = PluginAwareExtensionManager(extensions_path,
+                                              QuantumManager().get_plugin())
+        return ExtensionMiddleware(app, global_config, ext_mgr=ext_mgr)
+    return _factory
 
 
 class ExtensionManager(object):
@@ -449,8 +447,8 @@ class ExtensionManager(object):
 
 class PluginAwareExtensionManager(ExtensionManager):
 
-    def __init__(self, path, plugin_options=None):
-        self.plugin = QuantumManager(plugin_options).get_plugin()
+    def __init__(self, path, plugin):
+        self.plugin = plugin
         super(PluginAwareExtensionManager, self).__init__(path)
 
     def _check_extension(self, extension):
@@ -470,7 +468,8 @@ class PluginAwareExtensionManager(ExtensionManager):
         if(not hasattr(extension, "get_plugin_interface") or
            extension.get_plugin_interface() is None):
             return True
-        return isinstance(self.plugin, extension.get_plugin_interface())
+        return isinstance(self.plugin,
+                          extension.get_plugin_interface())
 
 
 class RequestExtension(object):
index 4c890d7f750729c6b2faa32030afdf7dadd73f19..388324a8db998e2e0deff0f0d9a3b12b980e5360 100644 (file)
@@ -47,6 +47,8 @@ def find_config(basepath):
 
 class QuantumManager(object):
 
+    _instance = None
+
     def __init__(self, options=None, config_file=None):
         if config_file == None:
             self.configuration_file = find_config(
@@ -69,5 +71,8 @@ class QuantumManager(object):
                       "All compatibility tests passed")
         self.plugin = plugin_klass()
 
-    def get_plugin(self):
-        return self.plugin
+    @classmethod
+    def get_plugin(cls, options=None, config_file=None):
+        if cls._instance is None:
+            cls._instance = cls(options, config_file)
+        return cls._instance.plugin
index 66095d85d1bc8ef8277a4fc28c587654c3607d39..3fd52e0c9c1679858adabf32235babb3caedaaf8 100644 (file)
@@ -1,7 +1,7 @@
 [DATABASE]
 name = ovs_quantum
 user = root
-pass = nova
+pass = 
 host = 127.0.0.1
 port = 3306
 
index e9f01e3ebca33471d11adfb917a2ec0a161acd8f..0478e3a3775a884861daa3ea39900e54fdc19428 100644 (file)
@@ -26,7 +26,7 @@ from quantum.common import wsgi
 from quantum.common import config
 from quantum.common.extensions import (ExtensionManager,
                                        PluginAwareExtensionManager,
-                                       PluginAwareExtensionMiddleware)
+                                       ExtensionMiddleware)
 
 test_conf_file = os.path.join(os.path.dirname(__file__), os.pardir,
                               os.pardir, 'etc', 'quantum.conf.test')
@@ -288,19 +288,17 @@ class ExtensionManagerTest(unittest.TestCase):
 
 class PluginAwareExtensionManagerTest(unittest.TestCase):
 
-    def setUp(self):
-        self.ext_mgr = PluginAwareExtensionManager('', plugin_options)
-
     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"))
-        self.ext_mgr.add_extension(StubExtension("e2"))
-        self.ext_mgr.add_extension(StubExtension("e3"))
+        ext_mgr.add_extension(StubExtension("e1"))
+        ext_mgr.add_extension(StubExtension("e2"))
+        ext_mgr.add_extension(StubExtension("e3"))
 
-        self.assertTrue("e1" in self.ext_mgr.extensions)
-        self.assertFalse("e2" in self.ext_mgr.extensions)
-        self.assertTrue("e3" in self.ext_mgr.extensions)
+        self.assertTrue("e1" in ext_mgr.extensions)
+        self.assertFalse("e2" in ext_mgr.extensions)
+        self.assertTrue("e3" in ext_mgr.extensions)
 
     def test_extensions_are_not_loaded_for_plugins_unaware_of_extensions(self):
         class ExtensionUnawarePlugin(object):
@@ -310,10 +308,10 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
             """
             pass
 
-        self.ext_mgr.plugin = ExtensionUnawarePlugin()
-        self.ext_mgr.add_extension(StubExtension("e1"))
+        ext_mgr = PluginAwareExtensionManager('', ExtensionUnawarePlugin())
+        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):
 
@@ -323,11 +321,12 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
             """
             supported_extension_aliases = ["supported_extension"]
 
-        self.ext_mgr.plugin = PluginWithoutExpectedInterface()
-        self.ext_mgr.add_extension(
+        ext_mgr = PluginAwareExtensionManager('',
+                                              PluginWithoutExpectedInterface())
+        ext_mgr.add_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):
 
@@ -339,12 +338,12 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
 
             def get_foo(self, bar=None):
                 pass
-
-        self.ext_mgr.plugin = PluginWithExpectedInterface()
-        self.ext_mgr.add_extension(
+        ext_mgr = PluginAwareExtensionManager('',
+                                              PluginWithExpectedInterface())
+        ext_mgr.add_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):
         class ExtensionForQuamtumPluginInterface(StubExtension):
@@ -353,11 +352,11 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
             This will work with any plugin implementing QuantumPluginBase
             """
             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.ext_mgr.add_extension(ExtensionForQuamtumPluginInterface("e1"))
-
-        self.assertTrue("e1" in self.ext_mgr.extensions)
+        self.assertTrue("e1" in ext_mgr.extensions)
 
     def test_extensions_without_need_for__plugin_interface_are_loaded(self):
         class ExtensionWithNoNeedForPluginInterface(StubExtension):
@@ -368,10 +367,11 @@ class PluginAwareExtensionManagerTest(unittest.TestCase):
             def get_plugin_interface(self):
                 return None
 
-        self.ext_mgr.plugin = StubPlugin(supported_extensions=["e1"])
-        self.ext_mgr.add_extension(ExtensionWithNoNeedForPluginInterface("e1"))
+        stub_plugin = StubPlugin(supported_extensions=["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):
@@ -396,16 +396,6 @@ class ExtensionControllerTest(unittest.TestCase):
                          "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):
     conf = global_conf.copy()
     conf.update(local_conf)
@@ -421,8 +411,7 @@ def setup_base_app():
 def setup_extensions_middleware(extension_manager=None):
     options = {'config_file': test_conf_file}
     conf, app = config.load_paste_app('extensions_test_app', options, None)
-    return PluginAwareExtensionMiddleware(app, conf, ext_mgr=extension_manager,
-                                          plugin_options=plugin_options)
+    return ExtensionMiddleware(app, conf, ext_mgr=extension_manager)
 
 
 def setup_extensions_test_app(extension_manager=None):