Make versioned notifications topics configurable

Some services (such as telemetry) actually consume the notifications. So
if one deploys a service that listens on the same queue as telemetry,
there will be race-conditions with these services and one will not get
the notifications that are expected at points.

To address this, one sets a different topic and consumes from there.
This is not possible with versioned notifications at the moment. And, as
services move to using that, the same need will arise.

So, this adds a configuration option to nova for enabling the
configuration of topics for this notifier.

Change-Id: I817ce4bae0dd37e0d06bd44f21ba81b3cb800548
This commit is contained in:
Juan Antonio Osorio Robles 2017-03-13 17:25:07 +02:00
parent 3027d779cb
commit 5bc5e8440e
5 changed files with 47 additions and 7 deletions

View File

@ -99,6 +99,21 @@ Possible values:
* both: Both the legacy unversioned and the new versioned notifications are
emitted. (Default)
The list of versioned notifications is visible in
http://docs.openstack.org/developer/nova/notifications.html
"""),
cfg.ListOpt(
'versioned_notifications_topics',
default=['versioned_notifications'],
help="""
Specifies the topics for the versioned notifications issued by nova.
The default value is fine for most deployments and rarely needs to be changed.
However, if you have a third-party service that consumes versioned
notifications, it might be worth getting a topic for that service.
Nova will send a message containing a versioned notification payload to each
topic queue in this list.
The list of versioned notifications is visible in
http://docs.openstack.org/developer/nova/notifications.html
"""),

View File

@ -85,16 +85,18 @@ def init(conf):
elif conf.notifications.notification_format == 'both':
LEGACY_NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer)
NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer,
topics=['versioned_notifications'])
NOTIFIER = messaging.Notifier(
NOTIFICATION_TRANSPORT,
serializer=serializer,
topics=conf.notifications.versioned_notifications_topics)
else:
LEGACY_NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer,
driver='noop')
NOTIFIER = messaging.Notifier(NOTIFICATION_TRANSPORT,
serializer=serializer,
topics=['versioned_notifications'])
NOTIFIER = messaging.Notifier(
NOTIFICATION_TRANSPORT,
serializer=serializer,
topics=conf.notifications.versioned_notifications_topics)
def cleanup():

View File

@ -29,6 +29,8 @@ class TestNotifier(test.NoDBTestCase):
mock_noti_trans,
mock_transport):
conf = mock.Mock()
conf.notifications.versioned_notifications_topics = [
'versioned_notifications']
cases = {
'unversioned': [

View File

@ -85,6 +85,20 @@ class TestRPC(testtools.TestCase):
self._test_init(mock_notif, mock_noti_trans, mock_ser,
mock_exmods, 'versioned', expected)
@mock.patch.object(rpc, 'get_allowed_exmods')
@mock.patch.object(rpc, 'RequestContextSerializer')
@mock.patch.object(messaging, 'get_notification_transport')
@mock.patch.object(messaging, 'Notifier')
def test_init_versioned_with_custom_topics(self, mock_notif,
mock_noti_trans, mock_ser,
mock_exmods):
expected = [{'driver': 'noop'},
{'topics': ['custom_topic1', 'custom_topic2']}]
self._test_init(
mock_notif, mock_noti_trans, mock_ser, mock_exmods, 'versioned',
expected, versioned_notification_topics=['custom_topic1',
'custom_topic2'])
def test_cleanup_transport_null(self):
rpc.NOTIFICATION_TRANSPORT = mock.Mock()
rpc.LEGACY_NOTIFIER = mock.Mock()
@ -304,7 +318,8 @@ class TestRPC(testtools.TestCase):
aliases=rpc.TRANSPORT_ALIASES)
def _test_init(self, mock_notif, mock_noti_trans, mock_ser,
mock_exmods, notif_format, expected_driver_topic_kwargs):
mock_exmods, notif_format, expected_driver_topic_kwargs,
versioned_notification_topics=['versioned_notifications']):
legacy_notifier = mock.Mock()
notifier = mock.Mock()
notif_transport = mock.Mock()
@ -314,6 +329,8 @@ class TestRPC(testtools.TestCase):
conf.transport_url = None
conf.notifications.notification_format = notif_format
conf.notifications.versioned_notifications_topics = (
versioned_notification_topics)
mock_exmods.return_value = ['foo']
mock_noti_trans.return_value = notif_transport
mock_ser.return_value = serializer

View File

@ -0,0 +1,4 @@
---
features:
- The versioned_notifications_topic configuration option; This enables one to
configure the topics used for versioned notifications.