moved to wrap_exception decorator

This commit is contained in:
Sandy Walsh
2011-06-28 21:04:50 -07:00
parent 4f625513ac
commit 898f4c46f8
3 changed files with 7 additions and 35 deletions

View File

@@ -81,11 +81,17 @@ def wrap_db_error(f):
_wrap.func_name = f.func_name _wrap.func_name = f.func_name
def wrap_exception(f): def wrap_exception(f, notifier=None, publisher_id=None, level=None):
def _wrap(*args, **kw): def _wrap(*args, **kw):
try: try:
return f(*args, **kw) return f(*args, **kw)
except Exception, e: except Exception, e:
if notifier != None and 'safe_notify' in notifier.dir():
event_type = f.__name__
payload = dict(args=args, exception=e)
payload.update(kw)
notifier.safe_notify(publisher_id, event_type, level, payload)
if not isinstance(e, Error): if not isinstance(e, Error):
#exc_type, exc_value, exc_traceback = sys.exc_info() #exc_type, exc_value, exc_traceback = sys.exc_info()
LOG.exception(_('Uncaught exception')) LOG.exception(_('Uncaught exception'))

View File

@@ -43,11 +43,6 @@ def publisher_id(service, host=None):
return "%s.%s" % (service, host) return "%s.%s" % (service, host)
def msgkeys(event_type, instance_id, level, publisher_id):
return dict(event_type=event_type, instance_id=instance_id,
notification_level=level, publisher_id=publisher_id)
def safe_notify(publisher_id, event_type, priority, payload): def safe_notify(publisher_id, event_type, priority, payload):
try: try:
notify(publisher_id, event_type, notification_level, payload) notify(publisher_id, event_type, notification_level, payload)
@@ -55,27 +50,6 @@ def safe_notify(publisher_id, event_type, priority, payload):
LOG.exception(_("Problem '%(e)' attempting to " LOG.exception(_("Problem '%(e)' attempting to "
"send to notification system." % locals())) "send to notification system." % locals()))
def instance_safe_notify(publisher_id, event_type, priority, instance_id,
extra_payload=None):
payload = dict(instance_id = instance_id)
if extra_payload:
payload.extend(extra_payload)
safe_notify(publisher_id, event_type, priority, payload)
def exception_to_notification(self, ex):
required = ['instance_id', 'publisher_id', 'notification_level',
'event_type']
for key in required:
if not (hasattr(ex, key) and ex.key):
return # Doesn't have everything we need. Skip it.
instance_id = ex.instance_id
publisher_id = ex.publisher_id
notification_level = ex.notification_level
event_type = ex.event_type
instance_safe_notify(publisher_id, event_type, priority, instance_id)
def notify(publisher_id, event_type, priority, payload): def notify(publisher_id, event_type, priority, payload):
""" """
Sends a notification using the specified driver Sends a notification using the specified driver

View File

@@ -44,7 +44,6 @@ from nova import fakerabbit
from nova import flags from nova import flags
from nova import log as logging from nova import log as logging
from nova import utils from nova import utils
from nova.notifier import api as notifier
LOG = logging.getLogger('nova.rpc') LOG = logging.getLogger('nova.rpc')
@@ -313,7 +312,6 @@ class ConsumerSet(object):
if not it: if not it:
break break
while True: while True:
ex = None
try: try:
it.next() it.next()
except StopIteration: except StopIteration:
@@ -321,13 +319,7 @@ class ConsumerSet(object):
except greenlet.GreenletExit: except greenlet.GreenletExit:
running = False running = False
break break
except exception.NovaException, e:
ex = e
notifier.exception_to_notification(e)
except Exception as e: except Exception as e:
ex = e
if ex:
LOG.exception(_("Exception while processing consumer")) LOG.exception(_("Exception while processing consumer"))
self.reconnect() self.reconnect()
# Break to outer loop # Break to outer loop