Analyze re-raised exceptions in Cisco Plugin

Checked all cases of re-raised exceptions. In several cases, the exception
was redundant (re-raising the same exception), so the try block and
exception handling was removed.

In one case, exceptions raised from two sources were re-raised with a
a different exception. Instead of doing this, the original exceptions
were changed and the try block and re-raised exception were removed.

In cases where there were database exceptions that were re-raised as
Neutron exceptions, the traceback was left as-is, since it was more
informative to know the higher level source of the issue.

The same was true for the exception mentioned in the bug, where the
original failure was in the ncclient library parsing the configuration
and it would be more descriptive to know that there was a connection
failure or a config failure, that to know the library method.

bug 1213159

Change-Id: Ie334d2548bf651c61e878bf797adaf8c5880eb86
This commit is contained in:
Paul Michali 2013-08-23 11:47:24 -04:00
parent a34f6f0e86
commit cf1af8d282
3 changed files with 14 additions and 38 deletions

View File

@ -269,7 +269,8 @@ def reserve_vlan(db_session, network_profile):
physical_network = alloc.physical_network
alloc.allocated = True
return (physical_network, segment_type, segment_id, "0.0.0.0")
raise q_exc.NoNetworkAvailable()
raise c_exc.NoMoreNetworkSegments(
network_profile_name=network_profile.name)
def reserve_vxlan(db_session, network_profile):
@ -297,7 +298,8 @@ def reserve_vxlan(db_session, network_profile):
alloc.allocated = True
return (physical_network, segment_type,
segment_id, get_multicast_ip(network_profile))
raise q_exc.NoNetworkAvailable()
raise c_exc.NoMoreNetworkSegments(
network_profile_name=network_profile.name)
def alloc_network(db_session, network_profile_id):
@ -310,14 +312,10 @@ def alloc_network(db_session, network_profile_id):
with db_session.begin(subtransactions=True):
network_profile = get_network_profile(db_session,
network_profile_id)
try:
if network_profile.segment_type == c_const.NETWORK_TYPE_VLAN:
return reserve_vlan(db_session, network_profile)
else:
return reserve_vxlan(db_session, network_profile)
except q_exc.NoNetworkAvailable:
raise c_exc.NoMoreNetworkSegments(
network_profile_name=network_profile.name)
if network_profile.segment_type == c_const.NETWORK_TYPE_VLAN:
return reserve_vlan(db_session, network_profile)
else:
return reserve_vxlan(db_session, network_profile)
def reserve_specific_vlan(db_session, physical_network, vlan_id):
@ -908,10 +906,7 @@ class NetworkProfile_db_mixin(object):
profile dictionary. Only these fields will be returned
:returns: network profile dictionary
"""
try:
profile = get_network_profile(context.session, id)
except exc.NoResultFound:
raise c_exc.NetworkProfileIdNotFound(profile_id=id)
profile = get_network_profile(context.session, id)
return self._make_network_profile_dict(profile, fields)
def get_network_profiles(self, context, filters=None, fields=None):
@ -1087,10 +1082,7 @@ class PolicyProfile_db_mixin(object):
profile dictionary. Only these fields will be returned
:returns: policy profile dictionary
"""
try:
profile = get_policy_profile(context.session, id)
except exc.NoResultFound:
raise c_exc.PolicyProfileIdNotFound(profile_id=id)
profile = get_policy_profile(context.session, id)
return self._make_policy_profile_dict(profile, fields)
def get_policy_profiles(self, context, filters=None, fields=None):

View File

@ -281,12 +281,7 @@ class PluginV2(db_base_plugin_v2.NeutronDbPluginV2):
def get_qos_details(self, tenant_id, qos_id):
"""Get QoS Details."""
LOG.debug(_("get_qos_details() called"))
try:
qos_level = cdb.get_qos(tenant_id, qos_id)
except Exception:
raise cexc.QosNotFound(tenant_id=tenant_id,
qos_id=qos_id)
return qos_level
return cdb.get_qos(tenant_id, qos_id)
def create_qos(self, tenant_id, qos_name, qos_desc):
"""Create a QoS level."""
@ -297,23 +292,12 @@ class PluginV2(db_base_plugin_v2.NeutronDbPluginV2):
def delete_qos(self, tenant_id, qos_id):
"""Delete a QoS level."""
LOG.debug(_("delete_qos() called"))
try:
cdb.get_qos(tenant_id, qos_id)
except Exception:
raise cexc.QosNotFound(tenant_id=tenant_id,
qos_id=qos_id)
return cdb.remove_qos(tenant_id, qos_id)
def rename_qos(self, tenant_id, qos_id, new_name):
"""Rename QoS level."""
LOG.debug(_("rename_qos() called"))
try:
cdb.get_qos(tenant_id, qos_id)
except Exception:
raise cexc.QosNotFound(tenant_id=tenant_id,
qos_id=qos_id)
qos = cdb.update_qos(tenant_id, qos_id, new_name)
return qos
return cdb.update_qos(tenant_id, qos_id, new_name)
def get_all_credentials(self):
"""Get all credentials."""

View File

@ -71,7 +71,7 @@ class CiscoNEXUSDriver():
break
else:
# Raise a Neutron exception. Include a description of
# the original ncclient exception.
# the original ncclient exception. No need to preserve T/B
raise cexc.NexusConfigFailed(config=config, exc=e)
def get_credential(self, nexus_ip):
@ -107,7 +107,7 @@ class CiscoNEXUSDriver():
self.connections[nexus_host] = man
except Exception as e:
# Raise a Neutron exception. Include a description of
# the original ncclient exception.
# the original ncclient exception. No need to preserve T/B.
raise cexc.NexusConnectFailed(nexus_host=nexus_host, exc=e)
return self.connections[nexus_host]