diff options
author | Davanum Srinivas <davanum@gmail.com> | 2016-02-24 10:08:30 -0800 |
---|---|---|
committer | Davanum Srinivas (dims) <davanum@gmail.com> | 2016-02-25 06:43:00 +0000 |
commit | 2d53db6c51c2ac2ccddda210906c1e6418557470 (patch) | |
tree | fa62c76285b20f942fdc1ed3ce2dc50980a06a4d | |
parent | a17e42d5cf11ac4e176925cc5fb30db5e2034d0c (diff) | |
download | oslo-messaging-2d53db6c51c2ac2ccddda210906c1e6418557470.tar.gz |
Allow Notifier to have multiple topics
Looks like there is a disconnect between the __init__
parameter 'topic' in Notifier and what we need when
we look up a driver. We should allow multiple topics
to be specified as a new topics parameter and pass
that along directly.
Change-Id: Id89957411aa219cff92fafec2f448c81cb57b3ca
-rw-r--r-- | oslo_messaging/notify/notifier.py | 18 | ||||
-rw-r--r-- | oslo_messaging/tests/notify/test_notifier.py | 25 |
2 files changed, 40 insertions, 3 deletions
diff --git a/oslo_messaging/notify/notifier.py b/oslo_messaging/notify/notifier.py index 13650c3..54658c0 100644 --- a/oslo_messaging/notify/notifier.py +++ b/oslo_messaging/notify/notifier.py @@ -19,6 +19,7 @@ import abc import logging import uuid +from debtcollector import renames from oslo_config import cfg from oslo_utils import timeutils import six @@ -142,9 +143,14 @@ class Notifier(object): notifier.info(ctxt, event_type, payload) """ + @renames.renamed_kwarg('topic', 'topics', + message="Please use topics instead of topic", + version='4.5.0', + removal_version='5.0.0') def __init__(self, transport, publisher_id=None, driver=None, topic=None, - serializer=None, retry=None): + serializer=None, retry=None, + topics=None): """Construct a Notifier object. :param transport: the transport to use for sending messages @@ -163,6 +169,8 @@ class Notifier(object): 0 means no retry N means N retries :type retry: int + :param topics: the topics which to send messages on + :type topic: list of strings """ conf = transport.conf conf.register_opts(_notifier_opts, @@ -175,8 +183,12 @@ class Notifier(object): self._driver_names = ([driver] if driver is not None else conf.oslo_messaging_notifications.driver) - self._topics = ([topic] if topic is not None else - conf.oslo_messaging_notifications.topics) + if topics is not None: + self._topics = topics + elif topic is not None: + self._topics = [topic] + else: + self._topics = conf.oslo_messaging_notifications.topics self._serializer = serializer or msg_serializer.NoOpSerializer() self._driver_mgr = named.NamedExtensionManager( diff --git a/oslo_messaging/tests/notify/test_notifier.py b/oslo_messaging/tests/notify/test_notifier.py index 7327466..bf56288 100644 --- a/oslo_messaging/tests/notify/test_notifier.py +++ b/oslo_messaging/tests/notify/test_notifier.py @@ -266,6 +266,31 @@ class TestSerializer(test_utils.BaseTestCase): _impl_test.NOTIFICATIONS) +class TestNotifierTopics(test_utils.BaseTestCase): + + def test_topics_from_config(self): + self.config(driver=['log'], + group='oslo_messaging_notifications') + self.config(topics=['topic1', 'topic2'], + group='oslo_messaging_notifications') + transport = _FakeTransport(self.conf) + + notifier = oslo_messaging.Notifier(transport, 'test.localhost') + self.assertEqual(['topic1', 'topic2'], notifier._topics) + + def test_topics_from_kwargs(self): + self.config(driver=['log'], + group='oslo_messaging_notifications') + transport = _FakeTransport(self.conf) + + notifier = oslo_messaging.Notifier(transport, 'test.localhost', + topic='topic1') + self.assertEqual(['topic1'], notifier._topics) + notifier = oslo_messaging.Notifier(transport, 'test.localhost', + topics=['topic1', 'topic2']) + self.assertEqual(['topic1', 'topic2'], notifier._topics) + + class TestLogNotifier(test_utils.BaseTestCase): @mock.patch('oslo_utils.timeutils.utcnow') |