Publish errors via nova.notifier
This commit is contained in:
@@ -35,6 +35,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import nova
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import version
|
from nova import version
|
||||||
|
|
||||||
@@ -63,6 +64,7 @@ flags.DEFINE_list('default_log_levels',
|
|||||||
'eventlet.wsgi.server=WARN'],
|
'eventlet.wsgi.server=WARN'],
|
||||||
'list of logger=LEVEL pairs')
|
'list of logger=LEVEL pairs')
|
||||||
flags.DEFINE_bool('use_syslog', False, 'output to syslog')
|
flags.DEFINE_bool('use_syslog', False, 'output to syslog')
|
||||||
|
flags.DEFINE_bool('publish_errors', True, 'publish error events')
|
||||||
flags.DEFINE_string('logfile', None, 'output to named file')
|
flags.DEFINE_string('logfile', None, 'output to named file')
|
||||||
|
|
||||||
|
|
||||||
@@ -258,12 +260,19 @@ class NovaRootLogger(NovaLogger):
|
|||||||
else:
|
else:
|
||||||
self.removeHandler(self.filelog)
|
self.removeHandler(self.filelog)
|
||||||
self.addHandler(self.streamlog)
|
self.addHandler(self.streamlog)
|
||||||
|
if FLAGS.publish_errors:
|
||||||
|
self.addHandler(PublishErrorsHandler(ERROR))
|
||||||
if FLAGS.verbose:
|
if FLAGS.verbose:
|
||||||
self.setLevel(DEBUG)
|
self.setLevel(DEBUG)
|
||||||
else:
|
else:
|
||||||
self.setLevel(INFO)
|
self.setLevel(INFO)
|
||||||
|
|
||||||
|
|
||||||
|
class PublishErrorsHandler(logging.Handler):
|
||||||
|
def emit(self, record):
|
||||||
|
nova.notifier.notify('error', record)
|
||||||
|
|
||||||
|
|
||||||
def handle_exception(type, value, tb):
|
def handle_exception(type, value, tb):
|
||||||
extra = {}
|
extra = {}
|
||||||
if FLAGS.verbose:
|
if FLAGS.verbose:
|
||||||
|
@@ -13,14 +13,18 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import nova
|
import json
|
||||||
|
|
||||||
|
import stubout
|
||||||
|
|
||||||
|
import nova
|
||||||
|
from nova import log as logging
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import notifier
|
from nova import notifier
|
||||||
from nova.notifier import no_op_notifier
|
from nova.notifier import no_op_notifier
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
import stubout
|
LOG = logging.getLogger('nova.compute.api')
|
||||||
|
|
||||||
class NotifierTestCase(test.TestCase):
|
class NotifierTestCase(test.TestCase):
|
||||||
"""Test case for notifications"""
|
"""Test case for notifications"""
|
||||||
@@ -58,3 +62,16 @@ class NotifierTestCase(test.TestCase):
|
|||||||
notifier.notify('derp', Mock())
|
notifier.notify('derp', Mock())
|
||||||
|
|
||||||
self.assertEqual(self.mock_cast, True)
|
self.assertEqual(self.mock_cast, True)
|
||||||
|
|
||||||
|
def test_error_notification(self):
|
||||||
|
self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
|
||||||
|
'nova.notifier.rabbit_notifier.RabbitNotifier')
|
||||||
|
msgs = []
|
||||||
|
def mock_cast(context, topic, msg):
|
||||||
|
data = json.loads(msg)
|
||||||
|
msgs.append(data)
|
||||||
|
self.stubs.Set(nova.rpc, 'cast', mock_cast)
|
||||||
|
LOG.error('foo');
|
||||||
|
msg = msgs[0]
|
||||||
|
self.assertEqual(msg['event_name'], 'error')
|
||||||
|
self.assertEqual(msg['model']['msg'], 'foo')
|
||||||
|
Reference in New Issue
Block a user