From 6417139b839dba96a6840c745d772e85a4f1d8bc Mon Sep 17 00:00:00 2001 From: gordon chung Date: Mon, 24 Nov 2014 10:28:45 -0500 Subject: [PATCH] fix swift middleware parsing swift middleware is incorrectly stripping out 'HTTP_' headers. This patch fixes this. Change-Id: I866d08badd32c83f72f05d113acc684fc40c501d Closes-Bug: #1394453 --- ceilometer/objectstore/swift_middleware.py | 2 +- ceilometer/tests/objectstore/test_swift_middleware.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ceilometer/objectstore/swift_middleware.py b/ceilometer/objectstore/swift_middleware.py index fc4369db0..fbb033774 100644 --- a/ceilometer/objectstore/swift_middleware.py +++ b/ceilometer/objectstore/swift_middleware.py @@ -150,7 +150,7 @@ class CeilometerMiddleware(object): headers = {} for header in env: if header.startswith('HTTP_') and env[header]: - key = header.strip('HTTP_') + key = header[5:] if isinstance(env[header], six.text_type): headers[key] = env[header].encode('utf-8') else: diff --git a/ceilometer/tests/objectstore/test_swift_middleware.py b/ceilometer/tests/objectstore/test_swift_middleware.py index fb756d787..82a550120 100644 --- a/ceilometer/tests/objectstore/test_swift_middleware.py +++ b/ceilometer/tests/objectstore/test_swift_middleware.py @@ -224,19 +224,20 @@ class TestSwiftMiddleware(tests_base.BaseTestCase): def test_metadata_headers(self): app = swift_middleware.CeilometerMiddleware(FakeApp(), { - 'metadata_headers': 'X_VAR1, x-var2, x-var3' + 'metadata_headers': 'X_VAR1, x-var2, x-var3, token' }) req = FakeRequest('/1.0/account/container', environ={'REQUEST_METHOD': 'GET'}, headers={'X_VAR1': 'value1', - 'X_VAR2': 'value2'}) + 'X_VAR2': 'value2', + 'TOKEN': 'token'}) list(app(req.environ, self.start_response)) samples = self.pipeline_manager.pipelines[0].samples self.assertEqual(2, len(samples)) data = samples[0] http_headers = [k for k in data.resource_metadata.keys() if k.startswith('http_header_')] - self.assertEqual(2, len(http_headers)) + self.assertEqual(3, len(http_headers)) self.assertEqual('1.0', data.resource_metadata['version']) self.assertEqual('container', data.resource_metadata['container']) self.assertIsNone(data.resource_metadata['object']) @@ -244,6 +245,8 @@ class TestSwiftMiddleware(tests_base.BaseTestCase): data.resource_metadata['http_header_x_var1']) self.assertEqual('value2', data.resource_metadata['http_header_x_var2']) + self.assertEqual('token', + data.resource_metadata['http_header_token']) self.assertFalse('http_header_x_var3' in data.resource_metadata) def test_metadata_headers_unicode(self):