summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-05-01 17:31:26 -0400
committerRussell Bryant <rbryant@redhat.com>2012-05-02 16:05:58 -0400
commit29dc47bd5045853d83a2343ec88c36ea89db188d (patch)
tree4a7d4696ceed6ddf34976445bf90a14480e1170e /nova/utils.py
parent1d97b77ea4c31f1fb17bc20cc4c16a3f6edf2cf1 (diff)
Use save_and_reraise_exception() from common.
This patch common.excutils from openstack-common, which includes save_and_reraise_exception(). The patch also converts the code base to use it from there instead of nova.utils and then removes it from nova.utils. The initial motivation for this was removing another nova dependency from nova.rpc so that it can eventually be moved to openstack-common. Change-Id: I7354ca51a02aec9c709cf33f77d4abc46acc2742
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py33
1 files changed, 4 insertions, 29 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 71e734e8b..c57833c54 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -57,6 +57,7 @@ from nova import exception
from nova import flags
from nova import log as logging
from nova.openstack.common import cfg
+from nova.openstack.common import excutils
from nova.openstack.common import importutils
@@ -1258,32 +1259,6 @@ def generate_glance_url():
@contextlib.contextmanager
-def save_and_reraise_exception():
- """Save current exception, run some code and then re-raise.
-
- In some cases the exception context can be cleared, resulting in None
- being attempted to be reraised after an exception handler is run. This
- can happen when eventlet switches greenthreads or when running an
- exception handler, code raises and catches an exception. In both
- cases the exception context will be cleared.
-
- To work around this, we save the exception state, run handler code, and
- then re-raise the original exception. If another exception occurs, the
- saved exception is logged and the new exception is reraised.
- """
- type_, value, traceback = sys.exc_info()
- try:
- yield
- except Exception:
- # NOTE(jkoelker): Using LOG.error here since it accepts exc_info
- # as a kwargs.
- LOG.error(_('Original exception being dropped'),
- exc_info=(type_, value, traceback))
- raise
- raise type_, value, traceback
-
-
-@contextlib.contextmanager
def logging_error(message):
"""Catches exception, write message to the log, re-raise.
This is a common refinement of save_and_reraise that writes a specific
@@ -1292,7 +1267,7 @@ def logging_error(message):
try:
yield
except Exception as error:
- with save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
LOG.exception(message)
@@ -1304,7 +1279,7 @@ def remove_path_on_error(path):
try:
yield
except Exception:
- with save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
delete_if_exists(path)
@@ -1671,7 +1646,7 @@ class UndoManager(object):
.. note:: (sirp) This should only be called within an
exception handler.
"""
- with save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
if msg:
LOG.exception(msg, **kwargs)