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:
@@ -14,14 +14,13 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
|
||||||
flags.DEFINE_string('default_notification_level', 'info',
|
flags.DEFINE_string('default_notification_level', 'INFO',
|
||||||
'Default notification level for outgoing notifications')
|
'Default notification level for outgoing notifications')
|
||||||
|
|
||||||
WARN = 'WARN'
|
WARN = 'WARN'
|
||||||
@@ -69,4 +68,4 @@ def notify(event_name, publisher_id, event_type, priority, payload):
|
|||||||
priority=priority,
|
priority=priority,
|
||||||
payload=payload,
|
payload=payload,
|
||||||
time=str(datetime.datetime.utcnow()))
|
time=str(datetime.datetime.utcnow()))
|
||||||
driver.notify(json.dumps(message))
|
driver.notify(message)
|
||||||
|
|||||||
@@ -14,6 +14,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
class NoopNotifier(object):
|
class NoopNotifier(object):
|
||||||
def notify(self, event_name, model):
|
def notify(self, payload):
|
||||||
"""Notifies the recipient of the desired event given the model"""
|
"""Notifies the recipient of the desired event given the model"""
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
import nova.context
|
import nova.context
|
||||||
|
|
||||||
@@ -28,10 +27,12 @@ flags.DEFINE_string('notification_topic', 'notifications',
|
|||||||
|
|
||||||
class RabbitNotifier(object):
|
class RabbitNotifier(object):
|
||||||
"""Sends notifications to a specific RabbitMQ server and topic"""
|
"""Sends notifications to a specific RabbitMQ server and topic"""
|
||||||
pass
|
|
||||||
|
|
||||||
def notify(self, payload):
|
def notify(self, payload):
|
||||||
"""Sends a notification to the RabbitMQ"""
|
"""Sends a notification to the RabbitMQ"""
|
||||||
context = nova.context.get_admin_context()
|
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)
|
rpc.cast(context, topic, payload)
|
||||||
|
|||||||
@@ -13,13 +13,14 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
import nova
|
import nova
|
||||||
|
|
||||||
|
from nova import context
|
||||||
from nova import flags
|
from nova import flags
|
||||||
|
from nova import rpc
|
||||||
from nova import notifier
|
from nova import notifier
|
||||||
from nova.notifier import no_op_notifier
|
from nova.notifier import no_op_notifier
|
||||||
|
from nova.notifier import rabbit_notifier
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
import stubout
|
import stubout
|
||||||
@@ -51,8 +52,7 @@ class NotifierTestCase(test.TestCase):
|
|||||||
def test_verify_message_format(self):
|
def test_verify_message_format(self):
|
||||||
"""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, blob):
|
def message_assert(cls, message):
|
||||||
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'),
|
||||||
@@ -94,3 +94,20 @@ class NotifierTestCase(test.TestCase):
|
|||||||
self.assertRaises(nova.notifier.BadPriorityException,
|
self.assertRaises(nova.notifier.BadPriorityException,
|
||||||
nova.notifier.notify, 'event_name', 'publisher_id',
|
nova.notifier.notify, 'event_name', 'publisher_id',
|
||||||
'event_type', 'not a priority', dict(a=3))
|
'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')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user