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
This commit is contained in:
Elena Ezhova 2015-09-28 14:52:18 +03:00 committed by Armando Migliaccio
parent 216d2d0b75
commit ed729862eb
5 changed files with 11 additions and 109 deletions

View 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

View 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,

View File

@ -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

View 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):

View 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.