diff options
author | Russell Bryant <rbryant@redhat.com> | 2012-12-13 12:53:43 -0500 |
---|---|---|
committer | Russell Bryant <rbryant@redhat.com> | 2013-01-03 14:02:09 -0500 |
commit | adffcd58fb09dafb0c4e128797b4a61a59087f9a (patch) | |
tree | afcbabee9561afb0fbc56ef2dafe6288c107ca01 /tests/unit/rpc/common.py | |
parent | fdc74c07d63ff897f42405b6dde0ffa46d6e26c3 (diff) | |
download | oslo-adffcd58fb09dafb0c4e128797b4a61a59087f9a.tar.gz oslo-adffcd58fb09dafb0c4e128797b4a61a59087f9a.tar.xz oslo-adffcd58fb09dafb0c4e128797b4a61a59087f9a.zip |
Optionally add message envelope to notifications.
When message envelopes were added for rpc messages, notifications were
explicitly left out. This was due to the fact that notifications are
consumed outside of OpenStack. However, notification consumers will
likely want to eventually start taking advantage of some of the features
that the envelope is a prerequisite for, such as message signing.
This patch adds a new notification driver that produces message based
notifications including the message envelope.
Related to blueprint version-rpc-messages.
Change-Id: Iaa8b437e6b4f64053f4b02bf486516f60bb020e9
Diffstat (limited to 'tests/unit/rpc/common.py')
-rw-r--r-- | tests/unit/rpc/common.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/unit/rpc/common.py b/tests/unit/rpc/common.py index 70a1ad0..9838c6f 100644 --- a/tests/unit/rpc/common.py +++ b/tests/unit/rpc/common.py @@ -29,6 +29,7 @@ import nose from openstack.common import cfg from openstack.common import exception from openstack.common.gettextutils import _ +from openstack.common import jsonutils from openstack.common.rpc import amqp as rpc_amqp from openstack.common.rpc import common as rpc_common from openstack.common.rpc import dispatcher as rpc_dispatcher @@ -276,6 +277,41 @@ class BaseRpcAMQPTestCase(BaseRpcTestCase): "args": {"value": value}}) self.assertEqual(value, result) + def test_notification_envelope(self): + raw_msg = {'a': 'b'} + self.test_msg = None + + def fake_notify_send(_conn, topic, msg): + self.test_msg = msg + + self.stubs.Set(self.rpc.Connection, 'notify_send', fake_notify_send) + + self.rpc.notify(FLAGS, self.context, 'notifications.info', raw_msg, + envelope=False) + self.assertEqual(self.test_msg, raw_msg) + + # Envelopes enabled, but not enabled for notifications + self.stubs.Set(rpc_common, '_SEND_RPC_ENVELOPE', True) + self.rpc.notify(FLAGS, self.context, 'notifications.info', raw_msg, + envelope=False) + self.assertEqual(self.test_msg, raw_msg) + + # Now turn it on for notifications + msg = { + 'oslo.version': rpc_common._RPC_ENVELOPE_VERSION, + 'oslo.message': jsonutils.dumps(raw_msg), + } + self.rpc.notify(FLAGS, self.context, 'notifications.info', raw_msg, + envelope=True) + self.assertEqual(self.test_msg, msg) + + # Make sure envelopes are still on notifications, even if turned off + # for general messages. + self.stubs.Set(rpc_common, '_SEND_RPC_ENVELOPE', False) + self.rpc.notify(FLAGS, self.context, 'notifications.info', raw_msg, + envelope=True) + self.assertEqual(self.test_msg, msg) + class TestReceiver(object): """Simple Proxy class so the consumer has methods to call. |