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')
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.')

View File

@ -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)

View File

@ -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))

View File

@ -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

View File

@ -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)

View File

@ -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')