Add priority based queues to notifications.

Remove duplicate json encoding in notifier (rpc.cast does encoding... ) 
make no_op_notifier  match rabbit one for signature on notify()
This commit is contained in:
Monsyne Dragon
2011-05-10 23:29:16 +00:00
parent ab016fa19b
commit de784972a1
4 changed files with 30 additions and 13 deletions

View File

@@ -14,14 +14,13 @@
# under the License.
import datetime
import json
from nova import flags
from nova import utils
FLAGS = flags.FLAGS
flags.DEFINE_string('default_notification_level', 'info',
flags.DEFINE_string('default_notification_level', 'INFO',
'Default notification level for outgoing notifications')
WARN = 'WARN'
@@ -69,4 +68,4 @@ def notify(event_name, publisher_id, event_type, priority, payload):
priority=priority,
payload=payload,
time=str(datetime.datetime.utcnow()))
driver.notify(json.dumps(message))
driver.notify(message)

View File

@@ -14,6 +14,6 @@
# under the License.
class NoopNotifier(object):
def notify(self, event_name, model):
def notify(self, payload):
"""Notifies the recipient of the desired event given the model"""
pass

View File

@@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import nova.context
@@ -28,10 +27,12 @@ flags.DEFINE_string('notification_topic', 'notifications',
class RabbitNotifier(object):
"""Sends notifications to a specific RabbitMQ server and topic"""
pass
def notify(self, payload):
"""Sends a notification to the RabbitMQ"""
context = nova.context.get_admin_context()
topic = FLAGS.notification_topic
priority = payload.get('priority',
FLAGS.default_notification_level)
priority = priority.lower()
topic = '%s.%s' % (FLAGS.notification_topic, priority)
rpc.cast(context, topic, payload)

View File

@@ -13,13 +13,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import nova
from nova import context
from nova import flags
from nova import rpc
from nova import notifier
from nova.notifier import no_op_notifier
from nova.notifier import rabbit_notifier
from nova import test
import stubout
@@ -51,8 +52,7 @@ class NotifierTestCase(test.TestCase):
def test_verify_message_format(self):
"""A test to ensure changing the message format is prohibitively
annoying"""
def message_assert(cls, blob):
message = json.loads(blob)
def message_assert(cls, message):
fields = [ ('publisher_id', 'publisher_id'),
('event_type', 'event_type'),
('priority', 'WARN'),
@@ -71,7 +71,7 @@ class NotifierTestCase(test.TestCase):
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)
@@ -86,7 +86,7 @@ class NotifierTestCase(test.TestCase):
self.mock_cast = False
def mock_cast(cls, *args):
pass
class Mock(object):
pass
@@ -94,3 +94,20 @@ class NotifierTestCase(test.TestCase):
self.assertRaises(nova.notifier.BadPriorityException,
nova.notifier.notify, 'event_name', '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')
self.stubs.Set(nova.flags.FLAGS, 'notification_topic',
'testnotify')
self.test_topic = None
def mock_cast(context, topic, msg):
self.test_topic = topic
self.stubs.Set(nova.rpc, 'cast', mock_cast)
nova.notifier.notify('event_name', 'publisher_id',
'event_type', 'DEBUG', dict(a=3))
self.assertEqual(self.test_topic, 'testnotify.debug')