]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Cleaned up remaining incorrect usage for LOG.exception
authorIhar Hrachyshka <ihrachys@redhat.com>
Thu, 8 Oct 2015 12:56:30 +0000 (14:56 +0200)
committerIhar Hrachyshka <ihrachys@redhat.com>
Thu, 8 Oct 2015 14:45:18 +0000 (16:45 +0200)
- 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
neutron/agent/common/ovs_lib.py
neutron/agent/l3/router_info.py
neutron/api/extensions.py
neutron/cmd/sanity/checks.py
neutron/plugins/brocade/nos/nosdriver.py
neutron/services/provider_configuration.py

index 8b7981b118c9126110051307347bb412060f02c0..2486c4ec7cf890030fc8ec4c1c82690dc5e8ef8d 100644 (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
 ~~~~~~~~~~~~~~~~~~
index 010644f01b41146a214a9468ac2ec401b228fbf3..559fca2320dd30f03a709fd4204108000af50c8e 100644 (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):
index 8ac21b38f8f316e962b441cf47a48b244e38925b..27581626b2b3f75f435819cbc84b81c742fae1e4 100644 (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(
index 4af58774ac9d50dd981b5dc70e895c262d589a36..a1d374f8b73508a6c6eacf93af346fed4d688c5f 100644 (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
 
index 39c97066e5a36bddc961b5204fdeb8a0aa03f3e5..761be3c065949028cef54a8f0aa256c0db66190c 100644 (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
 
index 3d87d939a780c265a0f211158d06e2873abf3c86..d2546a9a84d93591831607c1b9a910bbb5817f33 100644 (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):
index c2837855a30da8802a11f5ae4cc1525f89cfcb32..c068ce8a31958ba55d23cf7cbf3d7534e46c0697 100644 (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']}