]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Santhosh/Deepak | Made supports_extension method optional for plugin, plugin will...
authorDeepak N <deepak.n@thoughtworks.com>
Mon, 18 Jul 2011 11:54:26 +0000 (17:24 +0530)
committerDeepak N <deepak.n@thoughtworks.com>
Mon, 18 Jul 2011 11:54:26 +0000 (17:24 +0530)
quantum/api/__init__.py
quantum/common/extensions.py
quantum/manager.py
quantum/quantum_plugin_base.py
tests/__init__.py
tests/unit/test_extensions.py

index fc34767333873c34c8b7da1a404ce11d1e3afca8..87df7673f06cf60bcb1ab60d738b9e3b87e39899 100644 (file)
@@ -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),
index 2682aa92993625197e415b70bf58d8cb8fee80f9..44d52a8b88fdcb193a137e105e86718a42c5a3d3 100644 (file)
@@ -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.
 
index d639ec1d3c9094a13bb7e5c070c2844da8fdd990..33eb77e59048a0cc2e969547ea03332feb405e7f 100644 (file)
@@ -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
index 52947aa7ec35cecfd1bf66ef5614fdcb83bca69d..a43b8c0cc51ab504903796cc64fc2f2804084031 100644 (file)
@@ -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
         """
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9578283b2d65e9ea45d938f9f20f71a12cb7eef4 100644 (file)
@@ -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()
index 7a02cdeb479964d87b216ad40540bec83ac18db9..0fe557f0dbcbcb4d80705d6cc36a2c8dcebef4ff 100644 (file)
@@ -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):