Don't add exception instance in LOG.exception

LOG.exception will print out the full stacktrace, that's enough.
We should only record meaningful message.

Change-Id: I8b5c581717e6b78c11c46e226463927450c9f287
This commit is contained in:
ChangBo Guo(gcb) 2015-01-13 12:02:35 +08:00 committed by ChangBo Guo(gcb)
parent 4103a86f30
commit 3095aef31a
21 changed files with 89 additions and 94 deletions

View File

@ -91,8 +91,8 @@ class FaultWrapper(wsgi.Middleware):
def __call__(self, req):
try:
return req.get_response(self.application)
except Exception as ex:
LOG.exception(_LE("FaultWrapper: %s"), ex)
except Exception:
LOG.exception(_LE("FaultWrapper error"))
return faults.Fault(webob.exc.HTTPInternalServerError())

View File

@ -155,8 +155,8 @@ class AdminActionsController(wsgi.Controller):
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.NoValidHost as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
except Exception as e:
LOG.exception(_LE("Error in migrate %s"), e)
except Exception:
LOG.exception(_LE("Error in migrate"))
raise exc.HTTPBadRequest()
return webob.Response(status_int=202)

View File

@ -42,8 +42,8 @@ class LoadedExtensionInfo(object):
"""Checks for required methods in extension objects."""
try:
extension.is_valid()
except AttributeError as ex:
LOG.exception(_LE("Exception loading extension: %s"), ex)
except AttributeError:
LOG.exception(_LE("Exception loading extension"))
return False
return True

View File

@ -192,8 +192,8 @@ class ExtensionManager(object):
"""Checks for required methods in extension objects."""
try:
extension.is_valid()
except AttributeError as ex:
LOG.exception(_LE("Exception loading extension: %s"), ex)
except AttributeError:
LOG.exception(_LE("Exception loading extension"))
return False
return True

View File

@ -200,11 +200,10 @@ class _BaseMessage(object):
try:
resp_value = self.msg_runner._process_message_locally(self)
failure = False
except Exception as exc:
except Exception:
resp_value = sys.exc_info()
failure = True
LOG.exception(_LE("Error processing message locally: %(exc)s"),
{'exc': exc})
LOG.exception(_LE("Error processing message locally"))
return Response(self.routing_path, resp_value, failure)
def _setup_response_queue(self):
@ -411,10 +410,9 @@ class _TargetedMessage(_BaseMessage):
"""
try:
next_hop = self._get_next_hop()
except Exception as exc:
except Exception:
exc_info = sys.exc_info()
LOG.exception(_LE("Error locating next hop for message: %(exc)s"),
{'exc': exc})
LOG.exception(_LE("Error locating next hop for message"))
return self._send_response_from_exception(exc_info)
if next_hop.is_me:
@ -438,11 +436,10 @@ class _TargetedMessage(_BaseMessage):
raise exception.CellMaxHopCountReached(
hop_count=self.hop_count)
next_hop.send_message(self)
except Exception as exc:
except Exception:
exc_info = sys.exc_info()
err_str = _("Failed to send message to cell: %(next_hop)s: "
"%(exc)s")
LOG.exception(err_str, {'exc': exc, 'next_hop': next_hop})
err_str = _LE("Failed to send message to cell: %(next_hop)s")
LOG.exception(err_str, {'next_hop': next_hop})
self._cleanup_response_queue()
return self._send_response_from_exception(exc_info)
@ -517,10 +514,9 @@ class _BroadcastMessage(_BaseMessage):
"""
try:
next_hops = self._get_next_hops()
except Exception as exc:
except Exception:
exc_info = sys.exc_info()
LOG.exception(_LE("Error locating next hops for message: %(exc)s"),
{'exc': exc})
LOG.exception(_LE("Error locating next hops for message"))
return self._send_response_from_exception(exc_info)
# Short circuit if we don't need to respond
@ -535,12 +531,11 @@ class _BroadcastMessage(_BaseMessage):
try:
self._setup_response_queue()
self._send_to_cells(next_hops)
except Exception as exc:
except Exception:
# Error just trying to send to cells. Send a single response
# with the failure.
exc_info = sys.exc_info()
LOG.exception(_LE("Error sending message to next hops: %(exc)s"),
{'exc': exc})
LOG.exception(_LE("Error sending message to next hops."))
self._cleanup_response_queue()
return self._send_response_from_exception(exc_info)
@ -553,13 +548,12 @@ class _BroadcastMessage(_BaseMessage):
try:
remote_responses = self._wait_for_json_responses(
num_responses=len(next_hops))
except Exception as exc:
except Exception:
# Error waiting for responses, most likely a timeout.
# Send a single response back with the failure.
exc_info = sys.exc_info()
err_str = _("Error waiting for responses from neighbor cells: "
"%(exc)s")
LOG.exception(err_str, {'exc': exc})
LOG.exception(_LE("Error waiting for responses from"
" neighbor cells"))
return self._send_response_from_exception(exc_info)
if local_response:

View File

@ -173,11 +173,11 @@ class CellStateManager(base.Base):
try:
self._cell_data_sync(force=True)
break
except db_exc.DBError as e:
except db_exc.DBError:
attempts += 1
if attempts > 120:
raise
LOG.exception(_LE('DB error: %s'), e)
LOG.exception(_LE('DB error'))
time.sleep(30)
my_cell_capabs = {}

View File

@ -1556,7 +1556,7 @@ class API(base.Base):
LOG.warning(_LW("Failed to delete snapshot "
"from shelved instance (%s)."),
exc.format_message(), instance=instance)
except Exception as exc:
except Exception:
LOG.exception(_LE("Something wrong happened when trying to "
"delete snapshot from shelved instance."),
instance=instance)

View File

@ -1059,7 +1059,7 @@ class ComputeManager(manager.Manager):
self.driver.finish_revert_migration(context,
instance, net_info, block_dev_info, power_on)
except Exception as e:
except Exception:
LOG.exception(_LE('Failed to revert crashed migration'),
instance=instance)
finally:
@ -3264,9 +3264,9 @@ class ComputeManager(manager.Manager):
# interrupted by another (most likely delete) task
# do not retry
raise
except Exception as e:
except Exception:
# Catch all here because this could be anything.
LOG.exception(_LE('set_admin_password failed: %s'), e,
LOG.exception(_LE('set_admin_password failed'),
instance=instance)
self._set_instance_obj_error_state(context, instance)
# We create a new exception here so that we won't
@ -3996,10 +3996,10 @@ class ComputeManager(manager.Manager):
with excutils.save_and_reraise_exception():
try:
quotas.rollback()
except Exception as qr_error:
except Exception:
LOG.exception(_LE("Failed to rollback quota for failed "
"finish_resize: %s"),
qr_error, instance=instance)
"finish_resize"),
instance=instance)
self._set_instance_error_state(context, instance)
@object_compat

View File

@ -108,9 +108,9 @@ class ComputeDriverCPUMonitor(monitor._CPUMonitorBase):
self._data["cpu.idle.time"] = stats["idle"]
self._data["cpu.iowait.time"] = stats["iowait"]
self._data["cpu.frequency"] = stats["frequency"]
except (NotImplementedError, TypeError, KeyError) as ex:
except (NotImplementedError, TypeError, KeyError):
LOG.exception(_LE("Not all properties needed are implemented "
"in the compute driver: %s"), ex)
"in the compute driver"))
raise exception.ResourceMonitorError(
monitor=self.__class__.__name__)

View File

@ -343,8 +343,8 @@ class GlanceImageService(object):
"using %s") % o.scheme
LOG.info(msg)
return
except Exception as ex:
LOG.exception(ex)
except Exception:
LOG.exception(_LE("Download image error"))
try:
image_chunks = self._client.call(context, 1, 'data', image_id)

View File

@ -64,18 +64,18 @@ class SchedulerOptions(object):
"""Get the last modified datetime. Broken out for testing."""
try:
return os.path.getmtime(filename)
except os.error as e:
except os.error:
with excutils.save_and_reraise_exception():
LOG.exception(_LE("Could not stat scheduler options file "
"%(filename)s: '%(e)s'"),
{'filename': filename, 'e': e})
"%(filename)s"),
{'filename': filename})
def _load_file(self, handle):
"""Decode the JSON file. Broken out for testing."""
try:
return jsonutils.load(handle)
except ValueError as e:
LOG.exception(_LE("Could not decode scheduler options: '%s'"), e)
except ValueError:
LOG.exception(_LE("Could not decode scheduler options"))
return {}
def _get_time_now(self):

View File

@ -1481,8 +1481,8 @@ class FakeVim(object):
prop_list.append(prop)
obj_content = ObjectContent(mdo.obj, prop_list)
lst_ret_objs.add_object(obj_content)
except Exception as exc:
LOG.exception(exc)
except Exception:
LOG.exception("_retrieve_properties error")
continue
return lst_ret_objs

View File

@ -445,8 +445,8 @@ def teardown_container(container_dir, container_root_device=None):
LOG.debug('Release nbd device %s', container_root_device)
utils.execute('qemu-nbd', '-d', container_root_device,
run_as_root=True)
except Exception as exn:
LOG.exception(_LE('Failed to teardown container filesystem: %s'), exn)
except Exception:
LOG.exception(_LE('Failed to teardown container filesystem'))
def clean_lxc_namespace(container_dir):
@ -458,8 +458,8 @@ def clean_lxc_namespace(container_dir):
try:
img = _DiskImage(image=None, mount_dir=container_dir)
img.umount()
except Exception as exn:
LOG.exception(_LE('Failed to umount container filesystem: %s'), exn)
except Exception:
LOG.exception(_LE('Failed to umount container filesystem'))
def inject_data_into_fs(fs, key, net, metadata, admin_password, files,

View File

@ -21,7 +21,7 @@ if sys.platform == 'win32':
from oslo_log import log as logging
from nova import exception
from nova.i18n import _
from nova.i18n import _, _LE
from nova.virt.hyperv import vmutils
from nova.virt.hyperv import vmutilsv2
from nova.virt.hyperv import volumeutilsv2
@ -39,7 +39,7 @@ class LiveMigrationUtils(object):
try:
return wmi.WMI(moniker='//%s/root/virtualization/v2' % host)
except wmi.x_wmi as ex:
LOG.exception(ex)
LOG.exception(_LE('Get version 2 connection error'))
if ex.com_error.hresult == -2147217394:
msg = (_('Live migration is not supported on target host "%s"')
% host)

View File

@ -29,7 +29,7 @@ from oslo_utils import units
from oslo_vmware import rw_handles
from nova import exception
from nova.i18n import _, _LI
from nova.i18n import _, _LE, _LI
from nova import image
from nova.virt.vmwareapi import constants
from nova.virt.vmwareapi import io_util
@ -199,7 +199,7 @@ def start_transfer(context, read_file_handle, data_size,
write_thread.stop()
# Log and raise the exception.
LOG.exception(exc)
LOG.exception(_LE('Transfer data failed'))
raise exception.NovaException(exc)
finally:
# No matter what, try closing the read and write handles, if it so

View File

@ -25,7 +25,7 @@ from eventlet import queue
from oslo_log import log as logging
from nova import exception
from nova.i18n import _
from nova.i18n import _, _LE
from nova import image
LOG = logging.getLogger(__name__)
@ -180,7 +180,7 @@ class IOThread(object):
greenthread.sleep(IO_THREAD_SLEEP_TIME)
except Exception as exc:
self.stop()
LOG.exception(exc)
LOG.exception(_LE('Read/Write data failed'))
self.done.send_exception(exc)
greenthread.spawn(_inner)

View File

@ -31,7 +31,7 @@ from oslo_vmware.objects import datastore as ds_obj
from oslo_vmware import pbm
from nova import exception
from nova.i18n import _, _LI, _LW
from nova.i18n import _, _LE, _LI, _LW
from nova.network import model as network_model
from nova.virt.vmwareapi import constants
from nova.virt.vmwareapi import vim_util
@ -1279,8 +1279,8 @@ def destroy_vm(session, instance, vm_ref=None):
vm_ref)
session._wait_for_task(destroy_task)
LOG.info(_LI("Destroyed the VM"), instance=instance)
except Exception as exc:
LOG.exception(exc, instance=instance)
except Exception:
LOG.exception(_LE('Destroy VM failed'), instance=instance)
def create_virtual_disk(session, dc_ref, adapter_type, disk_type,

View File

@ -952,8 +952,9 @@ class VMwareVMOps(object):
LOG.warning(_LW("In vmwareapi:vmops:_destroy_instance, "
"exception while deleting the VM contents "
"from the disk"), exc_info=True)
except Exception as exc:
LOG.exception(exc, instance=instance)
except Exception:
LOG.exception(_LE('Destroy instance failed'),
instance=instance)
finally:
vm_util.vm_ref_cache_delete(instance_name)

View File

@ -315,8 +315,8 @@ def destroy_vm(session, instance, vm_ref):
"""Destroys a VM record."""
try:
session.VM.destroy(vm_ref)
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('Destroy VM failed'))
return
LOG.debug("VM destroyed", instance=instance)
@ -331,8 +331,8 @@ def clean_shutdown_vm(session, instance, vm_ref):
LOG.debug("Shutting down VM (cleanly)", instance=instance)
try:
session.call_xenapi('VM.clean_shutdown', vm_ref)
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('Shutting down VM (cleanly) failed.'))
return False
return True
@ -346,8 +346,8 @@ def hard_shutdown_vm(session, instance, vm_ref):
LOG.debug("Shutting down VM (hard)", instance=instance)
try:
session.call_xenapi('VM.hard_shutdown', vm_ref)
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('Shutting down VM (hard) failed'))
return False
return True
@ -400,7 +400,7 @@ def unplug_vbd(session, vbd_ref, this_vm_ref):
{'vbd_ref': vbd_ref, 'num_attempt': num_attempt,
'max_attempts': max_attempts, 'err': err})
else:
LOG.exception(exc)
LOG.exception(_LE('Unable to unplug VBD'))
raise exception.StorageError(
reason=_('Unable to unplug VBD %s') % vbd_ref)
@ -414,8 +414,8 @@ def destroy_vbd(session, vbd_ref):
"""Destroy VBD from host database."""
try:
session.call_xenapi('VBD.destroy', vbd_ref)
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('Unable to destroy VBD'))
raise exception.StorageError(
reason=_('Unable to destroy VBD %s') % vbd_ref)
@ -1684,8 +1684,8 @@ def lookup_vm_vdis(session, vm_ref):
if not vbd_other_config.get('osvol'):
# This is not an attached volume
vdi_refs.append(vdi_ref)
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('"Look for the VDIs failed'))
return vdi_refs

View File

@ -950,7 +950,7 @@ class VMOps(object):
transfer_vhd_to_dest(new_vdi_ref, new_vdi_uuid)
except Exception as error:
LOG.exception(_LE("_migrate_disk_resizing_down failed. "
"Restoring orig vm due_to: %s."), error,
"Restoring orig vm"),
instance=instance)
undo_mgr._rollback()
raise exception.InstanceFaultRollback(error)
@ -1733,8 +1733,8 @@ class VMOps(object):
try:
raw_console_data = self._session.call_plugin('console',
'get_console_log', {'dom_id': dom_id})
except self._session.XenAPI.Failure as exc:
LOG.exception(exc)
except self._session.XenAPI.Failure:
LOG.exception(_LE("Guest does not have a console available"))
msg = _("Guest does not have a console available")
raise exception.NovaException(msg)
@ -2057,8 +2057,8 @@ class VMOps(object):
destref,
nwref,
options)
except self._session.XenAPI.Failure as exc:
LOG.exception(exc)
except self._session.XenAPI.Failure:
LOG.exception(_LE('Migrate Receive failed'))
msg = _('Migrate Receive failed')
raise exception.MigrationPreCheckError(reason=msg)
return migrate_data
@ -2114,8 +2114,8 @@ class VMOps(object):
config_value = self._make_plugin_call('config_file',
'get_val',
key='relax-xsm-sr-check')
except Exception as exc:
LOG.exception(exc)
except Exception:
LOG.exception(_LE('Plugin config_file get_val failed'))
self.cached_xsm_sr_relaxed = config_value == "true"
return self.cached_xsm_sr_relaxed
@ -2202,8 +2202,8 @@ class VMOps(object):
try:
self._call_live_migrate_command(
"VM.migrate_send", vm_ref, migrate_data)
except self._session.XenAPI.Failure as exc:
LOG.exception(exc)
except self._session.XenAPI.Failure:
LOG.exception(_LE('Migrate Send failed'))
raise exception.MigrationError(
reason=_('Migrate Send failed'))

View File

@ -26,7 +26,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from nova import exception
from nova.i18n import _, _LW
from nova.i18n import _, _LE, _LW
xenapi_volume_utils_opts = [
cfg.IntOpt('introduce_vdi_retry_wait',
@ -159,8 +159,8 @@ def introduce_vdi(session, sr_ref, vdi_uuid=None, target_lun=None):
greenthread.sleep(CONF.xenserver.introduce_vdi_retry_wait)
session.call_xenapi("SR.scan", sr_ref)
vdi_ref = _get_vdi_ref(session, sr_ref, vdi_uuid, target_lun)
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('Unable to introduce VDI on SR'))
raise exception.StorageError(
reason=_('Unable to introduce VDI on SR %s') % sr_ref)
@ -174,8 +174,8 @@ def introduce_vdi(session, sr_ref, vdi_uuid=None, target_lun=None):
try:
vdi_rec = session.call_xenapi("VDI.get_record", vdi_ref)
LOG.debug(vdi_rec)
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('Unable to get record of VDI'))
raise exception.StorageError(
reason=_('Unable to get record of VDI %s on') % vdi_ref)
@ -196,8 +196,8 @@ def introduce_vdi(session, sr_ref, vdi_uuid=None, target_lun=None):
vdi_rec['location'],
vdi_rec['xenstore_data'],
vdi_rec['sm_config'])
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('Unable to introduce VDI for SR'))
raise exception.StorageError(
reason=_('Unable to introduce VDI for SR %s') % sr_ref)
@ -294,8 +294,8 @@ def find_sr_from_vbd(session, vbd_ref):
try:
vdi_ref = session.call_xenapi("VBD.get_VDI", vbd_ref)
sr_ref = session.call_xenapi("VDI.get_SR", vdi_ref)
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('Unable to find SR from VBD'))
raise exception.StorageError(
reason=_('Unable to find SR from VBD %s') % vbd_ref)
return sr_ref
@ -305,8 +305,8 @@ def find_sr_from_vdi(session, vdi_ref):
"""Find the SR reference from the VDI reference."""
try:
sr_ref = session.call_xenapi("VDI.get_SR", vdi_ref)
except session.XenAPI.Failure as exc:
LOG.exception(exc)
except session.XenAPI.Failure:
LOG.exception(_LE('Unable to find SR from VDI'))
raise exception.StorageError(
reason=_('Unable to find SR from VDI %s') % vdi_ref)
return sr_ref