diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 7b2fa3d87e1..ff3e2a9450d 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -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) diff --git a/neutron/db/migration/cli.py b/neutron/db/migration/cli.py index 96a0da705d0..5bd2eb30be0 100644 --- a/neutron/db/migration/cli.py +++ b/neutron/db/migration/cli.py @@ -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): diff --git a/neutron/plugins/bigswitch/servermanager.py b/neutron/plugins/bigswitch/servermanager.py index 6d473e3977f..b71c737619b 100644 --- a/neutron/plugins/bigswitch/servermanager.py +++ b/neutron/plugins/bigswitch/servermanager.py @@ -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, diff --git a/neutron/plugins/cisco/l3/hosting_device_drivers/csr1kv_hd_driver.py b/neutron/plugins/cisco/l3/hosting_device_drivers/csr1kv_hd_driver.py index 57e8b7ef1f8..189f5e27710 100644 --- a/neutron/plugins/cisco/l3/hosting_device_drivers/csr1kv_hd_driver.py +++ b/neutron/plugins/cisco/l3/hosting_device_drivers/csr1kv_hd_driver.py @@ -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 diff --git a/neutron/plugins/nec/packet_filter.py b/neutron/plugins/nec/packet_filter.py index d8d1240e4b1..9cb156537cc 100644 --- a/neutron/plugins/nec/packet_filter.py +++ b/neutron/plugins/nec/packet_filter.py @@ -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) diff --git a/neutron/plugins/nuage/syncmanager.py b/neutron/plugins/nuage/syncmanager.py index 13512f7c601..ef68b546c2b 100644 --- a/neutron/plugins/nuage/syncmanager.py +++ b/neutron/plugins/nuage/syncmanager.py @@ -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")) diff --git a/neutron/plugins/sriovnicagent/pci_lib.py b/neutron/plugins/sriovnicagent/pci_lib.py index 82be0d17902..f4108086c1f 100644 --- a/neutron/plugins/sriovnicagent/pci_lib.py +++ b/neutron/plugins/sriovnicagent/pci_lib.py @@ -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 diff --git a/neutron/plugins/vmware/check_nsx_config.py b/neutron/plugins/vmware/check_nsx_config.py index a063394c1bf..81368ecee5d 100644 --- a/neutron/plugins/vmware/check_nsx_config.py +++ b/neutron/plugins/vmware/check_nsx_config.py @@ -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) diff --git a/neutron/plugins/vmware/nsxlib/router.py b/neutron/plugins/vmware/nsxlib/router.py index 1b26dfc3679..89fee557b26 100644 --- a/neutron/plugins/vmware/nsxlib/router.py +++ b/neutron/plugins/vmware/nsxlib/router.py @@ -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) diff --git a/neutron/plugins/vmware/nsxlib/switch.py b/neutron/plugins/vmware/nsxlib/switch.py index 2a0e6924567..566c645e15c 100644 --- a/neutron/plugins/vmware/nsxlib/switch.py +++ b/neutron/plugins/vmware/nsxlib/switch.py @@ -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: diff --git a/neutron/tests/unit/database_stubs.py b/neutron/tests/unit/database_stubs.py index 66b052a5a04..b332d4a957b 100644 --- a/neutron/tests/unit/database_stubs.py +++ b/neutron/tests/unit/database_stubs.py @@ -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.")