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
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
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):
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
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."""
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
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(
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,
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']
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
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)
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__)
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()