Merge "add ability to publish to multiple topics"

This commit is contained in:
Jenkins 2015-03-18 21:14:14 +00:00 committed by Gerrit Code Review
commit 0c191b397c
2 changed files with 20 additions and 1 deletions

View File

@ -200,8 +200,10 @@ class RPCPublisher(MessagingPublisher):
class NotifierPublisher(MessagingPublisher): class NotifierPublisher(MessagingPublisher):
def __init__(self, parsed_url, topic): def __init__(self, parsed_url, default_topic):
super(NotifierPublisher, self).__init__(parsed_url) super(NotifierPublisher, self).__init__(parsed_url)
options = urlparse.parse_qs(parsed_url.query)
topic = options.get('topic', [default_topic])[-1]
self.notifier = oslo.messaging.Notifier( self.notifier = oslo.messaging.Notifier(
messaging.get_transport(), messaging.get_transport(),
driver=cfg.CONF.publisher_notifier.telemetry_driver, driver=cfg.CONF.publisher_notifier.telemetry_driver,

View File

@ -176,6 +176,23 @@ class RpcOnlyPublisherTest(BasePublisherTestCase):
self.assertEqual(expected, prepare.mock_calls) self.assertEqual(expected, prepare.mock_calls)
class NotifierOnlyPublisherTest(BasePublisherTestCase):
@mock.patch('oslo.messaging.Notifier')
def test_publish_topic_override(self, notifier):
msg_publisher.SampleNotifierPublisher(
netutils.urlsplit('notifier://?topic=custom_topic'))
notifier.assert_called_with(mock.ANY, topic='custom_topic',
driver=mock.ANY, retry=mock.ANY,
publisher_id=mock.ANY)
msg_publisher.EventNotifierPublisher(
netutils.urlsplit('notifier://?topic=custom_event_topic'))
notifier.assert_called_with(mock.ANY, topic='custom_event_topic',
driver=mock.ANY, retry=mock.ANY,
publisher_id=mock.ANY)
class TestPublisher(testscenarios.testcase.WithScenarios, class TestPublisher(testscenarios.testcase.WithScenarios,
BasePublisherTestCase): BasePublisherTestCase):
scenarios = [ scenarios = [