Merge prop changes

This commit is contained in:
Cerberus 2011-05-16 15:16:34 -05:00
parent 72f2f21f98
commit e59a50c5f1
6 changed files with 44 additions and 47 deletions

View File

@ -370,7 +370,7 @@ DEFINE_string('node_availability_zone', 'nova',
'availability zone of this node') 'availability zone of this node')
DEFINE_string('notification_driver', DEFINE_string('notification_driver',
'nova.notifier.no_op_notifier.NoopNotifier', 'nova.notifier.no_op_notifier',
'Default driver for sending notifications') 'Default driver for sending notifications')
DEFINE_list('memcached_servers', None, DEFINE_list('memcached_servers', None,
'Memcached servers or None for in process cache.') 'Memcached servers or None for in process cache.')

View File

@ -37,21 +37,25 @@ class BadPriorityException(Exception):
pass 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 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 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) event_type - the literal type of event (ex. Instance Creation)
priority - patterned after the enumeration of Python logging levels in priority - patterned after the enumeration of Python logging levels in
the set (DEBUG, WARN, INFO, ERROR, CRITICAL) the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
message - A python dictionary of attributes 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 attributes, which will then be sent via the transport mechanism defined
by the driver. by the driver.
@ -62,17 +66,17 @@ def notify(event_name, publisher_id, event_type, priority, message):
'timestamp': datetime.datetime.utcnow(), 'timestamp': datetime.datetime.utcnow(),
'priority': 'WARN', 'priority': 'WARN',
'event_type': 'compute.create_instance', 'event_type': 'compute.create_instance',
'message': {'instance_id': 12, ... }} 'payload': {'instance_id': 12, ... }}
""" """
if priority not in log_levels: if priority not in log_levels:
raise BadPriorityException( raise BadPriorityException(
_('%s not in valid priorities' % priority)) _('%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()), msg = dict(message_id=str(uuid.uuid4()),
publisher_id=publisher_id, publisher_id=publisher_id,
event_type=event_type, event_type=event_type,
priority=priority, priority=priority,
message=message, payload=message,
timestamp=str(datetime.datetime.utcnow())) timestamp=str(datetime.datetime.utcnow()))
driver.notify(msg) driver.notify(msg)

View File

@ -21,11 +21,10 @@ from nova import log as logging
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
class LogNotifier(object): def notify(message):
"""Log notifications using nova's default logging system""" """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', priority = message.get('priority',
FLAGS.default_notification_level) FLAGS.default_notification_level)
priority = priority.lower() priority = priority.lower()

View File

@ -14,9 +14,6 @@
# under the License. # under the License.
class NoopNotifier(object): def notify(message):
"""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""" """Notifies the recipient of the desired event given the model"""
pass pass

View File

@ -25,10 +25,7 @@ flags.DEFINE_string('notification_topic', 'notifications',
'RabbitMQ topic used for Nova notifications') 'RabbitMQ topic used for Nova notifications')
class RabbitNotifier(object): def notify(message):
"""Sends notifications to a specific RabbitMQ server and topic"""
def notify(self, message):
"""Sends a notification to the RabbitMQ""" """Sends a notification to the RabbitMQ"""
context = nova.context.get_admin_context() context = nova.context.get_admin_context()
priority = message.get('priority', priority = message.get('priority',

View File

@ -43,12 +43,12 @@ class NotifierTestCase(test.TestCase):
def mock_notify(cls, *args): def mock_notify(cls, *args):
self.notify_called = True 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) mock_notify)
class Mock(object): class Mock(object):
pass pass
notify('event_name', 'publisher_id', 'event_type', notify('publisher_id', 'event_type',
nova.notifier.api.WARN, dict(a=3)) nova.notifier.api.WARN, dict(a=3))
self.assertEqual(self.notify_called, True) self.assertEqual(self.notify_called, True)
@ -56,24 +56,24 @@ class NotifierTestCase(test.TestCase):
"""A test to ensure changing the message format is prohibitively """A test to ensure changing the message format is prohibitively
annoying""" annoying"""
def message_assert(cls, message): def message_assert(message):
fields = [('publisher_id', 'publisher_id'), fields = [('publisher_id', 'publisher_id'),
('event_type', 'event_type'), ('event_type', 'event_type'),
('priority', 'WARN'), ('priority', 'WARN'),
('message', dict(a=3))] ('payload', dict(a=3))]
for k, v in fields: for k, v in fields:
self.assertEqual(message[k], v) self.assertEqual(message[k], v)
self.assertTrue(len(message['message_id']) > 0) self.assertTrue(len(message['message_id']) > 0)
self.assertTrue(len(message['timestamp']) > 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) message_assert)
notify('event_name', 'publisher_id', 'event_type', notify('publisher_id', 'event_type',
nova.notifier.api.WARN, dict(a=3)) nova.notifier.api.WARN, dict(a=3))
def test_send_rabbit_notification(self): def test_send_rabbit_notification(self):
self.stubs.Set(nova.flags.FLAGS, 'notification_driver', self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
'nova.notifier.rabbit_notifier.RabbitNotifier') 'nova.notifier.rabbit_notifier')
self.mock_cast = False self.mock_cast = False
def mock_cast(cls, *args): def mock_cast(cls, *args):
@ -83,7 +83,7 @@ class NotifierTestCase(test.TestCase):
pass pass
self.stubs.Set(nova.rpc, 'cast', mock_cast) 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)) nova.notifier.api.WARN, dict(a=3))
self.assertEqual(self.mock_cast, True) self.assertEqual(self.mock_cast, True)
@ -97,12 +97,12 @@ class NotifierTestCase(test.TestCase):
self.stubs.Set(nova.rpc, 'cast', mock_cast) self.stubs.Set(nova.rpc, 'cast', mock_cast)
self.assertRaises(nova.notifier.api.BadPriorityException, self.assertRaises(nova.notifier.api.BadPriorityException,
notify, 'event_name', 'publisher_id', notify, 'publisher_id',
'event_type', 'not a priority', dict(a=3)) 'event_type', 'not a priority', dict(a=3))
def test_rabbit_priority_queue(self): def test_rabbit_priority_queue(self):
self.stubs.Set(nova.flags.FLAGS, 'notification_driver', 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', self.stubs.Set(nova.flags.FLAGS, 'notification_topic',
'testnotify') 'testnotify')
@ -112,6 +112,6 @@ class NotifierTestCase(test.TestCase):
self.test_topic = topic self.test_topic = topic
self.stubs.Set(nova.rpc, 'cast', mock_cast) self.stubs.Set(nova.rpc, 'cast', mock_cast)
notify('event_name', 'publisher_id', notify('publisher_id',
'event_type', 'DEBUG', dict(a=3)) 'event_type', 'DEBUG', dict(a=3))
self.assertEqual(self.test_topic, 'testnotify.debug') self.assertEqual(self.test_topic, 'testnotify.debug')