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
This commit is contained in:
parent
a17e42d5cf
commit
2d53db6c51
@ -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(
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user