Cleaned up remaining incorrect usage for LOG.exception

- callers should not explicitly pass exceptions into LOG.exception
  because it's already implicitly included in the message by stdlib
  logging module.
- callers should not call to LOG.exception when there is no exception to
  log about (known to fail in Python 3.x < 3.5).

Change-Id: I58e7e01ed152028ad43bb3ada87d719caa2ab08d
Related-Bug: #1504053
This commit is contained in:
Ihar Hrachyshka 2015-10-08 14:56:30 +02:00
parent 8f58bbf38f
commit 2758739847
7 changed files with 23 additions and 22 deletions

View File

@ -184,6 +184,10 @@ Document common pitfalls as well as good practices done when instrumenting your
exceptions or other objects directly (LOG.error(exc), LOG.error(port), etc.).
See http://docs.openstack.org/developer/oslo.log/usage.html#no-more-implicit-conversion-to-unicode-str
for more details.
* Don't pass exceptions into LOG.exception: it is already implicitly included
in the log message by Python logging module.
* Don't use LOG.exception when there is no exception registered in current
thread context: Python 3.x versions before 3.5 are known to fail on it.
Project interfaces
~~~~~~~~~~~~~~~~~~

View File

@ -244,10 +244,9 @@ class OVSBridge(BaseOVS):
ofport = INVALID_OFPORT
try:
ofport = self._get_port_ofport(port_name)
except retrying.RetryError as e:
LOG.exception(_LE("Timed out retrieving ofport on port %(pname)s. "
"Exception: %(exception)s"),
{'pname': port_name, 'exception': e})
except retrying.RetryError:
LOG.exception(_LE("Timed out retrieving ofport on port %s."),
port_name)
return ofport
def get_datapath_id(self):

View File

@ -24,7 +24,7 @@ from neutron.common import constants as l3_constants
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
from neutron.common import utils as common_utils
from neutron.i18n import _LW
from neutron.i18n import _LE, _LW
LOG = logging.getLogger(__name__)
INTERNAL_DEV_PREFIX = namespaces.INTERNAL_DEV_PREFIX
@ -666,9 +666,9 @@ class RouterInfo(object):
fip_statuses = self.configure_fip_addresses(interface_name)
except (n_exc.FloatingIpSetupException,
n_exc.IpTablesApplyException) as e:
n_exc.IpTablesApplyException):
# All floating IPs must be put in error state
LOG.exception(e)
LOG.exception(_LE("Failed to process floating IPs."))
fip_statuses = self.put_fips_in_error_state()
finally:
agent.update_fip_statuses(

View File

@ -478,9 +478,8 @@ class ExtensionManager(object):
LOG.debug('Ext alias: %s', extension.get_alias())
LOG.debug('Ext description: %s', extension.get_description())
LOG.debug('Ext updated: %s', extension.get_updated())
except AttributeError as ex:
LOG.exception(_LE("Exception loading extension: %s"),
six.text_type(ex))
except AttributeError:
LOG.exception(_LE("Exception loading extension"))
return False
return True

View File

@ -21,7 +21,6 @@ import netaddr
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import uuidutils
import six
from neutron.agent.common import ovs_lib
from neutron.agent.l3 import ha_router
@ -327,8 +326,8 @@ def ovsdb_native_supported():
LOG.error(_LE("Failed to import required modules. Ensure that the "
"python-openvswitch package is installed. Error: %s"),
ex)
except Exception as ex:
LOG.exception(six.text_type(ex))
except Exception:
LOG.exception(_LE("Unexpected exception occurred."))
return False

View File

@ -88,9 +88,9 @@ class NOSdriver(object):
self.configure_trunk_mode_for_vlan_profile(mgr, name)
self.configure_allowed_vlans_for_vlan_profile(mgr, name, net_id)
self.activate_port_profile(mgr, name)
except Exception as ex:
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_LE("NETCONF error: %s"), ex)
LOG.exception(_LE("NETCONF error"))
self.close_session()
def delete_network(self, host, username, password, net_id):
@ -102,9 +102,9 @@ class NOSdriver(object):
self.deactivate_port_profile(mgr, name)
self.delete_port_profile(mgr, name)
self.delete_vlan_interface(mgr, net_id)
except Exception as ex:
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_LE("NETCONF error: %s"), ex)
LOG.exception(_LE("NETCONF error"))
self.close_session()
def associate_mac_to_network(self, host, username, password,
@ -115,9 +115,9 @@ class NOSdriver(object):
try:
mgr = self.connect(host, username, password)
self.associate_mac_to_port_profile(mgr, name, mac)
except Exception as ex:
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_LE("NETCONF error: %s"), ex)
LOG.exception(_LE("NETCONF error"))
self.close_session()
def dissociate_mac_from_network(self, host, username, password,
@ -128,9 +128,9 @@ class NOSdriver(object):
try:
mgr = self.connect(host, username, password)
self.dissociate_mac_from_port_profile(mgr, name, mac)
except Exception as ex:
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_LE("NETCONF error: %s"), ex)
LOG.exception(_LE("NETCONF error"))
self.close_session()
def create_vlan_interface(self, mgr, vlan_id):

View File

@ -218,7 +218,7 @@ class ProviderConfiguration(object):
if provider_type in self.providers:
msg = (_("Multiple providers specified for service "
"%s") % provider['service_type'])
LOG.exception(msg)
LOG.error(msg)
raise n_exc.Invalid(msg)
self.providers[provider_type] = {'driver': provider['driver'],
'default': provider['default']}