]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix usage of save_and_reraise_exception
authorOleg Bondarev <obondarev@mirantis.com>
Wed, 19 Mar 2014 14:38:49 +0000 (18:38 +0400)
committerOleg Bondarev <obondarev@mirantis.com>
Wed, 19 Mar 2014 14:38:49 +0000 (18:38 +0400)
Set reraise=False for the cases where the purpose of exception
handler is to reraise proper type of exception

Change-Id: Id6595ba1e160b9033d519ded16e0fbd2f91ccb5d
Closes-Bug: #1288188

neutron/agent/l3_agent.py
neutron/db/dhcp_rpc_base.py
neutron/db/loadbalancer/loadbalancer_db.py
neutron/db/vpn/vpn_db.py

index 6fa97ea8cd1d239498bf1a401f1eb8496febdc96..aa3f3d1f46948310c82466338841e9dfd1728e05 100644 (file)
@@ -331,8 +331,9 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
                 self.context)
             return self.target_ex_net_id
         except rpc_common.RemoteError as e:
-            with excutils.save_and_reraise_exception():
+            with excutils.save_and_reraise_exception() as ctx:
                 if e.exc_type == 'TooManyExternalNetworks':
+                    ctx.reraise = False
                     msg = _(
                         "The 'gateway_external_network_id' option must be "
                         "configured for this agent as Neutron has more than "
index 953512d8383893b4b3bba815e2785ac16406c56b..106ad5ed7a04d277be0bf5d5388323caea9dfcbb 100644 (file)
@@ -59,8 +59,7 @@ class DhcpRpcCallbackMixin(object):
                 raise n_exc.Invalid(message=msg)
         except (db_exc.DBError, n_exc.NetworkNotFound,
                 n_exc.SubnetNotFound, n_exc.IpAddressGenerationFailure) as e:
-            with excutils.save_and_reraise_exception() as ctxt:
-                ctxt.reraise = False
+            with excutils.save_and_reraise_exception(reraise=False) as ctxt:
                 if isinstance(e, n_exc.IpAddressGenerationFailure):
                     # Check if the subnet still exists and if it does not,
                     # this is the reason why the ip address generation failed.
index cbff0ed0dbcc8af79e4bb0401e8c0bb4f8f9a471..4ed96de685573b553f1c42e9701a5fd9d4920c8b 100644 (file)
@@ -205,7 +205,7 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase,
         try:
             r = self._get_by_id(context, model, id)
         except exc.NoResultFound:
-            with excutils.save_and_reraise_exception():
+            with excutils.save_and_reraise_exception(reraise=False) as ctx:
                 if issubclass(model, Vip):
                     raise loadbalancer.VipNotFound(vip_id=id)
                 elif issubclass(model, Pool):
@@ -214,6 +214,7 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase,
                     raise loadbalancer.MemberNotFound(member_id=id)
                 elif issubclass(model, HealthMonitor):
                     raise loadbalancer.HealthMonitorNotFound(monitor_id=id)
+                ctx.reraise = True
         return r
 
     def assert_modification_allowed(self, obj):
index c750d8c4b72fdeccfea9dc234dde6f197fdb5385..056d956f3927ff7285784f19f4c6aed6c5bfc7c3 100644 (file)
@@ -179,7 +179,7 @@ class VPNPluginDb(VPNPluginBase, base_db.CommonDbMixin):
         try:
             r = self._get_by_id(context, model, v_id)
         except exc.NoResultFound:
-            with excutils.save_and_reraise_exception():
+            with excutils.save_and_reraise_exception(reraise=False) as ctx:
                 if issubclass(model, IPsecSiteConnection):
                     raise vpnaas.IPsecSiteConnectionNotFound(
                         ipsec_site_conn_id=v_id
@@ -190,6 +190,7 @@ class VPNPluginDb(VPNPluginBase, base_db.CommonDbMixin):
                     raise vpnaas.IPsecPolicyNotFound(ipsecpolicy_id=v_id)
                 elif issubclass(model, VPNService):
                     raise vpnaas.VPNServiceNotFound(vpnservice_id=v_id)
+                ctx.reraise = True
         return r
 
     def assert_update_allowed(self, obj):