]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Analyze re-raised exceptions in Cisco Plugin
authorPaul Michali <pcm@cisco.com>
Fri, 23 Aug 2013 15:47:24 +0000 (11:47 -0400)
committerPaul Michali <pcm@cisco.com>
Sat, 24 Aug 2013 06:34:43 +0000 (02:34 -0400)
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

neutron/plugins/cisco/db/n1kv_db_v2.py
neutron/plugins/cisco/network_plugin.py
neutron/plugins/cisco/nexus/cisco_nexus_network_driver_v2.py

index 4f47b1ced65d660642afb96c353a859418d1dd69..51b7c6a77cbf5149f4e0f68a4858b1f799807e7a 100644 (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):
index bfd5ad9e0f86df4d8c73a0e44d55e22c0ccd9e46..c0ef874eb4772e7ec3bd7b99affaaf0cfee64802 100644 (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."""
index bb0f8e6deca77df71e24639dbd35b631cbff6794..dd09e92f9425d217c52536f900314a1b2bc4b041 100644 (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]