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
This commit is contained in:
Gordon Chung 2013-08-24 11:14:12 -04:00
parent 056e883373
commit c675197fa3
2 changed files with 22 additions and 8 deletions

View File

@ -66,7 +66,8 @@ class HTTPRequest(plugin.NotificationBase):
unit=message['event_type'].split('.')[1], unit=message['event_type'].split('.')[1],
user_id=message['payload']['request'].get('HTTP_X_USER_ID'), user_id=message['payload']['request'].get('HTTP_X_USER_ID'),
project_id=message['payload']['request'].get('HTTP_X_PROJECT_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) message=message)

View File

@ -35,7 +35,9 @@ HTTP_REQUEST = {
u'event_type': u'http.request', u'event_type': u'http.request',
u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451', u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451',
u'payload': {u'request': {'HTTP_X_FOOBAR': 'foobaz', 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'priority': u'INFO',
u'publisher_id': u'compute.vagrant-precise', u'publisher_id': u'compute.vagrant-precise',
u'timestamp': u'2012-05-08 20:23:48.028195', u'timestamp': u'2012-05-08 20:23:48.028195',
@ -55,7 +57,10 @@ HTTP_RESPONSE = {
u'event_type': u'http.response', u'event_type': u'http.response',
u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451', u'message_id': u'dae6f69c-00e0-41c0-b371-41ec3b7f4451',
u'payload': {u'request': {'HTTP_X_FOOBAR': 'foobaz', 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'priority': u'INFO',
u'publisher_id': u'compute.vagrant-precise', u'publisher_id': u'compute.vagrant-precise',
u'timestamp': u'2012-05-08 20:23:48.028195', u'timestamp': u'2012-05-08 20:23:48.028195',
@ -69,8 +74,12 @@ class TestNotifications(base.TestCase):
))[0] ))[0]
self.assertEqual(sample.user_id, self.assertEqual(sample.user_id,
HTTP_REQUEST['payload']['request']['HTTP_X_USER_ID']) HTTP_REQUEST['payload']['request']['HTTP_X_USER_ID'])
self.assertEqual(sample.project_id, None) self.assertEqual(sample.project_id,
self.assertEqual(sample.resource_id, None) 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) self.assertEqual(sample.volume, 1)
def test_process_response_notification(self): def test_process_response_notification(self):
@ -78,9 +87,13 @@ class TestNotifications(base.TestCase):
HTTP_RESPONSE HTTP_RESPONSE
))[0] ))[0]
self.assertEqual(sample.user_id, self.assertEqual(sample.user_id,
HTTP_REQUEST['payload']['request']['HTTP_X_USER_ID']) HTTP_RESPONSE['payload']['request']['HTTP_X_USER_ID'])
self.assertEqual(sample.project_id, None) self.assertEqual(sample.project_id,
self.assertEqual(sample.resource_id, None) 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) self.assertEqual(sample.volume, 1)
def test_exchanges(self): def test_exchanges(self):