Make notify driver messaging play well with publish_errors

When publish_errors is True, and using `messaging` notify driver,
produces a infinite loop that report sending notification error.

The reason is we always passing None to the content argument in
logger handlers (LoggingNotificationHandler, LoggingErrorNotificationHandler),
when pack the context object which expected as a dict, raise TypeError
exception, so result in infinite retry looping.

To match what document said, passing a empty dict rather than None. Also
modify unittests to make sure context is a empty dict.

Change-Id: Ic2c4c43f5bbafa8107ea370ba959da16cfa4a24c
Closes-bug: #1346466
This commit is contained in:
gtt116 2015-03-24 07:43:34 +00:00
parent ec1fb8c760
commit fb8c431ad6
6 changed files with 29 additions and 19 deletions

View File

@ -35,7 +35,8 @@ class LoggingErrorNotificationHandler(logging.Handler):
# handler sends a notification, and the log_notifier sees the
# notification and logs it.
return
self._notifier.error(None, 'error_notification',
self._notifier.error({},
'error_notification',
dict(error=record.msg))

View File

@ -64,19 +64,21 @@ class LoggingNotificationHandler(logging.Handler):
if not method:
return
method(None,
'logrecord',
{
'name': record.name,
'levelno': record.levelno,
'levelname': record.levelname,
'exc_info': record.exc_info,
'pathname': record.pathname,
'lineno': record.lineno,
'msg': record.getMessage(),
'funcName': record.funcName,
'thread': record.thread,
'processName': record.processName,
'process': record.process,
'extra': getattr(record, 'extra', None),
})
method(
{},
'logrecord',
{
'name': record.name,
'levelno': record.levelno,
'levelname': record.levelname,
'exc_info': record.exc_info,
'pathname': record.pathname,
'lineno': record.lineno,
'msg': record.getMessage(),
'funcName': record.funcName,
'thread': record.thread,
'processName': record.processName,
'process': record.process,
'extra': getattr(record, 'extra', None),
}
)

View File

@ -54,5 +54,6 @@ class PublishErrorsHandlerTestCase(test_utils.BaseTestCase):
self.publisherrorshandler.emit(logrecord)
self.assertEqual('error.publisher',
self.publisherrorshandler._notifier.publisher_id)
mock_notify.assert_called_with(None, 'error_notification',
mock_notify.assert_called_with({},
'error_notification',
{'error': 'Message'}, 'ERROR')

View File

@ -76,6 +76,9 @@ class TestLogNotifier(test_utils.BaseTestCase):
self.logger.emit(record)
context = oslo_messaging.notify._impl_test.NOTIFICATIONS[0][0]
self.assertEqual({}, context)
n = oslo_messaging.notify._impl_test.NOTIFICATIONS[0][1]
self.assertEqual(getattr(self, 'queue', self.priority.upper()),
n['priority'])

View File

@ -54,5 +54,5 @@ class PublishErrorsHandlerTestCase(test_utils.BaseTestCase):
self.publisherrorshandler.emit(logrecord)
self.assertEqual('error.publisher',
self.publisherrorshandler._notifier.publisher_id)
mock_notify.assert_called_with(None, 'error_notification',
mock_notify.assert_called_with({}, 'error_notification',
{'error': 'Message'}, 'ERROR')

View File

@ -77,6 +77,9 @@ class TestLogNotifier(test_utils.BaseTestCase):
self.logger.emit(record)
context = oslo_messaging.notify._impl_test.NOTIFICATIONS[0][0]
self.assertEqual({}, context)
n = oslo_messaging.notify._impl_test.NOTIFICATIONS[0][1]
self.assertEqual(getattr(self, 'queue', self.priority.upper()),
n['priority'])