]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add startup hook after pecan init for plugins
authorKevin Benton <blak111@gmail.com>
Thu, 11 Jun 2015 09:05:22 +0000 (02:05 -0700)
committerKevin Benton <kevinbenton@buttewifi.com>
Sat, 1 Aug 2015 18:54:51 +0000 (18:54 +0000)
Add a startup method to initialize all of the plugins after the
pecan app is configured but before it is returned to guaruntee
that everything is ready before the app starts taking requests.

Change-Id: Id18ac5ab979b5f2cb49b69d8650248010e02fe76
Partially-Implements: blueprint wsgi-pecan-switch

neutron/newapi/app.py
neutron/newapi/startup.py [new file with mode: 0644]
neutron/tests/functional/newapi/test_functional.py

index 517f2690ecfeb30b3bbc2e487ecec6980f37a27c..448896cd9b60070a40b69a16909ed733becd1cd9 100644 (file)
@@ -19,7 +19,7 @@ from oslo_middleware import request_id
 import pecan
 
 from neutron.common import exceptions as n_exc
-
+from neutron.newapi import startup
 
 CONF = cfg.CONF
 CONF.import_opt('bind_host', 'neutron.common.config')
@@ -50,6 +50,7 @@ def setup_app(*args, **kwargs):
         hooks=app_hooks,
         guess_content_type_from_ext=True
     )
+    startup.initialize_all()
 
     return app
 
diff --git a/neutron/newapi/startup.py b/neutron/newapi/startup.py
new file mode 100644 (file)
index 0000000..e2e3f7f
--- /dev/null
@@ -0,0 +1,37 @@
+# Copyright (c) 2015 Mirantis, Inc.
+# 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.
+
+from neutron.api import extensions
+from neutron.api.v2 import attributes
+from neutron import policy
+
+
+def initialize_all():
+    ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
+    ext_mgr.extend_resources("2.0", attributes.RESOURCE_ATTRIBUTE_MAP)
+    for ext in ext_mgr.extensions.values():
+        # make each extension populate its plurals
+        if hasattr(ext, 'get_resources'):
+            ext.get_resources()
+        if hasattr(ext, 'get_extended_resources'):
+            ext.get_extended_resources('v2.0')
+    # Certain policy checks require that the extensions are loaded
+    # and the RESOURCE_ATTRIBUTE_MAP populated before they can be
+    # properly initialized. This can only be claimed with certainty
+    # once this point in the code has been reached. In the event
+    # that the policies have been initialized before this point,
+    # calling reset will cause the next policy check to
+    # re-initialize with all of the required data in place.
+    policy.reset()
index 0dde0bf9f9292d38176dd6b77da588c95685011b..473a7b007b6bdefb5716c0c3e3ed7888a928bf65 100644 (file)
@@ -22,6 +22,7 @@ from pecan.testing import load_test_app
 import testtools
 
 from neutron.common import exceptions as n_exc
+from neutron import manager
 from neutron.tests.unit import testlib_api
 
 
@@ -64,6 +65,9 @@ class TestV2Controller(PecanFunctionalTest):
         response = self.app.delete('/v2.0/ports/44.json')
         self.assertEqual(response.status_int, 200)
 
+    def test_plugin_initialized(self):
+        self.assertIsNotNone(manager.NeutronManager._instance)
+
 
 class TestErrors(PecanFunctionalTest):