From c675197fa326319bb410b788595088918597dc39 Mon Sep 17 00:00:00 2001 From: Gordon Chung Date: Sat, 24 Aug 2013 11:14:12 -0400 Subject: [PATCH] missing resource in middleware notification sql backend throws errors because resource is a required value set the resource to HTTP_X_SERVICE_NAME value. Change-Id: If2407881b8e3f3ce313ade5295258f0f72f6ea71 Partial-Bug: #1214257 --- ceilometer/middleware.py | 3 ++- tests/test_middleware.py | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ceilometer/middleware.py b/ceilometer/middleware.py index a13e2d16..c420acd5 100644 --- a/ceilometer/middleware.py +++ b/ceilometer/middleware.py @@ -66,7 +66,8 @@ class HTTPRequest(plugin.NotificationBase): unit=message['event_type'].split('.')[1], user_id=message['payload']['request'].get('HTTP_X_USER_ID'), project_id=message['payload']['request'].get('HTTP_X_PROJECT_ID'), - resource_id=None, + resource_id=message['payload']['request'].get( + 'HTTP_X_SERVICE_NAME'), message=message) diff --git a/tests/test_middleware.py b/tests/test_middleware.py index 7b12ebbd..ceea5899 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -35,7 +35,9 @@ HTTP_REQUEST = { u'event_type': u'http.request', u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451', u'payload': {u'request': {'HTTP_X_FOOBAR': 'foobaz', - 'HTTP_X_USER_ID': 'jd-x32'}}, + 'HTTP_X_USER_ID': 'jd-x32', + 'HTTP_X_PROJECT_ID': 'project-id', + 'HTTP_X_SERVICE_NAME': 'nova'}}, u'priority': u'INFO', u'publisher_id': u'compute.vagrant-precise', u'timestamp': u'2012-05-08 20:23:48.028195', @@ -55,7 +57,10 @@ HTTP_RESPONSE = { u'event_type': u'http.response', u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451', u'payload': {u'request': {'HTTP_X_FOOBAR': 'foobaz', - 'HTTP_X_USER_ID': 'jd-x32'}}, + 'HTTP_X_USER_ID': 'jd-x32', + 'HTTP_X_PROJECT_ID': 'project-id', + 'HTTP_X_SERVICE_NAME': 'nova'}, + u'response': {'status': '200 OK'}}, u'priority': u'INFO', u'publisher_id': u'compute.vagrant-precise', u'timestamp': u'2012-05-08 20:23:48.028195', @@ -69,8 +74,12 @@ class TestNotifications(base.TestCase): ))[0] self.assertEqual(sample.user_id, HTTP_REQUEST['payload']['request']['HTTP_X_USER_ID']) - self.assertEqual(sample.project_id, None) - self.assertEqual(sample.resource_id, None) + self.assertEqual(sample.project_id, + HTTP_REQUEST['payload']['request'] + ['HTTP_X_PROJECT_ID']) + self.assertEqual(sample.resource_id, + HTTP_REQUEST['payload']['request'] + ['HTTP_X_SERVICE_NAME']) self.assertEqual(sample.volume, 1) def test_process_response_notification(self): @@ -78,9 +87,13 @@ class TestNotifications(base.TestCase): HTTP_RESPONSE ))[0] self.assertEqual(sample.user_id, - HTTP_REQUEST['payload']['request']['HTTP_X_USER_ID']) - self.assertEqual(sample.project_id, None) - self.assertEqual(sample.resource_id, None) + HTTP_RESPONSE['payload']['request']['HTTP_X_USER_ID']) + self.assertEqual(sample.project_id, + HTTP_RESPONSE['payload']['request'] + ['HTTP_X_PROJECT_ID']) + self.assertEqual(sample.resource_id, + HTTP_RESPONSE['payload']['request'] + ['HTTP_X_SERVICE_NAME']) self.assertEqual(sample.volume, 1) def test_exchanges(self):