summaryrefslogtreecommitdiff
path: root/oslo_middleware/tests
diff options
context:
space:
mode:
authorMehdi Abaakouk <sileht@redhat.com>2015-08-06 09:15:57 +0200
committerMehdi Abaakouk <sileht@redhat.com>2015-08-07 08:22:42 +0200
commite744501c47e23abc6db52bd70115c4d833b44b4a (patch)
tree86194b157148f3fecea7f24a4cecc754e7ab039c /oslo_middleware/tests
parentd65a8f0afed36e650b5b7fe3def17ce6fccda220 (diff)
downloadoslo-middleware-e744501c47e23abc6db52bd70115c4d833b44b4a.tar.gz
Remove usage of oslo.config global
Currently application that doesn't use the global configuration object have to rely on hack to setup the global oslo config object for each middleware it want to use. For example, gnocchi have its own middleware loader and add crap to load keystonemiddleware: https://github.com/openstack/gnocchi/blob/master/gnocchi/rest/app.py#L140 And it can't use oslo.middleware that relies on the global conf object. Also aodh (use 'paste' for middleware) have to hack the global configuration object for each middlewares it want to use by code... https://review.openstack.org/#/c/208632/1/aodh/service.py But middleware are optional deployer stuffs, we should not write any code for them... This change allows application to use paste-deploy (or any middleware loader) without enforcing the application to use the global oslo.config object. If the middleware want to use oslo.config it should load the configuration file himself (and fallback to the global one if any) The proposed paste configuration to allow this is: [filter:cors] paste.filter_factory = oslo.middleware:cors oslo_config_project = aodh So the cors middleware can find and load the aodh config and what is it interested in. Also, some of them use oslo.config local, some other the global object. Some can be loaded by an middleware loader like paste, some other not. This change make consistent the way we bootstrap all middlewares. Closes-bug: #1482086 Change-Id: Iad197d1f3a386683d818b59718df34e14e15ca5c
Diffstat (limited to 'oslo_middleware/tests')
-rw-r--r--oslo_middleware/tests/test_cors.py3
-rw-r--r--oslo_middleware/tests/test_sizelimit.py6
-rw-r--r--oslo_middleware/tests/test_ssl.py15
3 files changed, 13 insertions, 11 deletions
diff --git a/oslo_middleware/tests/test_cors.py b/oslo_middleware/tests/test_cors.py
index d078d14..8eebf5b 100644
--- a/oslo_middleware/tests/test_cors.py
+++ b/oslo_middleware/tests/test_cors.py
@@ -115,6 +115,9 @@ class CORSTestFilterFactory(test_base.BaseTestCase):
"""Test the CORS filter_factory method."""
def test_filter_factory(self):
+ config = self.useFixture(fixture.Config())
+ config.conf([])
+
# Test a valid filter.
filter = cors.filter_factory(None,
allowed_origin='http://valid.example.com',
diff --git a/oslo_middleware/tests/test_sizelimit.py b/oslo_middleware/tests/test_sizelimit.py
index 2a24659..dc29cd0 100644
--- a/oslo_middleware/tests/test_sizelimit.py
+++ b/oslo_middleware/tests/test_sizelimit.py
@@ -78,15 +78,15 @@ class TestRequestBodySizeLimiter(test_base.BaseTestCase):
def setUp(self):
super(TestRequestBodySizeLimiter, self).setUp()
- fixture = self.useFixture(config.Config(sizelimit.CONF))
- self.MAX_REQUEST_BODY_SIZE = \
- fixture.conf.oslo_middleware.max_request_body_size
+ self.useFixture(config.Config())
@webob.dec.wsgify()
def fake_app(req):
return webob.Response(req.body)
self.middleware = sizelimit.RequestBodySizeLimiter(fake_app)
+ self.MAX_REQUEST_BODY_SIZE = (
+ self.middleware.oslo_conf.oslo_middleware.max_request_body_size)
self.request = webob.Request.blank('/', method='POST')
def test_content_length_acceptable(self):
diff --git a/oslo_middleware/tests/test_ssl.py b/oslo_middleware/tests/test_ssl.py
index 7314260..a94e4c4 100644
--- a/oslo_middleware/tests/test_ssl.py
+++ b/oslo_middleware/tests/test_ssl.py
@@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-from oslo_config import cfg
from oslo_config import fixture as config
from oslotest import base
import webob
@@ -27,8 +26,12 @@ class SSLMiddlewareTest(base.BaseTestCase):
super(SSLMiddlewareTest, self).setUp()
self.useFixture(config.Config())
- def _test_scheme(self, expected, headers):
+ def _test_scheme(self, expected, headers, config=None):
middleware = ssl.SSLMiddleware(None)
+ if config:
+ middleware.oslo_conf.set_override(
+ 'secure_proxy_ssl_header', config,
+ group='oslo_middleware')
request = webob.Request.blank('http://example.com/', headers=headers)
# Ensure ssl middleware does not stop pipeline execution
@@ -44,13 +47,9 @@ class SSLMiddlewareTest(base.BaseTestCase):
self._test_scheme('https', headers)
def test_with_custom_header(self):
- cfg.CONF.set_override('secure_proxy_ssl_header', 'X-My-Header',
- group='oslo_middleware')
headers = {'X-Forwarded-Proto': 'https'}
- self._test_scheme('http', headers)
+ self._test_scheme('http', headers, config='X-My-Header')
def test_with_custom_header_and_forwarded_protocol(self):
- cfg.CONF.set_override('secure_proxy_ssl_header', 'X-My-Header',
- group='oslo_middleware')
headers = {'X-My-Header': 'https'}
- self._test_scheme('https', headers)
+ self._test_scheme('https', headers, config='X-My-Header')