Code cleanup
This commit is contained in:
		@@ -15,6 +15,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import datetime
 | 
					import datetime
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
 | 
					import uuid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from nova import flags
 | 
					from nova import flags
 | 
				
			||||||
from nova import utils
 | 
					from nova import utils
 | 
				
			||||||
@@ -41,6 +42,7 @@ def notify(event_name, publisher_id, event_type, priority, payload):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    Message format is as follows:
 | 
					    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
 | 
					    publisher_id - the source worker_type.host of the message
 | 
				
			||||||
    timestamp - the GMT timestamp the notification was sent at
 | 
					    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)
 | 
				
			||||||
@@ -48,23 +50,25 @@ def notify(event_name, publisher_id, event_type, priority, payload):
 | 
				
			|||||||
               the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
 | 
					               the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
 | 
				
			||||||
    payload - A python dictionary of attributes
 | 
					    payload - A python dictionary of attributes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    The payload will be constructed as a dictionary of the above attributes,
 | 
					    The message body will be constructed as a dictionary of the above
 | 
				
			||||||
    and converted into a JSON dump, which will then be sent via the transport
 | 
					    attributes, and converted into a JSON dump, which will then be sent
 | 
				
			||||||
    mechanism defined by the driver.
 | 
					    via the transport mechanism defined by the driver.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Message example:
 | 
					    Message example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    { 'publisher_id': 'compute.host1',
 | 
					    {'message_id': str(uuid.uuid4()),
 | 
				
			||||||
      'timestamp': '2011-05-09 22:00:14.621831',
 | 
					     'publisher_id': 'compute.host1',
 | 
				
			||||||
      'priority': 'WARN',
 | 
					     'timestamp': datetime.datetime.utcnow(),
 | 
				
			||||||
      'event_type': 'compute.create_instance',
 | 
					     'priority': 'WARN',
 | 
				
			||||||
      'payload': {'instance_id': 12, ... }}
 | 
					     'event_type': 'compute.create_instance',
 | 
				
			||||||
 | 
					     'payload': {'instance_id': 12, ... }}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    if priority not in log_levels:
 | 
					    if priority not in log_levels:
 | 
				
			||||||
        raise BadPriorityException('%s not in valid priorities' % priority)
 | 
					        raise BadPriorityException('%s not in valid priorities' % priority)
 | 
				
			||||||
    driver = utils.import_class(FLAGS.notification_driver)()
 | 
					    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,
 | 
					                   event_type=event_type,
 | 
				
			||||||
                   priority=priority,
 | 
					                   priority=priority,
 | 
				
			||||||
                   payload=payload,
 | 
					                   payload=payload,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,12 +53,13 @@ class NotifierTestCase(test.TestCase):
 | 
				
			|||||||
        annoying""" 
 | 
					        annoying""" 
 | 
				
			||||||
        def message_assert(cls, blob):
 | 
					        def message_assert(cls, blob):
 | 
				
			||||||
            message = json.loads(blob)
 | 
					            message = json.loads(blob)
 | 
				
			||||||
            fields = [ ('publisher_id', 'publisher_id'),
 | 
					            fields = [('publisher_id', 'publisher_id'),
 | 
				
			||||||
                       ('event_type', 'event_type'),
 | 
					                      ('event_type', 'event_type'),
 | 
				
			||||||
                       ('priority', 'WARN'),
 | 
					                      ('priority', 'WARN'),
 | 
				
			||||||
                       ('payload', 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.stubs.Set(nova.notifier.no_op_notifier.NoopNotifier, 'notify',
 | 
					        self.stubs.Set(nova.notifier.no_op_notifier.NoopNotifier, 'notify',
 | 
				
			||||||
                message_assert)
 | 
					                message_assert)
 | 
				
			||||||
@@ -81,9 +82,6 @@ class NotifierTestCase(test.TestCase):
 | 
				
			|||||||
        self.assertEqual(self.mock_cast, True)
 | 
					        self.assertEqual(self.mock_cast, True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_invalid_priority(self):
 | 
					    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):
 | 
					        def mock_cast(cls, *args):
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user