From: Sergey Vilgelm Date: Mon, 24 Jun 2013 11:26:50 +0000 (+0400) Subject: Do not raise NEW exceptions X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3ecd1cbbc95f5dacfd6503818e2c00f394f2c82d;p=openstack-build%2Fneutron-build.git Do not raise NEW exceptions Raising NEW exception is bad practice, because we lose TraceBack. So all places like: except SomeException as e: raise e should be replaced by except SomeException: raise If we are doing some other actions before reraising we should store information about exception then do all actions and then reraise it. This is caused by eventlet bug. It lost information about exception if it switch threads. fixes bug 1191730 Change-Id: Id4aaadde7e69f0bc087cf6d96bb041d53feb131d --- diff --git a/quantum/db/db_base_plugin_v2.py b/quantum/db/db_base_plugin_v2.py index 225ad703a..3860a5b6c 100644 --- a/quantum/db/db_base_plugin_v2.py +++ b/quantum/db/db_base_plugin_v2.py @@ -29,6 +29,7 @@ from quantum.common import exceptions as q_exc from quantum.db import api as db from quantum.db import models_v2 from quantum.db import sqlalchemyutils +from quantum.openstack.common import excutils from quantum.openstack.common import log as logging from quantum.openstack.common import timeutils from quantum.openstack.common import uuidutils @@ -958,12 +959,12 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2, obj_creator = getattr(self, 'create_%s' % resource) objects.append(obj_creator(context, item)) context.session.commit() - except Exception as e: - LOG.exception(_("An exception occured while creating " + except Exception: + with excutils.save_and_reraise_exception(): + LOG.error(_("An exception occured while creating " "the %(resource)s:%(item)s"), {'resource': resource, 'item': item}) - context.session.rollback() - raise e + context.session.rollback() return objects def _get_marker_obj(self, context, resource, limit, marker): diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver_v2.py b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver_v2.py index b6d9f42d0..a92681a2e 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver_v2.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver_v2.py @@ -25,6 +25,7 @@ import logging from ncclient import manager +from quantum.openstack.common import excutils from quantum.plugins.cisco.common import cisco_exceptions as cexc from quantum.plugins.cisco.db import network_db_v2 as cdb from quantum.plugins.cisco.db import nexus_db_v2 @@ -113,13 +114,9 @@ class CiscoNEXUSDriver(): config=confstr, allowed_exc_strs=["Can't modify state for extended", "Command is only allowed on VLAN"]) - except cexc.NexusConfigFailed as e: - # Rollback VLAN creation - try: + except cexc.NexusConfigFailed: + with excutils.save_and_reraise_exception(): self.disable_vlan(mgr, vlanid) - finally: - # Re-raise original exception - raise e def disable_vlan(self, mgr, vlanid): """Delete a VLAN on Nexus Switch given the VLAN ID.""" diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py b/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py index 2ecf38197..f2acd9524 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py @@ -27,6 +27,7 @@ PlugIn for Nexus OS driver import logging from quantum.common import exceptions as exc +from quantum.openstack.common import excutils from quantum.openstack.common import importutils from quantum.plugins.cisco.common import cisco_constants as const from quantum.plugins.cisco.common import cisco_credentials_v2 as cred @@ -125,8 +126,8 @@ class NexusPlugin(L2DevicePluginBase): try: nxos_db.add_nexusport_binding(port_id, str(vlan_id), switch_ip, instance) - except Exception as e: - try: + except Exception: + with excutils.save_and_reraise_exception(): # Add binding failed, roll back any vlan creation/enabling if vlan_created: self._client.delete_vlan( @@ -137,9 +138,6 @@ class NexusPlugin(L2DevicePluginBase): self._client.disable_vlan_on_trunk_int(man, port_id, vlan_id) - finally: - # Raise the original exception - raise e new_net_dict = {const.NET_ID: net_id, const.NET_NAME: net_name, @@ -303,19 +301,16 @@ class NexusPlugin(L2DevicePluginBase): str(row['vlan_id']), _nexus_ip, _nexus_username, _nexus_password, _nexus_ports, _nexus_ssh_port) - except Exception as e: + except Exception: # The delete vlan operation on the Nexus failed, # so this delete_port request has failed. For # consistency, roll back the Nexus database to what # it was before this request. - try: + with excutils.save_and_reraise_exception(): nxos_db.add_nexusport_binding(row['port_id'], row['vlan_id'], row['switch_ip'], row['instance_id']) - finally: - # Raise the original exception - raise e return row['instance_id'] diff --git a/quantum/plugins/nicira/QuantumPlugin.py b/quantum/plugins/nicira/QuantumPlugin.py index 0c1419347..5fbea4b4b 100644 --- a/quantum/plugins/nicira/QuantumPlugin.py +++ b/quantum/plugins/nicira/QuantumPlugin.py @@ -51,6 +51,7 @@ from quantum.extensions import l3 from quantum.extensions import portsecurity as psec from quantum.extensions import providernet as pnet from quantum.extensions import securitygroup as ext_sg +from quantum.openstack.common import excutils from quantum.openstack.common import importutils from quantum.openstack.common import rpc from quantum.plugins.nicira.common import config # noqa @@ -1215,13 +1216,14 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2, LOG.warning(_("Network %s was not found in NVP."), port_data['network_id']) port_data['status'] = constants.PORT_STATUS_ERROR - except Exception as e: - # FIXME (arosen) or the plugin_interface call failed in which - # case we need to garbage collect the left over port in nvp. - err_msg = _("Unable to create port or set port attachment " - "in NVP.") - LOG.exception(err_msg) - raise e + except Exception: + with excutils.save_and_reraise_exception(): + # FIXME (arosen) or the plugin_interface call failed in + # which case we need to garbage collect the left over + # port in nvp. + err_msg = _("Unable to create port or set port " + "attachment in NVP.") + LOG.error(err_msg) LOG.debug(_("create_port completed on NVP for tenant " "%(tenant_id)s: (%(id)s)"), port_data) diff --git a/quantum/plugins/nicira/api_client/request.py b/quantum/plugins/nicira/api_client/request.py index 466b7ea01..d7bd03bfc 100644 --- a/quantum/plugins/nicira/api_client/request.py +++ b/quantum/plugins/nicira/api_client/request.py @@ -26,9 +26,11 @@ import logging import time import urlparse +from quantum.openstack.common import excutils from quantum.plugins.nicira.api_client.common import ( _conn_str) + logging.basicConfig(level=logging.INFO) LOG = logging.getLogger(__name__) @@ -122,9 +124,10 @@ class NvpApiRequest(object): try: conn.request(self._method, url, self._body, headers) except Exception as e: - LOG.warn(_("[%(rid)d] Exception issuing request: %(e)s"), - {'rid': self._rid(), 'e': e}) - raise e + with excutils.save_and_reraise_exception(): + LOG.warn(_("[%(rid)d] Exception issuing request: " + "%(e)s"), + {'rid': self._rid(), 'e': e}) response = conn.getresponse() response.body = response.read()