From: Elena Ezhova Date: Mon, 28 Sep 2015 11:52:18 +0000 (+0300) Subject: Consume ConfigurableMiddleware from oslo_middleware X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ed729862eb99dd98e2b7e98f86b1688f393b44e3;p=openstack-build%2Fneutron-build.git Consume ConfigurableMiddleware from oslo_middleware 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 --- diff --git a/doc/source/devref/neutron_api.rst b/doc/source/devref/neutron_api.rst index 8a6592c31..28c779e77 100644 --- a/doc/source/devref/neutron_api.rst +++ b/doc/source/devref/neutron_api.rst @@ -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 diff --git a/neutron/api/extensions.py b/neutron/api/extensions.py index 4af58774a..c494cbc18 100644 --- a/neutron/api/extensions.py +++ b/neutron/api/extensions.py @@ -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, diff --git a/neutron/auth.py b/neutron/auth.py index b8c45e2e8..5d972b884 100644 --- a/neutron/auth.py +++ b/neutron/auth.py @@ -14,17 +14,17 @@ 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 diff --git a/neutron/tests/unit/test_wsgi.py b/neutron/tests/unit/test_wsgi.py index 884a4e736..bafb5392c 100644 --- a/neutron/tests/unit/test_wsgi.py +++ b/neutron/tests/unit/test_wsgi.py @@ -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): diff --git a/neutron/wsgi.py b/neutron/wsgi.py index db46ac669..038b26c6b 100644 --- a/neutron/wsgi.py +++ b/neutron/wsgi.py @@ -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.