diff --git a/sahara/main.py b/sahara/main.py index 0014792e..75616d2c 100644 --- a/sahara/main.py +++ b/sahara/main.py @@ -83,7 +83,8 @@ def setup_common(possible_topdir, service_name): # Validate other configurations (that may produce logs) here cinder.validate_config() - messaging.setup() + if service_name != 'all-in-one' or cfg.CONF.enable_notifications: + messaging.setup() if service_name != 'all-in-one': LOG.warn( diff --git a/sahara/tests/unit/utils/notification/test_sender.py b/sahara/tests/unit/utils/notification/test_sender.py index 4cdb8c5a..2873bfe0 100644 --- a/sahara/tests/unit/utils/notification/test_sender.py +++ b/sahara/tests/unit/utils/notification/test_sender.py @@ -52,7 +52,7 @@ class NotificationTest(base.SaharaTestCase): @mock.patch('oslo_messaging.notify.notifier.Notifier.info') def test_update_cluster(self, mock_notify): self.override_config("enable_notifications", True) - messaging.setup("fake://", optional=True) + messaging.setup() self._make_sample() self.assertEqual([self.expected], diff --git a/sahara/tests/unit/utils/test_rpc.py b/sahara/tests/unit/utils/test_rpc.py index 73d933c2..6df883aa 100644 --- a/sahara/tests/unit/utils/test_rpc.py +++ b/sahara/tests/unit/utils/test_rpc.py @@ -33,7 +33,7 @@ class TestMessagingSetup(base.SaharaTestCase): self.override_config('enable_notifications', True) def _install(self): - messaging.setup('fake://', optional=True) + messaging.setup() self.assertNotEqual(None, messaging.TRANSPORT) self.assertNotEqual(None, messaging.NOTIFIER) @@ -58,7 +58,7 @@ class TestMessagingSetup(base.SaharaTestCase): self._install() expected = [ - mock.call(main.CONF, 'fake://', aliases=_ALIASES) + mock.call(main.CONF, aliases=_ALIASES) ] self.assertEqual(expected, mock_transport.call_args_list) @@ -68,11 +68,6 @@ class TestMessagingSetup(base.SaharaTestCase): def test_notifier(self, mock_init): self._install() - serializer = messaging.SERIALIZER - expected = [ - mock.call(messaging.TRANSPORT, serializer=serializer) - ] - - self.assertEqual(expected, mock_init.call_args_list) + self.assertEqual(1, mock_init.call_count) self._remove_install() diff --git a/sahara/utils/rpc.py b/sahara/utils/rpc.py index bce11dc8..054d2ec9 100644 --- a/sahara/utils/rpc.py +++ b/sahara/utils/rpc.py @@ -25,7 +25,6 @@ from sahara.i18n import _LI TRANSPORT = None NOTIFIER = None -SERIALIZER = None CONF = cfg.CONF LOG = logging.getLogger(__name__) @@ -64,9 +63,11 @@ class JsonPayloadSerializer(messaging.NoOpSerializer): class RPCClient(object): def __init__(self, target): + global TRANSPORT + self.__client = messaging.RPCClient( target=target, - transport=messaging.get_transport(cfg.CONF), + transport=TRANSPORT, ) def cast(self, name, **kwargs): @@ -80,9 +81,11 @@ class RPCClient(object): class RPCServer(object): def __init__(self, target): + global TRANSPORT + self.__server = messaging.get_rpc_server( target=target, - transport=messaging.get_transport(cfg.CONF), + transport=TRANSPORT, endpoints=[self], executor='eventlet') @@ -91,29 +94,21 @@ class RPCServer(object): self.__server.wait() -def setup(url=None, optional=False): +def setup(): """Initialise the oslo_messaging layer.""" - global TRANSPORT, NOTIFIER, SERIALIZER + global TRANSPORT, NOTIFIER + + messaging.set_transport_defaults('sahara') + + TRANSPORT = messaging.get_transport(cfg.CONF, aliases=_ALIASES) if not cfg.CONF.enable_notifications: LOG.info(_LI("Notifications disabled")) return LOG.info(_LI("Notifications enabled")) - messaging.set_transport_defaults('sahara') - - SERIALIZER = ContextSerializer(JsonPayloadSerializer()) - - try: - TRANSPORT = messaging.get_transport(cfg.CONF, url, - aliases=_ALIASES) - except messaging.InvalidTransportURL as e: - TRANSPORT = None - if not optional or e.url: - raise - - if TRANSPORT: - NOTIFIER = messaging.Notifier(TRANSPORT, serializer=SERIALIZER) + serializer = ContextSerializer(JsonPayloadSerializer()) + NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer) def get_notifier(publisher_id):