summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/notifier/__init__.py22
-rw-r--r--nova/tests/test_notifier.py12
2 files changed, 18 insertions, 16 deletions
diff --git a/nova/notifier/__init__.py b/nova/notifier/__init__.py
index 942c1a1a2..58809f179 100644
--- a/nova/notifier/__init__.py
+++ b/nova/notifier/__init__.py
@@ -15,6 +15,7 @@
import datetime
import json
+import uuid
from nova import flags
from nova import utils
@@ -41,6 +42,7 @@ def notify(event_name, publisher_id, event_type, priority, payload):
Message format is as follows:
+ message_id - a UUID representing the id for this notification
publisher_id - the source worker_type.host of the message
timestamp - the GMT timestamp the notification was sent at
event_type - the literal type of event (ex. Instance Creation)
@@ -48,23 +50,25 @@ def notify(event_name, publisher_id, event_type, priority, payload):
the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
payload - A python dictionary of attributes
- The payload will be constructed as a dictionary of the above attributes,
- and converted into a JSON dump, which will then be sent via the transport
- mechanism defined by the driver.
+ The message body will be constructed as a dictionary of the above
+ attributes, and converted into a JSON dump, which will then be sent
+ via the transport mechanism defined by the driver.
Message example:
- { 'publisher_id': 'compute.host1',
- 'timestamp': '2011-05-09 22:00:14.621831',
- 'priority': 'WARN',
- 'event_type': 'compute.create_instance',
- 'payload': {'instance_id': 12, ... }}
+ {'message_id': str(uuid.uuid4()),
+ 'publisher_id': 'compute.host1',
+ 'timestamp': datetime.datetime.utcnow(),
+ 'priority': 'WARN',
+ 'event_type': 'compute.create_instance',
+ 'payload': {'instance_id': 12, ... }}
"""
if priority not in log_levels:
raise BadPriorityException('%s not in valid priorities' % priority)
driver = utils.import_class(FLAGS.notification_driver)()
- message = dict(publisher_id=publisher_id,
+ message = dict(message_id=str(uuid.uuid4()),
+ publisher_id=publisher_id,
event_type=event_type,
priority=priority,
payload=payload,
diff --git a/nova/tests/test_notifier.py b/nova/tests/test_notifier.py
index 396ce13b1..640a0cb34 100644
--- a/nova/tests/test_notifier.py
+++ b/nova/tests/test_notifier.py
@@ -53,12 +53,13 @@ class NotifierTestCase(test.TestCase):
annoying"""
def message_assert(cls, blob):
message = json.loads(blob)
- fields = [ ('publisher_id', 'publisher_id'),
- ('event_type', 'event_type'),
- ('priority', 'WARN'),
- ('payload', dict(a=3))]
+ fields = [('publisher_id', 'publisher_id'),
+ ('event_type', 'event_type'),
+ ('priority', 'WARN'),
+ ('payload', dict(a=3))]
for k, v in fields:
self.assertEqual(message[k], v)
+ self.assertTrue(len(message['message_id']) > 0)
self.stubs.Set(nova.notifier.no_op_notifier.NoopNotifier, 'notify',
message_assert)
@@ -81,9 +82,6 @@ class NotifierTestCase(test.TestCase):
self.assertEqual(self.mock_cast, True)
def test_invalid_priority(self):
- self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
- 'nova.notifier.rabbit_notifier.RabbitNotifier')
- self.mock_cast = False
def mock_cast(cls, *args):
pass