Use LOG.exception() properly

Contrary to popular belief, LOG.exception() is not a method to which you
pass an exception in order to log it. Rather, you pass the message to be
logged at ERROR level, and the exception is retrieved automatically via
sys.exc_info().

Change-Id: I197cf94ada34a7ce80fc4026a99d95cd50823882
This commit is contained in:
Zane Bitter 2016-06-06 17:06:19 -04:00
parent 0864664209
commit ad2b579ed6
5 changed files with 21 additions and 27 deletions

View File

@ -820,9 +820,8 @@ def read_global_environment(env, env_dir=None):
try:
env_files = glob.glob(os.path.join(env_dir, '*'))
except OSError as osex:
LOG.error(_LE('Failed to read %s'), env_dir)
LOG.exception(osex)
except OSError:
LOG.exception(_LE('Failed to read %s'), env_dir)
return
for file_path in env_files:
@ -832,11 +831,7 @@ def read_global_environment(env, env_dir=None):
env_body = env_fmt.parse(env_fd.read())
env_fmt.default_for_missing(env_body)
env.load(env_body)
except ValueError as vex:
LOG.error(_LE('Failed to parse %(file_path)s'), {
'file_path': file_path})
LOG.exception(vex)
except IOError as ioex:
LOG.error(_LE('Failed to read %(file_path)s'), {
'file_path': file_path})
LOG.exception(ioex)
except ValueError:
LOG.exception(_LE('Failed to parse %s'), file_path)
except IOError:
LOG.exception(_LE('Failed to read %s'), file_path)

View File

@ -168,11 +168,12 @@ class Resource(object):
try:
svc_available = cls.is_service_available(context)
except Exception as exc:
LOG.exception(_LE("Resource type %s unavailable"),
resource_type)
ex = exception.ResourceTypeUnavailable(
resource_type=resource_type,
service_name=cls.default_client_name,
reason=six.text_type(exc))
LOG.exception(exc)
raise ex
else:
if not svc_available:

View File

@ -1246,15 +1246,16 @@ class Server(stack_user.StackUser, sh.SchedulerHintsMixin,
self.context, sd['id'])
self.rpc_client().delete_software_config(
self.context, sc['id'])
except Exception as e:
except Exception:
# Updating the software config transport is on a best-effort
# basis as any raised exception here would result in the resource
# going into an ERROR state, which will be replaced on the next
# stack update. This is not desirable for a server. The old
# transport will continue to work, and the new transport may work
# despite exceptions in the above block.
LOG.error(_LE('Error while updating software config transport'))
LOG.exception(e)
LOG.exception(
_LE('Error while updating software config transport')
)
def check_update_complete(self, updaters):
"""Push all updaters to completion in list order."""

View File

@ -1564,14 +1564,12 @@ class Stack(collections.Mapping):
# There are cases where the user_creds cannot be returned
# due to credentials truncated when being saved to DB.
# Ignore this error instead of blocking stack deletion.
user_creds = None
try:
user_creds = ucreds_object.UserCreds.get_by_id(
self.context, self.user_creds_id)
except exception.Error as err:
LOG.exception(err)
pass
return user_creds
return ucreds_object.UserCreds.get_by_id(self.context,
self.user_creds_id)
except exception.Error:
LOG.exception(_LE("Failed to retrieve user_creds"))
return None
def _delete_credentials(self, stack_status, reason, abandon):
# Cleanup stored user_creds so they aren't accessible via
@ -1601,7 +1599,7 @@ class Stack(collections.Mapping):
self.clients.client('keystone').delete_trust(
trust_id)
except Exception as ex:
LOG.exception(ex)
LOG.exception(_LE("Error deleting trust"))
stack_status = self.FAILED
reason = ("Error deleting trust: %s" %
six.text_type(ex))
@ -1629,7 +1627,7 @@ class Stack(collections.Mapping):
keystone.delete_stack_domain_project(
project_id=self.stack_user_project_id)
except Exception as ex:
LOG.exception(ex)
LOG.exception(_LE("Error deleting project"))
stack_status = self.FAILED
reason = "Error deleting project: %s" % six.text_type(ex)

View File

@ -77,9 +77,8 @@ class VolumeBackupRestoreIntegrationTest(scenario_base.ScenarioTestsBase):
template_name='test_volumes_create_from_backup.yaml',
add_parameters={'backup_id': backup.id})
stack2 = self.client.stacks.get(stack_identifier2)
except exceptions.StackBuildErrorException as e:
LOG.error("Halting test due to bug: #1382300")
LOG.exception(e)
except exceptions.StackBuildErrorException:
LOG.exception("Halting test due to bug: #1382300")
return
# Verify with cinder that the volume exists, with matching details