drop topic keyword from Notifier

we marked it for removal >=5.0.0

Change-Id: I4634c082c2383569c4aa8a6d9a8a560de7e3c12f
This commit is contained in:
gord chung 2017-02-14 21:53:25 +00:00 committed by gordon chung
parent 41fa1ac649
commit 94c818dc98
6 changed files with 20 additions and 33 deletions

View File

@ -47,9 +47,9 @@ class LoggingNotificationHandler(logging.Handler):
topic=None, serializer=None):
self.notifier = notifier.Notifier(
notifier.get_notification_transport(self.CONF, url),
publisher_id, driver,
topic,
serializer() if serializer else None)
publisher_id, driver, serializer() if serializer else None,
topics=(topic if isinstance(topic, list) or topic is None
else [topic]))
logging.Handler.__init__(self)
def emit(self, record):

View File

@ -20,7 +20,6 @@ import argparse
import logging
import uuid
from debtcollector import renames
from oslo_config import cfg
from oslo_utils import timeutils
import six
@ -205,7 +204,7 @@ class Notifier(object):
notifier = notifier.Notifier(transport,
'compute.host',
driver='messaging',
topic='notifications')
topics=['notifications'])
Notifier objects are relatively expensive to instantiate (mostly the cost
of loading notification drivers), so it is possible to specialize a given
@ -215,13 +214,8 @@ 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,
driver=None, serializer=None, retry=None,
topics=None):
"""Construct a Notifier object.
@ -232,8 +226,6 @@ class Notifier(object):
:type publisher_id: str
:param driver: a driver to lookup from oslo_messaging.notify.drivers
:type driver: str
:param topic: the topic which to send messages on
:type topic: str
:param serializer: an optional entity serializer
:type serializer: Serializer
:param retry: connection retries configuration (used by the messaging
@ -258,8 +250,6 @@ class Notifier(object):
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()

View File

@ -240,8 +240,8 @@ class NotifyTestCase(utils.SkipIfNoTransportURL):
def test_multiple_topics(self):
listener = self.useFixture(
utils.NotificationFixture(self.conf, self.url, ['a', 'b']))
a = listener.notifier('pub-a', topic='a')
b = listener.notifier('pub-b', topic='b')
a = listener.notifier('pub-a', topics=['a'])
b = listener.notifier('pub-b', topics=['b'])
sent = {
'pub-a': [a, 'test-a', 'payload-a'],
@ -295,8 +295,8 @@ class NotifyTestCase(utils.SkipIfNoTransportURL):
listener_b = self.useFixture(
utils.NotificationFixture(self.conf, self.url, ['2']))
a = listener_a.notifier('pub-1', topic='1')
b = listener_b.notifier('pub-2', topic='2')
a = listener_a.notifier('pub-1', topics=['1'])
b = listener_b.notifier('pub-2', topics=['2'])
a_out = [('test-1-%s' % c, 'payload-1-%s' % c) for c in 'abcdefgh']
for event_type, payload in a_out:

View File

@ -345,7 +345,7 @@ class NotificationFixture(fixtures.Fixture):
targets.append(oslo_messaging.Target(topic=self.name))
transport = self.useFixture(TransportFixture(self.conf, self.url))
self.server = self._get_server(transport, targets)
self._ctrl = self.notifier('internal', topic=self.name)
self._ctrl = self.notifier('internal', topics=[self.name])
self._start()
transport.wait()
@ -369,12 +369,12 @@ class NotificationFixture(fixtures.Fixture):
if self.thread.isAlive():
raise Exception("Server did not shutdown properly")
def notifier(self, publisher, topic=None):
def notifier(self, publisher, topics=None):
transport = self.useFixture(TransportFixture(self.conf, self.url))
n = notifier.Notifier(transport.transport,
publisher,
driver='messaging',
topic=topic or self.topics[0])
topics=topics or self.topics)
transport.wait()
return n

View File

@ -115,9 +115,9 @@ class ListenerSetupMixin(object):
def wait_for_messages(self, expect_messages, tracker_name='__default__'):
self.trackers[tracker_name].wait_for_messages(expect_messages)
def _setup_notifier(self, transport, topic='testtopic',
def _setup_notifier(self, transport, topics=['testtopic'],
publisher_id='testpublisher'):
return oslo_messaging.Notifier(transport, topic=topic,
return oslo_messaging.Notifier(transport, topics=topics,
driver='messaging',
publisher_id=publisher_id)
@ -279,9 +279,9 @@ class TestNotifyListener(test_utils.BaseTestCase, ListenerSetupMixin):
oslo_messaging.Target(topic="topic2")]
listener_thread = self._setup_listener(transport, [endpoint],
targets=targets)
notifier = self._setup_notifier(transport, topic='topic1')
notifier = self._setup_notifier(transport, topics=['topic1'])
notifier.info({'ctxt': '1'}, 'an_event.start1', 'test')
notifier = self._setup_notifier(transport, topic='topic2')
notifier = self._setup_notifier(transport, topics=['topic2'])
notifier.info({'ctxt': '2'}, 'an_event.start2', 'test')
self.wait_for_messages(2)
@ -309,7 +309,7 @@ class TestNotifyListener(test_utils.BaseTestCase, ListenerSetupMixin):
listener_thread = self._setup_listener(transport, [endpoint],
targets=targets)
notifier = self._setup_notifier(transport, topic="topic")
notifier = self._setup_notifier(transport, topics=["topic"])
def mock_notifier_exchange(name):
def side_effect(target, ctxt, message, version, retry):
@ -407,7 +407,7 @@ class TestNotifyListener(test_utils.BaseTestCase, ListenerSetupMixin):
listener2_thread = self._setup_listener(transport, [endpoint2],
targets=targets, pool="pool2")
notifier = self._setup_notifier(transport, topic="topic")
notifier = self._setup_notifier(transport, topics=["topic"])
notifier.info({'ctxt': '0'}, 'an_event.start', 'test message0')
notifier.info({'ctxt': '1'}, 'an_event.start', 'test message1')
@ -450,7 +450,7 @@ class TestNotifyListener(test_utils.BaseTestCase, ListenerSetupMixin):
'an_event.start', 'test message%d' % i,
{'timestamp': mock.ANY, 'message_id': mock.ANY})
notifier = self._setup_notifier(transport, topic="topic")
notifier = self._setup_notifier(transport, topics=["topic"])
mocked_endpoint1_calls = []
for i in range(0, 25):
notifier.info({'ctxt': '%d' % i}, 'an_event.start',

View File

@ -244,7 +244,7 @@ class TestSerializer(test_utils.BaseTestCase):
notifier = oslo_messaging.Notifier(transport,
'test.localhost',
driver='test',
topic='test',
topics=['test'],
serializer=serializer)
message_id = uuid.uuid4()
@ -295,9 +295,6 @@ class TestNotifierTopics(test_utils.BaseTestCase):
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)