Pep8 stuff

This commit is contained in:
Cerberus
2011-05-11 13:22:55 -05:00
parent 77d2b9af78
commit 0952d59a4f
5 changed files with 19 additions and 9 deletions

View File

@@ -32,9 +32,11 @@ DEBUG = 'DEBUG'
log_levels = (DEBUG, WARN, INFO, ERROR, CRITICAL)
class BadPriorityException(Exception):
pass
def notify(event_name, publisher_id, event_type, priority, payload):
"""
Sends a notification using the specified driver

View File

@@ -20,6 +20,7 @@ from nova import log as logging
FLAGS = flags.FLAGS
class LogNotifier(object):
""" log notifications using nova's default logging system """
@@ -28,6 +29,6 @@ class LogNotifier(object):
priority = payload.get('priority',
FLAGS.default_notification_level)
priority = priority.lower()
logger = logging.getLogger('nova.notification.%s' % payload['event_type'])
logger = logging.getLogger(
'nova.notification.%s' % payload['event_type'])
getattr(logger, priority)(json.dumps(payload))

View File

@@ -13,7 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
class NoopNotifier(object):
"""A notifier that doesn't actually do anything. Simply a placeholder"""
def notify(self, payload):
"""Notifies the recipient of the desired event given the model"""
pass

View File

@@ -21,7 +21,7 @@ from nova import rpc
FLAGS = flags.FLAGS
flags.DEFINE_string('notification_topic', 'notifications',
flags.DEFINE_string('notification_topic', 'notifications',
'RabbitMQ topic used for Nova notifications')

View File

@@ -26,6 +26,7 @@ from nova import test
import stubout
class NotifierTestCase(test.TestCase):
"""Test case for notifications"""
def setUp(self):
@@ -38,6 +39,7 @@ class NotifierTestCase(test.TestCase):
def test_send_notification(self):
self.notify_called = False
def mock_notify(cls, *args):
self.notify_called = True
@@ -52,7 +54,8 @@ class NotifierTestCase(test.TestCase):
def test_verify_message_format(self):
"""A test to ensure changing the message format is prohibitively
annoying"""
annoying"""
def message_assert(cls, message):
fields = [('publisher_id', 'publisher_id'),
('event_type', 'event_type'),
@@ -72,12 +75,14 @@ class NotifierTestCase(test.TestCase):
self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
'nova.notifier.rabbit_notifier.RabbitNotifier')
self.mock_cast = False
def mock_cast(cls, *args):
self.mock_cast = True
class Mock(object):
pass
self.stubs.Set(nova.rpc, 'cast', mock_cast)
self.stubs.Set(nova.rpc, 'cast', mock_cast)
notify('event_name', 'publisher_id', 'event_type',
nova.notifier.api.WARN, dict(a=3))
@@ -90,8 +95,8 @@ class NotifierTestCase(test.TestCase):
class Mock(object):
pass
self.stubs.Set(nova.rpc, 'cast', mock_cast)
self.assertRaises(nova.notifier.api.BadPriorityException,
self.stubs.Set(nova.rpc, 'cast', mock_cast)
self.assertRaises(nova.notifier.api.BadPriorityException,
notify, 'event_name', 'publisher_id',
'event_type', 'not a priority', dict(a=3))
@@ -106,8 +111,7 @@ class NotifierTestCase(test.TestCase):
def mock_cast(context, topic, msg):
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',
'event_type', 'DEBUG', dict(a=3))
self.assertEqual(self.test_topic, 'testnotify.debug')