From 2758739847e30e18675ad945a1a3ad04c4603e3f Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 8 Oct 2015 14:56:30 +0200 Subject: [PATCH] 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 --- doc/source/devref/effective_neutron.rst | 4 ++++ neutron/agent/common/ovs_lib.py | 7 +++---- neutron/agent/l3/router_info.py | 6 +++--- neutron/api/extensions.py | 5 ++--- neutron/cmd/sanity/checks.py | 5 ++--- neutron/plugins/brocade/nos/nosdriver.py | 16 ++++++++-------- neutron/services/provider_configuration.py | 2 +- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/doc/source/devref/effective_neutron.rst b/doc/source/devref/effective_neutron.rst index 8b7981b11..2486c4ec7 100644 --- a/doc/source/devref/effective_neutron.rst +++ b/doc/source/devref/effective_neutron.rst @@ -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 ~~~~~~~~~~~~~~~~~~ diff --git a/neutron/agent/common/ovs_lib.py b/neutron/agent/common/ovs_lib.py index 010644f01..559fca232 100644 --- a/neutron/agent/common/ovs_lib.py +++ b/neutron/agent/common/ovs_lib.py @@ -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): diff --git a/neutron/agent/l3/router_info.py b/neutron/agent/l3/router_info.py index 8ac21b38f..27581626b 100644 --- a/neutron/agent/l3/router_info.py +++ b/neutron/agent/l3/router_info.py @@ -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( diff --git a/neutron/api/extensions.py b/neutron/api/extensions.py index 4af58774a..a1d374f8b 100644 --- a/neutron/api/extensions.py +++ b/neutron/api/extensions.py @@ -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 diff --git a/neutron/cmd/sanity/checks.py b/neutron/cmd/sanity/checks.py index 39c97066e..761be3c06 100644 --- a/neutron/cmd/sanity/checks.py +++ b/neutron/cmd/sanity/checks.py @@ -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 diff --git a/neutron/plugins/brocade/nos/nosdriver.py b/neutron/plugins/brocade/nos/nosdriver.py index 3d87d939a..d2546a9a8 100644 --- a/neutron/plugins/brocade/nos/nosdriver.py +++ b/neutron/plugins/brocade/nos/nosdriver.py @@ -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): diff --git a/neutron/services/provider_configuration.py b/neutron/services/provider_configuration.py index c2837855a..c068ce8a3 100644 --- a/neutron/services/provider_configuration.py +++ b/neutron/services/provider_configuration.py @@ -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']} -- 2.45.2