]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Avoid unnecessary explicit str() conversion around exceptions
authorAnn Kamyshnikova <akamyshnikova@mirantis.com>
Wed, 3 Dec 2014 12:57:58 +0000 (15:57 +0300)
committerAnn Kamyshnikova <akamyshnikova@mirantis.com>
Tue, 16 Dec 2014 08:19:09 +0000 (11:19 +0300)
There are number of places like

except Exception as exc:
            LOG.error("Failed to get network: %s", str(exc))

where str() is not needed since %s substitution already does
the same conversion. Also LOG.error could be replaced with
LOG.exception, so argument exc won't be needed at all.

Closes-bug: #1398839

Change-Id: I73cc6e1ce55ade08e7706b99a5ab075f7059a4ef

neutron/agent/l3/agent.py
neutron/db/migration/cli.py
neutron/plugins/bigswitch/servermanager.py
neutron/plugins/cisco/l3/hosting_device_drivers/csr1kv_hd_driver.py
neutron/plugins/nec/packet_filter.py
neutron/plugins/nuage/syncmanager.py
neutron/plugins/sriovnicagent/pci_lib.py
neutron/plugins/vmware/check_nsx_config.py
neutron/plugins/vmware/nsxlib/router.py
neutron/plugins/vmware/nsxlib/switch.py
neutron/tests/unit/database_stubs.py

index 7b2fa3d87e1efc2ab16d3be88629c7815b6c85e6..ff3e2a9450dc7f5dd6d21d9a5f98cf441910da0f 100644 (file)
@@ -915,8 +915,8 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
             ip_wrapper = ip_lib.IPWrapper(self.root_helper,
                                           namespace=ns_name)
             ip_wrapper.netns.execute(arping_cmd, check_exit_code=True)
-        except Exception as e:
-            LOG.error(_LE("Failed sending gratuitous ARP: %s"), str(e))
+        except Exception:
+            LOG.exception(_LE("Failed sending gratuitous ARP."))
         if distributed:
             device.addr.delete(net.version, ip_cidr)
 
index 96a0da705d08d324b41fb6d3717f62ea0cdbe3fa..5bd2eb30be047eb8acd60ca253ab20133e8cbcbe 100644 (file)
@@ -13,6 +13,7 @@
 #    under the License.
 
 import os
+import six
 
 from alembic import command as alembic_command
 from alembic import config as alembic_config
@@ -60,7 +61,7 @@ def do_alembic_command(config, cmd, *args, **kwargs):
     try:
         getattr(alembic_command, cmd)(config, *args, **kwargs)
     except alembic_util.CommandError as e:
-        alembic_util.err(str(e))
+        alembic_util.err(six.text_type(e))
 
 
 def do_check_migration(config, cmd):
index 6d473e3977fda4b0fc07356cba824fe9e32cb6e8..b71c737619bb0f508f846beafe413d8110ed196b 100644 (file)
@@ -395,7 +395,7 @@ class ServerPool(object):
             raise cfg.Error(_('Could not retrieve initial '
                               'certificate from controller %(server)s. '
                               'Error details: %(error)s') %
-                            {'server': server, 'error': str(e)})
+                            {'server': server, 'error': e})
 
         LOG.warning(_LW("Storing to certificate for host %(server)s "
                         "at %(path)s"), {'server': server,
index 57e8b7ef1f8f07b8f9b4192934ac567f40191b20..189f5e2771082b9ea371f64afa929e9ddddb6195 100644 (file)
@@ -63,9 +63,9 @@ class CSR1kvHostingDeviceDriver(hosting_device_drivers.HostingDeviceDriver):
                                         tokens)) + '\n'
                     vm_cfg_data += line
             return {'iosxe_config.txt': vm_cfg_data}
-        except IOError as e:
-            LOG.error(_LE('Failed to create config file: %s. Trying to'
-                        'clean up.'), str(e))
+        except IOError:
+            LOG.exception(_LE('Failed to create config file. Trying to '
+                              'clean up.'))
             self.delete_configdrive_files(context, mgmtport)
             raise
 
index d8d1240e4b1f5a3a931ba32b2ae5d02f21792794..9cb156537cc068220e0de34d9d0aa7e0e2e6ee02 100644 (file)
@@ -217,7 +217,7 @@ class PacketFilterMixin(pf_db.PacketFilterDbMixin):
             with excutils.save_and_reraise_exception():
                 LOG.error(_LE("Failed to delete packet_filter id=%(id)s "
                               "from OFC: %(exc)s"),
-                          {'id': pf_id, 'exc': str(exc)})
+                          {'id': pf_id, 'exc': exc})
                 self._update_resource_status_if_changed(
                     context, "packet_filter", packet_filter,
                     pf_db.PF_STATUS_ERROR)
index 13512f7c601d140e57f3510160a964b68cd8cf4d..ef68b546c2bc5cfbdc0c4349b035c708509d83fc 100644 (file)
@@ -51,9 +51,9 @@ class SyncManager(db_base_plugin_v2.NeutronDbPluginV2,
 
             # Sync all resources
             self._sync(resources, fipquota)
-        except Exception as e:
-            LOG.error(_LE("Cannot complete the sync between Neutron and VSD "
-                          "because of error:%s"), str(e))
+        except Exception:
+            LOG.exception(_LE("Cannot complete the sync between Neutron and "
+                              "VSD because of error."))
             return
 
         LOG.info(_LI("Sync between Neutron and VSD completed successfully"))
index 82be0d17902d5ead8cfedb846a5e128117444927..f4108086c1f4273998cfbe7c2500f326e89fedc4 100644 (file)
@@ -56,7 +56,7 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
         except Exception as e:
             LOG.exception(_LE("Failed executing ip command"))
             raise exc.IpCommandError(dev_name=self.dev_name,
-                                     reason=str(e))
+                                     reason=e)
         vf_lines = self._get_vf_link_show(vf_list, out)
         vf_details_list = []
         if vf_lines:
@@ -78,7 +78,7 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
         except Exception as e:
             LOG.exception(_LE("Failed executing ip command"))
             raise exc.IpCommandError(dev_name=self.dev_name,
-                                     reason=str(e))
+                                     reason=e)
         vf_lines = self._get_vf_link_show([vf_index], out)
         if vf_lines:
             vf_details = self._parse_vf_link_show(vf_lines[0])
@@ -105,7 +105,7 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
         except Exception as e:
             LOG.exception(_LE("Failed executing ip command"))
             raise exc.IpCommandError(dev_name=self.dev_name,
-                                     reason=str(e))
+                                     reason=e)
 
     def _get_vf_link_show(self, vf_list, link_show_out):
         """Get link show output for VFs
index a063394c1bfa965732804193a7f4885525b0a761..81368ecee5d610dbd05bae6388442ee14371884b 100644 (file)
@@ -43,7 +43,7 @@ def config_helper(config_entity, cluster):
                                  cluster=cluster).get('results', [])
     except Exception as e:
         msg = (_("Error '%(err)s' when connecting to controller(s): %(ctl)s.")
-               % {'err': str(e),
+               % {'err': e,
                   'ctl': ', '.join(get_nsx_controllers(cluster))})
         raise Exception(msg)
 
@@ -78,7 +78,7 @@ def is_transport_node_connected(cluster, node_uuid):
                                  cluster=cluster)['connection']['connected']
     except Exception as e:
         msg = (_("Error '%(err)s' when connecting to controller(s): %(ctl)s.")
-               % {'err': str(e),
+               % {'err': e,
                   'ctl': ', '.join(get_nsx_controllers(cluster))})
         raise Exception(msg)
 
index 1b26dfc3679dcf4fc87a3339752424b882b2d2de..89fee557b26829a25c91ac21275ad37fc1e310ab 100644 (file)
@@ -630,7 +630,7 @@ def update_lrouter_port_ips(cluster, lrouter_id, lport_id,
         raise nsx_exc.NsxPluginException(err_msg=msg)
     except api_exc.NsxApiException as e:
         msg = _("An exception occurred while updating IP addresses on a "
-                "router logical port:%s") % str(e)
+                "router logical port:%s") % e
         LOG.exception(msg)
         raise nsx_exc.NsxPluginException(err_msg=msg)
 
index 2a0e6924567ec82c5fa4b4c621cd98b315e333bd..566c645e15c57d77c5cad22956ee9d60863d8e37 100644 (file)
@@ -147,8 +147,8 @@ def update_lswitch(cluster, lswitch_id, display_name,
     try:
         return nsxlib.do_request(HTTP_PUT, uri, jsonutils.dumps(lswitch_obj),
                                  cluster=cluster)
-    except exception.NotFound as e:
-        LOG.error(_LE("Network not found, Error: %s"), str(e))
+    except exception.NotFound:
+        LOG.exception(_LE("Network not found."))
         raise exception.NetworkNotFound(net_id=lswitch_id)
 
 
@@ -162,8 +162,8 @@ def delete_networks(cluster, net_id, lswitch_ids):
         path = "/ws.v1/lswitch/%s" % ls_id
         try:
             nsxlib.do_request(HTTP_DELETE, path, cluster=cluster)
-        except exception.NotFound as e:
-            LOG.error(_LE("Network not found, Error: %s"), str(e))
+        except exception.NotFound:
+            LOG.exception(_LE("Network not found."))
             raise exception.NetworkNotFound(net_id=ls_id)
 
 
@@ -295,8 +295,8 @@ def get_port(cluster, network, port, relations=None):
         uri += "relations=%s" % relations
     try:
         return nsxlib.do_request(HTTP_GET, uri, cluster=cluster)
-    except exception.NotFound as e:
-        LOG.error(_LE("Port or Network not found, Error: %s"), str(e))
+    except exception.NotFound:
+        LOG.exception(_LE("Port or Network not found."))
         raise exception.PortNotFoundOnNetwork(
             port_id=port, net_id=network)
 
@@ -326,8 +326,8 @@ def update_port(cluster, lswitch_uuid, lport_uuid, neutron_port_id, tenant_id,
                   "on logical switch %(uuid)s",
                   {'result': result['uuid'], 'uuid': lswitch_uuid})
         return result
-    except exception.NotFound as e:
-        LOG.error(_LE("Port or Network not found, Error: %s"), str(e))
+    except exception.NotFound:
+        LOG.exception(_LE("Port or Network not found."))
         raise exception.PortNotFoundOnNetwork(
             port_id=lport_uuid, net_id=lswitch_uuid)
 
@@ -368,8 +368,8 @@ def get_port_status(cluster, lswitch_id, port_id):
         r = nsxlib.do_request(HTTP_GET,
                               "/ws.v1/lswitch/%s/lport/%s/status" %
                               (lswitch_id, port_id), cluster=cluster)
-    except exception.NotFound as e:
-        LOG.error(_LE("Port not found, Error: %s"), str(e))
+    except exception.NotFound:
+        LOG.exception(_LE("Port not found."))
         raise exception.PortNotFoundOnNetwork(
             port_id=port_id, net_id=lswitch_id)
     if r['link_status_up'] is True:
index 66b052a5a04b15aa6957fc8e0d0ad7805eb9a2b1..b332d4a957b12601506dcbb037fd475b6b1ea680 100644 (file)
@@ -35,8 +35,8 @@ class NeutronDB(object):
                 net_dict["id"] = str(net.uuid)
                 net_dict["name"] = net.name
                 nets.append(net_dict)
-        except Exception as exc:
-            LOG.error("Failed to get all networks: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to get all networks.")
         return nets
 
     def get_network(self, network_id):
@@ -50,8 +50,8 @@ class NeutronDB(object):
                 net_dict["id"] = str(net.uuid)
                 net_dict["name"] = net.name
                 net.append(net_dict)
-        except Exception as exc:
-            LOG.error("Failed to get network: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to get network.")
         return net
 
     def create_network(self, tenant_id, net_name):
@@ -64,8 +64,8 @@ class NeutronDB(object):
             net_dict["id"] = str(res.uuid)
             net_dict["name"] = res.name
             return net_dict
-        except Exception as exc:
-            LOG.error("Failed to create network: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to create network.")
 
     def delete_network(self, net_id):
         """Delete a network."""
@@ -75,8 +75,8 @@ class NeutronDB(object):
             net_dict = {}
             net_dict["id"] = str(net.uuid)
             return net_dict
-        except Exception as exc:
-            LOG.error("Failed to delete network: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to delete network.")
 
     def update_network(self, tenant_id, net_id, param_data):
         """Rename a network."""
@@ -87,8 +87,8 @@ class NeutronDB(object):
             net_dict["id"] = str(net.uuid)
             net_dict["name"] = net.name
             return net_dict
-        except Exception as exc:
-            LOG.error("Failed to update network: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to update network.")
 
     def get_all_ports(self, net_id):
         """Get all ports."""
@@ -103,8 +103,8 @@ class NeutronDB(object):
                 port_dict["state"] = port.state
                 ports.append(port_dict)
             return ports
-        except Exception as exc:
-            LOG.error("Failed to get all ports: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to get all ports.")
 
     def get_port(self, net_id, port_id):
         """Get a port."""
@@ -119,8 +119,8 @@ class NeutronDB(object):
             port_dict["state"] = port.state
             port_list.append(port_dict)
             return port_list
-        except Exception as exc:
-            LOG.error("Failed to get port: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to get port.")
 
     def create_port(self, net_id):
         """Add a port."""
@@ -133,8 +133,8 @@ class NeutronDB(object):
             port_dict["attachment"] = port.interface_id
             port_dict["state"] = port.state
             return port_dict
-        except Exception as exc:
-            LOG.error("Failed to create port: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to create port.")
 
     def delete_port(self, net_id, port_id):
         """Delete a port."""
@@ -144,8 +144,8 @@ class NeutronDB(object):
             port_dict = {}
             port_dict["id"] = str(port.uuid)
             return port_dict
-        except Exception as exc:
-            LOG.error("Failed to delete port: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to delete port.")
 
     def update_port(self, net_id, port_id, **kwargs):
         """Update a port."""
@@ -158,8 +158,8 @@ class NeutronDB(object):
             port_dict["attachment"] = port.interface_id
             port_dict["state"] = port.state
             return port_dict
-        except Exception as exc:
-            LOG.error("Failed to update port state: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to update port state.")
 
     def plug_interface(self, net_id, port_id, int_id):
         """Plug interface to a port."""
@@ -172,13 +172,13 @@ class NeutronDB(object):
             port_dict["attachment"] = port.interface_id
             port_dict["state"] = port.state
             return port_dict
-        except Exception as exc:
-            LOG.error("Failed to plug interface: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to plug interface.")
 
     def unplug_interface(self, net_id, port_id):
         """Unplug interface to a port."""
         try:
             db.port_unset_attachment(port_id, net_id)
             LOG.debug("Detached interface from port %s", port_id)
-        except Exception as exc:
-            LOG.error("Failed to unplug interface: %s", str(exc))
+        except Exception:
+            LOG.exception("Failed to unplug interface.")