Avoid unnecessary explicit str() conversion around exceptions
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
This commit is contained in:
parent
bcb5675d92
commit
3a7c3f77b0
|
@ -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)
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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.")
|
||||
|
|
Loading…
Reference in New Issue