--- /dev/null
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC.
+# Copyright 2012, Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""
+Exception related utilities.
+"""
+
+import contextlib
+import logging
+import sys
+import traceback
+
+
+@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, tb = sys.exc_info()
+ try:
+ yield
+ except Exception:
+ logging.error('Original exception being dropped: %s' %
+ (traceback.format_exception(type_, value, tb)))
+ raise
+ raise type_, value, tb
from eventlet import pools
from eventlet import semaphore
+from cinder.openstack.common import excutils
from cinder.openstack.common import local
import cinder.rpc.common as rpc_common
-from cinder import utils
+
LOG = logging.getLogger(__name__)
try:
self._iterator.next()
except Exception:
- with utils.save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
self.done()
if self._got_ending:
self.done()
from cinder import manager
from cinder.notifier import api as notifier
from cinder.openstack.common import cfg
+from cinder.openstack.common import excutils
from cinder.openstack.common import importutils
-from cinder import utils
LOG = logging.getLogger(__name__)
try:
return driver_method(*args, **kwargs)
except Exception as ex:
- with utils.save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
self._set_vm_state_and_notify(method,
{'vm_state': vm_states.ERROR},
context, ex, *args, **kwargs)
{'vm_state': vm_states.ERROR},
context, ex, *args, **kwargs)
except Exception as ex:
- with utils.save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
self._set_vm_state_and_notify('run_instance',
{'vm_state': vm_states.ERROR},
context, ex, *args, **kwargs)
'task_state': None},
context, ex, *args, **kwargs)
except Exception as ex:
- with utils.save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
self._set_vm_state_and_notify('prep_resize',
{'vm_state': vm_states.ERROR},
context, ex, *args, **kwargs)
from cinder import flags
from cinder import log as logging
from cinder.openstack.common import cfg
+from cinder.openstack.common import excutils
from cinder.openstack.common import importutils
from cinder.openstack.common import timeutils
return "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port)
-@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.
try:
yield
except Exception as error:
- with save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
LOG.exception(message)
try:
yield
except Exception:
- with save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
delete_if_exists(path)
.. 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)
from cinder import log as logging
from cinder import manager
from cinder.openstack.common import cfg
+from cinder.openstack.common import excutils
from cinder.openstack.common import importutils
from cinder.openstack.common import timeutils
from cinder import rpc
if model_update:
self.db.volume_update(context, volume_ref['id'], model_update)
except Exception:
- with utils.save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
self.db.volume_update(context,
volume_ref['id'], {'status': 'error'})
{'status': 'available'})
return True
except Exception:
- with utils.save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
self.db.volume_update(context,
volume_ref['id'],
{'status': 'error_deleting'})
model_update)
except Exception:
- with utils.save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
self.db.snapshot_update(context,
snapshot_ref['id'],
{'status': 'error'})
{'status': 'available'})
return True
except Exception:
- with utils.save_and_reraise_exception():
+ with excutils.save_and_reraise_exception():
self.db.snapshot_update(context,
snapshot_ref['id'],
{'status': 'error_deleting'})
[DEFAULT]
# The list of modules to copy from openstack-common
-modules=cfg,exception,importutils,iniparser,jsonutils,local,timeutils
+modules=cfg,exception,excutils,importutils,iniparser,jsonutils,local,timeutils
# The base module to hold the copy of openstack.common
base=cinder