Merge "Prevent infinite loop in PublishErrorsHandler"

This commit is contained in:
Jenkins
2012-02-23 19:49:08 +00:00
committed by Gerrit Code Review
2 changed files with 41 additions and 0 deletions

View File

@@ -262,6 +262,9 @@ class LegacyNovaFormatter(logging.Formatter):
class PublishErrorsHandler(logging.Handler):
def emit(self, record):
if 'list_notifier_drivers' in FLAGS:
if 'nova.notifier.log_notifier' in FLAGS.list_notifier_drivers:
return
nova.notifier.api.notify('nova.error.publisher', 'error_notification',
nova.notifier.api.ERROR, dict(error=record.msg))

View File

@@ -1,13 +1,17 @@
import cStringIO
import json
import logging
import sys
from nova import context
from nova import flags
from nova import log
from nova.notifier import api as notifier
from nova import test
FLAGS = flags.FLAGS
flags.DECLARE('list_notifier_drivers',
'nova.notifier.list_notifier')
def _fake_context():
@@ -74,6 +78,40 @@ class LogHandlerTestCase(test.TestCase):
'/some/path/foo-bar.log')
class PublishErrorsHandlerTestCase(test.TestCase):
"""Tests for nova.log.PublishErrorsHandler"""
def setUp(self):
super(PublishErrorsHandlerTestCase, self).setUp()
self.handler = logging.Handler()
self.publiserrorshandler = log.PublishErrorsHandler(logging.ERROR)
def test_emit_cfg_list_notifier_drivers_in_flags(self):
self.stub_flg = False
def fake_notifier(*args, **kwargs):
self.stub_flg = True
self.stubs.Set(notifier, 'notify', fake_notifier)
logrecord = logging.LogRecord('name', 'WARN', '/tmp', 1,
'Message', None, None)
self.publiserrorshandler.emit(logrecord)
self.assertTrue(self.stub_flg)
def test_emit_cfg_log_notifier_in_list_notifier_drivers(self):
self.flags(list_notifier_drivers=['nova.notifier.rabbit_notifier',
'nova.notifier.log_notifier'])
self.stub_flg = True
def fake_notifier(*args, **kwargs):
self.stub_flg = False
self.stubs.Set(notifier, 'notify', fake_notifier)
logrecord = logging.LogRecord('name', 'WARN', '/tmp', 1,
'Message', None, None)
self.publiserrorshandler.emit(logrecord)
self.assertTrue(self.stub_flg)
class NovaFormatterTestCase(test.TestCase):
def setUp(self):
super(NovaFormatterTestCase, self).setUp()