summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-06-28 21:04:50 -0700
committerSandy Walsh <sandy.walsh@rackspace.com>2011-06-28 21:04:50 -0700
commita0f968235332e5400d507bbafa99bc0728aa8479 (patch)
treeef67f6404ed19906d0129adb73de220e45e3661c
parent4c98425ba7a53c8b966317444abe2d4f7b6556d8 (diff)
downloadnova-a0f968235332e5400d507bbafa99bc0728aa8479.tar.gz
nova-a0f968235332e5400d507bbafa99bc0728aa8479.tar.xz
nova-a0f968235332e5400d507bbafa99bc0728aa8479.zip
moved to wrap_exception decorator
-rw-r--r--nova/compute/manager.py7
-rw-r--r--nova/exception.py8
-rw-r--r--nova/notifier/api.py26
-rw-r--r--nova/rpc.py8
4 files changed, 13 insertions, 36 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 5aed2c677..86d375b9e 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -54,6 +54,7 @@ from nova import utils
from nova import volume
from nova.compute import power_state
from nova.compute.utils import terminate_volumes
+from nova.notifier import api as notifier
from nova.virt import driver
@@ -111,6 +112,10 @@ def checks_instance_lock(function):
return decorated_function
+def publisher_id(host=None):
+ return notifier.publisher_id("compute", host)
+
+
class ComputeManager(manager.SchedulerDependentManager):
"""Manages the running instances from creation to destruction."""
@@ -1158,7 +1163,7 @@ class ComputeManager(manager.SchedulerDependentManager):
{"method": "pre_live_migration",
"args": {'instance_id': instance_id}})
- except Exception:
+ except Exception, e:
msg = _("Pre live migration for %(i_name)s failed at %(dest)s")
LOG.error(msg % locals())
self.recover_live_migration(context, instance_ref)
diff --git a/nova/exception.py b/nova/exception.py
index f3a452228..4b625dd04 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -81,11 +81,17 @@ def wrap_db_error(f):
_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):
try:
return f(*args, **kw)
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):
#exc_type, exc_value, exc_traceback = sys.exc_info()
LOG.exception(_('Uncaught exception'))
diff --git a/nova/notifier/api.py b/nova/notifier/api.py
index 027aa7cc3..89527be16 100644
--- a/nova/notifier/api.py
+++ b/nova/notifier/api.py
@@ -43,11 +43,6 @@ def publisher_id(service, host=None):
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):
try:
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 "
"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):
"""
Sends a notification using the specified driver
diff --git a/nova/rpc.py b/nova/rpc.py
index 47d63769a..2e78a31e7 100644
--- a/nova/rpc.py
+++ b/nova/rpc.py
@@ -44,7 +44,6 @@ from nova import fakerabbit
from nova import flags
from nova import log as logging
from nova import utils
-from nova.notifier import api as notifier
LOG = logging.getLogger('nova.rpc')
@@ -313,7 +312,6 @@ class ConsumerSet(object):
if not it:
break
while True:
- ex = None
try:
it.next()
except StopIteration:
@@ -321,13 +319,7 @@ class ConsumerSet(object):
except greenlet.GreenletExit:
running = False
break
- except exception.NovaException, e:
- ex = e
- notifier.exception_to_notification(e)
except Exception as e:
- ex = e
-
- if ex:
LOG.exception(_("Exception while processing consumer"))
self.reconnect()
# Break to outer loop