]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Consume ConfigurableMiddleware from oslo_middleware
authorElena Ezhova <eezhova@mirantis.com>
Mon, 28 Sep 2015 11:52:18 +0000 (14:52 +0300)
committerArmando Migliaccio <armamig@gmail.com>
Thu, 8 Oct 2015 17:59:43 +0000 (17:59 +0000)
Middleware class in neutron/wsgi.py can be replaced with
ConfigurableMiddleware from oslo_middleware.

Remove the Debug helper class as it doesn't seem to be used
anywhere. Instead, one can use oslo_middleware.debug.Debug.

Added a note about possible implications for out-of-tree plugins
to neutron_api.rst.

Change-Id: If7360608f94625b7d0972267b763f3e7d7624fee

doc/source/devref/neutron_api.rst
neutron/api/extensions.py
neutron/auth.py
neutron/tests/unit/test_wsgi.py
neutron/wsgi.py

index 8a6592c31a5cb5e8d9f776f31ca909108af2e773..28c779e77b7d6d76b27540b570d00036847c3efe 100644 (file)
@@ -52,6 +52,13 @@ repositories under the neutron tent. Below you can find a list of known
 incompatible changes that could or are known to trigger those breakages.
 The changes are listed in reverse chronological order (newer at the top).
 
+* change: Consume ConfigurableMiddleware from oslo_middleware.
+
+  - commit: If7360608f94625b7d0972267b763f3e7d7624fee
+  - solution: switch to oslo_middleware.base.ConfigurableMiddleware;
+              stop using neutron.wsgi.Middleware and neutron.wsgi.Debug.
+  - severity: Low (some out-of-tree plugins might be affected).
+
 * change: Consume sslutils and wsgi modules from oslo.service.
 
   - commit: Ibfdf07e665fcfcd093a0e31274e1a6116706aec2
index 4af58774ac9d50dd981b5dc70e895c262d589a36..c494cbc18a2f97b6f98c0eb03777e5168512078f 100644 (file)
@@ -21,6 +21,7 @@ import os
 
 from oslo_config import cfg
 from oslo_log import log as logging
+from oslo_middleware import base
 import routes
 import six
 import webob.dec
@@ -240,7 +241,7 @@ class ExtensionController(wsgi.Controller):
         raise webob.exc.HTTPNotFound(msg)
 
 
-class ExtensionMiddleware(wsgi.Middleware):
+class ExtensionMiddleware(base.ConfigurableMiddleware):
     """Extensions middleware for WSGI."""
 
     def __init__(self, application,
index b8c45e2e80414e085f4cce42c4237a90e0a20f00..5d972b8840e8d2f2ce057c883d487f4c49c6ab0a 100644 (file)
 
 from oslo_config import cfg
 from oslo_log import log as logging
+from oslo_middleware import base
 from oslo_middleware import request_id
 import webob.dec
 import webob.exc
 
 from neutron import context
-from neutron import wsgi
 
 LOG = logging.getLogger(__name__)
 
 
-class NeutronKeystoneContext(wsgi.Middleware):
+class NeutronKeystoneContext(base.ConfigurableMiddleware):
     """Make a request context from keystone headers."""
 
     @webob.dec.wsgify
index 884a4e736db739fdf7eea5a7e5ddf62afdd0d9fc..bafb5392c4e6b7c559a10d2a0e3f93e40f99c37c 100644 (file)
@@ -693,16 +693,6 @@ class ResourceTest(base.BaseTestCase):
         self.assertEqual(500, result.status_int)
 
 
-class MiddlewareTest(base.BaseTestCase):
-    def test_process_response(self):
-        def application(environ, start_response):
-            response = 'Success'
-            return response
-        response = application('test', 'fake')
-        result = wsgi.Middleware(application).process_response(response)
-        self.assertEqual('Success', result)
-
-
 class FaultTest(base.BaseTestCase):
     def test_call_fault(self):
         class MyException(object):
index db46ac669ddc1642b6e1994ce8caa9b42b409a30..038b26c6ba746dbc5912b85c35f150a3b53239a3 100644 (file)
@@ -237,67 +237,6 @@ class Server(object):
                              socket_timeout=self.client_socket_timeout)
 
 
-class Middleware(object):
-    """Base WSGI middleware wrapper.
-
-    These classes require an application to be initialized that will be called
-    next.  By default the middleware will simply call its wrapped app, or you
-    can override __call__ to customize its behavior.
-    """
-
-    @classmethod
-    def factory(cls, global_config, **local_config):
-        """Used for paste app factories in paste.deploy config files.
-
-        Any local configuration (that is, values under the [filter:APPNAME]
-        section of the paste config) will be passed into the `__init__` method
-        as kwargs.
-
-        A hypothetical configuration would look like:
-
-            [filter:analytics]
-            redis_host = 127.0.0.1
-            paste.filter_factory = nova.api.analytics:Analytics.factory
-
-        which would result in a call to the `Analytics` class as
-
-            import nova.api.analytics
-            analytics.Analytics(app_from_paste, redis_host='127.0.0.1')
-
-        You could of course re-implement the `factory` method in subclasses,
-        but using the kwarg passing it shouldn't be necessary.
-
-        """
-        def _factory(app):
-            return cls(app, **local_config)
-        return _factory
-
-    def __init__(self, application):
-        self.application = application
-
-    def process_request(self, req):
-        """Called on each request.
-
-        If this returns None, the next application down the stack will be
-        executed. If it returns a response then that response will be returned
-        and execution will stop here.
-
-        """
-        return None
-
-    def process_response(self, response):
-        """Do whatever you'd like to the response."""
-        return response
-
-    @webob.dec.wsgify
-    def __call__(self, req):
-        response = self.process_request(req)
-        if response:
-            return response
-        response = req.get_response(self.application)
-        return self.process_response(response)
-
-
 class Request(wsgi.Request):
 
     def best_match_content_type(self):
@@ -620,41 +559,6 @@ class Application(object):
         raise NotImplementedError(_('You must implement __call__'))
 
 
-class Debug(Middleware):
-    """Middleware for debugging.
-
-    Helper class that can be inserted into any WSGI application chain
-    to get information about the request and response.
-    """
-
-    @webob.dec.wsgify
-    def __call__(self, req):
-        print(("*" * 40) + " REQUEST ENVIRON")
-        for key, value in req.environ.items():
-            print(key, "=", value)
-        print()
-        resp = req.get_response(self.application)
-
-        print(("*" * 40) + " RESPONSE HEADERS")
-        for (key, value) in six.iteritems(resp.headers):
-            print(key, "=", value)
-        print()
-
-        resp.app_iter = self.print_generator(resp.app_iter)
-
-        return resp
-
-    @staticmethod
-    def print_generator(app_iter):
-        """Print contents of a wrapper string iterator when iterated."""
-        print(("*" * 40) + " BODY")
-        for part in app_iter:
-            sys.stdout.write(part)
-            sys.stdout.flush()
-            yield part
-        print()
-
-
 class Resource(Application):
     """WSGI app that handles (de)serialization and controller dispatch.