diff --git a/oslo_messaging/notify/notifier.py b/oslo_messaging/notify/notifier.py index caf04aba4..8af1142f9 100644 --- a/oslo_messaging/notify/notifier.py +++ b/oslo_messaging/notify/notifier.py @@ -54,6 +54,10 @@ _notifier_opts = [ group='DEFAULT') ], help='AMQP topic used for OpenStack notifications.'), + cfg.IntOpt('retry', default=-1, + help='The maximum number of attempts to re-send a notification ' + 'message which failed to be delivered due to a ' + 'recoverable error. 0 - No retry, -1 - indefinite'), ] _LOG = logging.getLogger(__name__) @@ -243,7 +247,10 @@ class Notifier(object): self.transport = transport self.publisher_id = publisher_id - self.retry = retry + if retry is not None: + self.retry = retry + else: + self.retry = conf.oslo_messaging_notifications.retry self._driver_names = ([driver] if driver is not None else conf.oslo_messaging_notifications.driver) diff --git a/oslo_messaging/tests/notify/test_notifier.py b/oslo_messaging/tests/notify/test_notifier.py index b6ee8ff8a..6bd3f7ec8 100755 --- a/oslo_messaging/tests/notify/test_notifier.py +++ b/oslo_messaging/tests/notify/test_notifier.py @@ -214,7 +214,7 @@ class TestMessagingNotifier(test_utils.BaseTestCase): if hasattr(self, 'retry'): send_kwargs['retry'] = self.retry else: - send_kwargs['retry'] = None + send_kwargs['retry'] = -1 target = oslo_messaging.Target(topic='%s.%s' % (topic, self.priority)) calls.append(mock.call(target, @@ -273,7 +273,7 @@ class TestSerializer(test_utils.BaseTestCase): 'timestamp': str(timeutils.utcnow()), } - self.assertEqual([(dict(user='alice'), message, 'INFO', None)], + self.assertEqual([(dict(user='alice'), message, 'INFO', -1)], _impl_test.NOTIFICATIONS) uuid.uuid4.assert_called_once_with() @@ -375,6 +375,31 @@ class TestLogNotifier(test_utils.BaseTestCase): logger.info.assert_called_once_with(mask_str) +class TestNotificationConfig(test_utils.BaseTestCase): + + def test_retry_config(self): + conf = self.messaging_conf.conf + self.config(driver=['messaging'], + group='oslo_messaging_notifications') + + conf.set_override('retry', 3, group='oslo_messaging_notifications') + transport = _FakeTransport(conf) + notifier = oslo_messaging.Notifier(transport) + + self.assertEqual(3, notifier.retry) + + def test_notifier_retry_config(self): + conf = self.messaging_conf.conf + self.config(driver=['messaging'], + group='oslo_messaging_notifications') + + conf.set_override('retry', 3, group='oslo_messaging_notifications') + transport = _FakeTransport(conf) + notifier = oslo_messaging.Notifier(transport, retry=5) + + self.assertEqual(5, notifier.retry) + + class TestRoutingNotifier(test_utils.BaseTestCase): def setUp(self): super(TestRoutingNotifier, self).setUp() @@ -603,9 +628,9 @@ group_1: self.notifier.info({}, 'my_event', {}) self.assertFalse(bar_driver.info.called) rpc_driver.notify.assert_called_once_with( - {}, mock.ANY, 'INFO', None) + {}, mock.ANY, 'INFO', -1) rpc2_driver.notify.assert_called_once_with( - {}, mock.ANY, 'INFO', None) + {}, mock.ANY, 'INFO', -1) class TestNoOpNotifier(test_utils.BaseTestCase): diff --git a/releasenotes/notes/retry-support-07996ef04dda9482.yaml b/releasenotes/notes/retry-support-07996ef04dda9482.yaml new file mode 100644 index 000000000..2b5fad7b7 --- /dev/null +++ b/releasenotes/notes/retry-support-07996ef04dda9482.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + | Retry support for oslo_messaging_notifications driver + | Configuration param 'retry' is added. Default is -1, indefinite + + * *retry* (default=-1) +