From 4405e6d412a089732c53b42dbd475824d8b8befc Mon Sep 17 00:00:00 2001 From: Ruby Loo Date: Tue, 31 May 2016 14:26:22 -0400 Subject: [PATCH] NOTIFICATION_TRANSPORT should be global This is a followup to "Use messaging notifications transport instead of default" (Ic72fd658fe9b35d39cc3d7da2e4b9fe3454edfba). The use of NOTIFICATION_TRANSPORT should be global. A unit test is added; it fails if the variable isn't global. A typo was addressed in the release notes. Change-Id: Ie303d79aba893b36a7aecb29c0ff2703f742146e --- ironic/common/rpc.py | 2 +- ironic/tests/unit/common/test_rpc.py | 23 +++++++++++++++++++ ...figure-notifications-72824356e7d8832a.yaml | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ironic/common/rpc.py b/ironic/common/rpc.py index 7c02be69b0..dbf702bb98 100644 --- a/ironic/common/rpc.py +++ b/ironic/common/rpc.py @@ -43,7 +43,7 @@ TRANSPORT_ALIASES = { def init(conf): - global TRANSPORT, NOTIFIER + global TRANSPORT, NOTIFICATION_TRANSPORT, NOTIFIER exmods = get_allowed_exmods() TRANSPORT = messaging.get_transport(conf, allowed_remote_exmods=exmods, diff --git a/ironic/tests/unit/common/test_rpc.py b/ironic/tests/unit/common/test_rpc.py index 6e10aac070..a4a3e17c13 100644 --- a/ironic/tests/unit/common/test_rpc.py +++ b/ironic/tests/unit/common/test_rpc.py @@ -11,11 +11,34 @@ # under the License. import mock +from oslo_config import cfg +import oslo_messaging as messaging from ironic.common import context as ironic_context from ironic.common import rpc from ironic.tests import base +CONF = cfg.CONF + + +class TestUtils(base.TestCase): + + @mock.patch.object(messaging, 'Notifier', autospec=True) + @mock.patch.object(messaging, 'JsonPayloadSerializer', autospec=True) + @mock.patch.object(messaging, 'get_notification_transport', autospec=True) + @mock.patch.object(messaging, 'get_transport', autospec=True) + def test_init_globals(self, mock_get_transport, mock_get_notification, + mock_serializer, mock_notifier): + rpc.TRANSPORT = None + rpc.NOTIFICATION_TRANSPORT = None + rpc.NOTIFIER = None + rpc.init(CONF) + self.assertEqual(mock_get_transport.return_value, rpc.TRANSPORT) + self.assertEqual(mock_get_notification.return_value, + rpc.NOTIFICATION_TRANSPORT) + self.assertTrue(mock_serializer.called) + self.assertEqual(mock_notifier.return_value, rpc.NOTIFIER) + class TestRequestContextSerializer(base.TestCase): diff --git a/releasenotes/notes/configure-notifications-72824356e7d8832a.yaml b/releasenotes/notes/configure-notifications-72824356e7d8832a.yaml index c3ba116469..097ea6c6f6 100644 --- a/releasenotes/notes/configure-notifications-72824356e7d8832a.yaml +++ b/releasenotes/notes/configure-notifications-72824356e7d8832a.yaml @@ -1,6 +1,6 @@ --- features: - - It is now possible to configure the notifications tu use a different + - It is now possible to configure the notifications to use a different transport URL than the RPCs. These could potentially be completely different message broker hosts (though they don't need to be). If the notification-specific configuration is not provided, the notifier will use