This adds the ability to publish nova errors to an error queue.
This commit is contained in:
		
							
								
								
									
										10
									
								
								nova/log.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								nova/log.py
									
									
									
									
									
								
							@@ -35,6 +35,7 @@ import os
 | 
			
		||||
import sys
 | 
			
		||||
import traceback
 | 
			
		||||
 | 
			
		||||
import nova
 | 
			
		||||
from nova import flags
 | 
			
		||||
from nova import version
 | 
			
		||||
 | 
			
		||||
@@ -63,6 +64,7 @@ flags.DEFINE_list('default_log_levels',
 | 
			
		||||
                   'eventlet.wsgi.server=WARN'],
 | 
			
		||||
                  'list of logger=LEVEL pairs')
 | 
			
		||||
flags.DEFINE_bool('use_syslog', False, 'output to syslog')
 | 
			
		||||
flags.DEFINE_bool('publish_errors', False, 'publish error events')
 | 
			
		||||
flags.DEFINE_string('logfile', None, 'output to named file')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -258,12 +260,20 @@ class NovaRootLogger(NovaLogger):
 | 
			
		||||
        else:
 | 
			
		||||
            self.removeHandler(self.filelog)
 | 
			
		||||
            self.addHandler(self.streamlog)
 | 
			
		||||
        if FLAGS.publish_errors:
 | 
			
		||||
            self.addHandler(PublishErrorsHandler(ERROR))
 | 
			
		||||
        if FLAGS.verbose:
 | 
			
		||||
            self.setLevel(DEBUG)
 | 
			
		||||
        else:
 | 
			
		||||
            self.setLevel(INFO)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PublishErrorsHandler(logging.Handler):
 | 
			
		||||
    def emit(self, record):
 | 
			
		||||
        nova.notifier.api.notify('nova.error.publisher', 'error_notification',
 | 
			
		||||
            nova.notifier.api.ERROR, dict(error=record.msg))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def handle_exception(type, value, tb):
 | 
			
		||||
    extra = {}
 | 
			
		||||
    if FLAGS.verbose:
 | 
			
		||||
 
 | 
			
		||||
@@ -13,10 +13,12 @@
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
 | 
			
		||||
import nova
 | 
			
		||||
import stubout
 | 
			
		||||
 | 
			
		||||
import nova
 | 
			
		||||
from nova import context
 | 
			
		||||
from nova import flags
 | 
			
		||||
from nova import log
 | 
			
		||||
from nova import rpc
 | 
			
		||||
import nova.notifier.api
 | 
			
		||||
from nova.notifier.api import notify
 | 
			
		||||
@@ -24,8 +26,6 @@ from nova.notifier import no_op_notifier
 | 
			
		||||
from nova.notifier import rabbit_notifier
 | 
			
		||||
from nova import test
 | 
			
		||||
 | 
			
		||||
import stubout
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class NotifierTestCase(test.TestCase):
 | 
			
		||||
    """Test case for notifications"""
 | 
			
		||||
@@ -115,3 +115,22 @@ class NotifierTestCase(test.TestCase):
 | 
			
		||||
        notify('publisher_id',
 | 
			
		||||
                'event_type', 'DEBUG', dict(a=3))
 | 
			
		||||
        self.assertEqual(self.test_topic, 'testnotify.debug')
 | 
			
		||||
 | 
			
		||||
    def test_error_notification(self):
 | 
			
		||||
        self.stubs.Set(nova.flags.FLAGS, 'notification_driver',
 | 
			
		||||
            'nova.notifier.rabbit_notifier')
 | 
			
		||||
        self.stubs.Set(nova.flags.FLAGS, 'publish_errors', True)
 | 
			
		||||
        LOG = log.getLogger('nova')
 | 
			
		||||
        LOG.setup_from_flags()
 | 
			
		||||
        msgs = []
 | 
			
		||||
 | 
			
		||||
        def mock_cast(context, topic, data):
 | 
			
		||||
            msgs.append(data)
 | 
			
		||||
 | 
			
		||||
        self.stubs.Set(nova.rpc, 'cast', mock_cast)
 | 
			
		||||
        LOG.error('foo')
 | 
			
		||||
        self.assertEqual(1, len(msgs))
 | 
			
		||||
        msg = msgs[0]
 | 
			
		||||
        self.assertEqual(msg['event_type'], 'error_notification')
 | 
			
		||||
        self.assertEqual(msg['priority'], 'ERROR')
 | 
			
		||||
        self.assertEqual(msg['payload']['error'], 'foo')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user