summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCerberus <matt.dietz@rackspace.com>2011-05-16 15:16:34 -0500
committerCerberus <matt.dietz@rackspace.com>2011-05-16 15:16:34 -0500
commitea847e600249f1e3b65e04cfaa67014508c26e95 (patch)
tree8f04e648811e1a718cc88169309dd92cdc179b19
parent0d3627f8276b27be35962c2d947a0c8bb8e8fbb6 (diff)
Merge prop changes
-rw-r--r--nova/flags.py2
-rw-r--r--nova/notifier/api.py20
-rw-r--r--nova/notifier/log_notifier.py19
-rw-r--r--nova/notifier/no_op_notifier.py9
-rw-r--r--nova/notifier/rabbit_notifier.py19
-rw-r--r--nova/tests/test_notifier.py22
6 files changed, 44 insertions, 47 deletions
diff --git a/nova/flags.py b/nova/flags.py
index a1f7f71c8..32cb6efa8 100644
--- a/nova/flags.py
+++ b/nova/flags.py
@@ -370,7 +370,7 @@ DEFINE_string('node_availability_zone', 'nova',
'availability zone of this node')
DEFINE_string('notification_driver',
- 'nova.notifier.no_op_notifier.NoopNotifier',
+ 'nova.notifier.no_op_notifier',
'Default driver for sending notifications')
DEFINE_list('memcached_servers', None,
'Memcached servers or None for in process cache.')
diff --git a/nova/notifier/api.py b/nova/notifier/api.py
index 4fcfa84ff..5b9b8ea29 100644
--- a/nova/notifier/api.py
+++ b/nova/notifier/api.py
@@ -37,21 +37,25 @@ class BadPriorityException(Exception):
pass
-def notify(event_name, publisher_id, event_type, priority, message):
+def notify(publisher_id, event_type, priority, message):
"""
Sends a notification using the specified driver
- Message format is as follows:
+ Notify parameters:
- 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)
priority - patterned after the enumeration of Python logging levels in
the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
message - A python dictionary of attributes
- The message payload will be constructed as a dictionary of the above
+ Outgoing message format includes the above parameters, and appends the
+ following:
+
+ message_id - a UUID representing the id for this notification
+ timestamp - the GMT timestamp the notification was sent at
+
+ The composite message will be constructed as a dictionary of the above
attributes, which will then be sent via the transport mechanism defined
by the driver.
@@ -62,17 +66,17 @@ def notify(event_name, publisher_id, event_type, priority, message):
'timestamp': datetime.datetime.utcnow(),
'priority': 'WARN',
'event_type': 'compute.create_instance',
- 'message': {'instance_id': 12, ... }}
+ '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)()
+ driver = utils.import_object(FLAGS.notification_driver)
msg = dict(message_id=str(uuid.uuid4()),
publisher_id=publisher_id,
event_type=event_type,
priority=priority,
- message=message,
+ payload=message,
timestamp=str(datetime.datetime.utcnow()))
driver.notify(msg)
diff --git a/nova/notifier/log_notifier.py b/nova/notifier/log_notifier.py
index f072a6125..a3df31721 100644
--- a/nova/notifier/log_notifier.py
+++ b/nova/notifier/log_notifier.py
@@ -21,14 +21,13 @@ from nova import log as logging
FLAGS = flags.FLAGS
-class LogNotifier(object):
- """Log notifications using nova's default logging system"""
+def notify(message):
+ """Notifies the recipient of the desired event given the model.
+ Log notifications using nova's default logging system"""
- def notify(self, message):
- """Notifies the recipient of the desired event given the model"""
- priority = message.get('priority',
- FLAGS.default_notification_level)
- priority = priority.lower()
- logger = logging.getLogger(
- 'nova.notification.%s' % message['event_type'])
- getattr(logger, priority)(json.dumps(message))
+ priority = message.get('priority',
+ FLAGS.default_notification_level)
+ priority = priority.lower()
+ logger = logging.getLogger(
+ 'nova.notification.%s' % message['event_type'])
+ getattr(logger, priority)(json.dumps(message))
diff --git a/nova/notifier/no_op_notifier.py b/nova/notifier/no_op_notifier.py
index f5e745f1f..029710505 100644
--- a/nova/notifier/no_op_notifier.py
+++ b/nova/notifier/no_op_notifier.py
@@ -14,9 +14,6 @@
# under the License.
-class NoopNotifier(object):
- """A notifier that doesn't actually do anything. Simply a placeholder"""
-
- def notify(self, message):
- """Notifies the recipient of the desired event given the model"""
- pass
+def notify(message):
+ """Notifies the recipient of the desired event given the model"""
+ pass
diff --git a/nova/notifier/rabbit_notifier.py b/nova/notifier/rabbit_notifier.py
index 7e2ee5f0b..acab79658 100644
--- a/nova/notifier/rabbit_notifier.py
+++ b/nova/notifier/rabbit_notifier.py
@@ -25,14 +25,11 @@ flags.DEFINE_string('notification_topic', 'notifications',
'RabbitMQ topic used for Nova notifications')
-class RabbitNotifier(object):
- """Sends notifications to a specific RabbitMQ server and topic"""
-
- def notify(self, message):
- """Sends a notification to the RabbitMQ"""
- context = nova.context.get_admin_context()
- priority = message.get('priority',
- FLAGS.default_notification_level)
- priority = priority.lower()
- topic = '%s.%s' % (FLAGS.notification_topic, priority)
- rpc.cast(context, topic, message)
+def notify(message):
+ """Sends a notification to the RabbitMQ"""
+ context = nova.context.get_admin_context()
+ priority = message.get('priority',
+ FLAGS.default_notification_level)
+ priority = priority.lower()
+ topic = '%s.%s' % (FLAGS.notification_topic, priority)
+ rpc.cast(context, topic, message)
diff --git a/nova/tests/test_notifier.py b/nova/tests/test_notifier.py
index 82c4d3f5a..b6b0fcc68 100644
--- a/nova/tests/test_notifier.py
+++ b/nova/tests/test_notifier.py
@@ -43,12 +43,12 @@ class NotifierTestCase(test.TestCase):
def mock_notify(cls, *args):
self.notify_called = True
- self.stubs.Set(nova.notifier.no_op_notifier.NoopNotifier, 'notify',
+ self.stubs.Set(nova.notifier.no_op_notifier, 'notify',
mock_notify)
class Mock(object):
pass
- notify('event_name', 'publisher_id', 'event_type',
+ notify('publisher_id', 'event_type',
nova.notifier.api.WARN, dict(a=3))
self.assertEqual(self.notify_called, True)
@@ -56,24 +56,24 @@ class NotifierTestCase(test.TestCase):
"""A test to ensure changing the message format is prohibitively
annoying"""
- def message_assert(cls, message):
+ def message_assert(message):
fields = [('publisher_id', 'publisher_id'),
('event_type', 'event_type'),
('priority', 'WARN'),
- ('message', dict(a=3))]
+ ('payload', dict(a=3))]
for k, v in fields:
self.assertEqual(message[k], v)
self.assertTrue(len(message['message_id']) > 0)
self.assertTrue(len(message['timestamp']) > 0)
- self.stubs.Set(nova.notifier.no_op_notifier.NoopNotifier, 'notify',
+ self.stubs.Set(nova.notifier.no_op_notifier, 'notify',
message_assert)
- notify('event_name', 'publisher_id', 'event_type',
+ notify('publisher_id', 'event_type',
nova.notifier.api.WARN, dict(a=3))
def test_send_rabbit_notification(self):
self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
- 'nova.notifier.rabbit_notifier.RabbitNotifier')
+ 'nova.notifier.rabbit_notifier')
self.mock_cast = False
def mock_cast(cls, *args):
@@ -83,7 +83,7 @@ class NotifierTestCase(test.TestCase):
pass
self.stubs.Set(nova.rpc, 'cast', mock_cast)
- notify('event_name', 'publisher_id', 'event_type',
+ notify('publisher_id', 'event_type',
nova.notifier.api.WARN, dict(a=3))
self.assertEqual(self.mock_cast, True)
@@ -97,12 +97,12 @@ class NotifierTestCase(test.TestCase):
self.stubs.Set(nova.rpc, 'cast', mock_cast)
self.assertRaises(nova.notifier.api.BadPriorityException,
- notify, 'event_name', 'publisher_id',
+ notify, 'publisher_id',
'event_type', 'not a priority', dict(a=3))
def test_rabbit_priority_queue(self):
self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
- 'nova.notifier.rabbit_notifier.RabbitNotifier')
+ 'nova.notifier.rabbit_notifier')
self.stubs.Set(nova.flags.FLAGS, 'notification_topic',
'testnotify')
@@ -112,6 +112,6 @@ class NotifierTestCase(test.TestCase):
self.test_topic = topic
self.stubs.Set(nova.rpc, 'cast', mock_cast)
- notify('event_name', 'publisher_id',
+ notify('publisher_id',
'event_type', 'DEBUG', dict(a=3))
self.assertEqual(self.test_topic, 'testnotify.debug')