username=username, password=password,
unknown_host_cb=nos_unknown_host_cb)
except Exception as e:
- LOG.error(_("Connect failed to switch: %s"), e)
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.error(_("Connect failed to switch: %s"), e)
LOG.debug(_("Connect success to host %(host)s:%(ssh_port)d"),
dict(host=host, ssh_port=SSH_PORT))
try:
super(MidonetPluginV2, self).delete_network(context, id)
except Exception:
- LOG.error(_('Failed to delete neutron db, while Midonet bridge=%r'
- 'had been deleted'), id)
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.error(_('Failed to delete neutron db, while Midonet '
+ 'bridge=%r had been deleted'), id)
def create_port(self, context, port):
"""Create a L2 port in Neutron/MidoNet."""
username=username, password=password,
unknown_host_cb=nos_unknown_host_cb)
except Exception:
- LOG.exception(_("Connect failed to switch"))
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_("Connect failed to switch"))
LOG.debug(_("Connect success to host %(host)s:%(ssh_port)d"),
dict(host=host, ssh_port=SSH_PORT))
LOG.debug(_("Committing transaction"))
break
except os_db.exception.DBError as e:
- if isinstance(e.inner_exception, sql_exc.IntegrityError):
- msg = _("A concurrent port creation has occurred")
- LOG.warning(msg)
- continue
- else:
- raise
+ with excutils.save_and_reraise_exception() as ctxt:
+ if isinstance(e.inner_exception, sql_exc.IntegrityError):
+ ctxt.reraise = False
+ msg = _("A concurrent port creation has occurred")
+ LOG.warning(msg)
+ continue
for port in ports:
try:
self.delete_port(context, port.id)
except Exception:
- LOG.exception(_("Exception auto-deleting port %s"),
- port.id)
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_("Exception auto-deleting port %s"),
+ port.id)
for subnet in subnets:
try:
self.delete_subnet(context, subnet.id)
except Exception:
- LOG.exception(_("Exception auto-deleting subnet %s"),
- subnet.id)
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_("Exception auto-deleting subnet %s"),
+ subnet.id)
try:
self.mechanism_manager.delete_network_postcommit(mech_context)
try:
self.delete_port(context, a.port_id)
except Exception:
- LOG.exception(_("Exception auto-deleting port %s"),
- a.port_id)
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_("Exception auto-deleting port %s"),
+ a.port_id)
try:
self.mechanism_manager.delete_subnet_postcommit(mech_context)
import socket
import time
+from neutron.openstack.common import excutils
from neutron.openstack.common import log as logging
from neutron.plugins.nec.common import config
from neutron.plugins.nec.common import exceptions as nexc
try:
return self.do_single_request(method, action, body)
except nexc.OFCServiceUnavailable as e:
- try:
- wait_time = int(e.retry_after)
- except (ValueError, TypeError):
- wait_time = None
- if i > 1 and wait_time:
- LOG.info(_("Waiting for %s seconds due to "
- "OFC Service_Unavailable."), wait_time)
- time.sleep(wait_time)
- continue
- raise
+ with excutils.save_and_reraise_exception() as ctxt:
+ try:
+ wait_time = int(e.retry_after)
+ except (ValueError, TypeError):
+ wait_time = None
+ if i > 1 and wait_time:
+ LOG.info(_("Waiting for %s seconds due to "
+ "OFC Service_Unavailable."), wait_time)
+ time.sleep(wait_time)
+ ctxt.reraise = False
+ continue
def get(self, action):
return self.do_request("GET", action)
from neutron.db import securitygroups_rpc_base as sg_db_rpc
from neutron.extensions import allowedaddresspairs as addr_pair
from neutron.extensions import portbindings
+from neutron.openstack.common import excutils
from neutron.openstack.common import importutils
from neutron.openstack.common import log as logging
from neutron.openstack.common import rpc
try:
self.ofc.delete_ofc_network(context, id, net_db)
except (nexc.OFCException, nexc.OFCMappingNotFound) as exc:
- reason = _("delete_network() failed due to %s") % exc
- LOG.error(reason)
- self._update_resource_status(context, "network", net_db['id'],
- const.NET_STATUS_ERROR)
- raise
+ with excutils.save_and_reraise_exception():
+ reason = _("delete_network() failed due to %s") % exc
+ LOG.error(reason)
+ self._update_resource_status(context, "network", net_db['id'],
+ const.NET_STATUS_ERROR)
super(NECPluginV2, self).delete_network(context, id)
from neutron.db import l3_gwmode_db
from neutron.db import models_v2
from neutron.extensions import l3
+from neutron.openstack.common import excutils
from neutron.openstack.common import importutils
from neutron.openstack.common import log as logging
from neutron.plugins.nec.common import config
try:
return driver.create_router(context, tenant_id, new_router)
except nexc.RouterOverLimit:
- super(RouterMixin, self).delete_router(context, new_router['id'])
- raise
+ with excutils.save_and_reraise_exception():
+ super(RouterMixin, self).delete_router(context,
+ new_router['id'])
def update_router(self, context, router_id, router):
LOG.debug(_("RouterMixin.update_router() called, "
from neutron.db import portbindings_base
from neutron.db import securitygroups_rpc_base as sg_db_rpc
from neutron.extensions import portbindings
+from neutron.openstack.common import excutils
from neutron.openstack.common import log as logging
from neutron.openstack.common import rpc
from neutron.openstack.common.rpc import proxy
try:
self._client_create_network(net['id'], tunnel_key)
except Exception:
- self._client_delete_network(net['id'])
- raise
+ with excutils.save_and_reraise_exception():
+ self._client_delete_network(net['id'])
return net
import neutron.db.api as db
from neutron.openstack.common.db import exception as db_exc
+from neutron.openstack.common import excutils
from neutron.openstack.common import log as logging
from neutron.plugins.vmware.dbexts import models
from neutron.plugins.vmware.dbexts import networkgw_db
session.add(mapping)
session.commit()
except db_exc.DBDuplicateEntry:
- session.rollback()
- # do not complain if the same exact mapping is being added, otherwise
- # re-raise because even though it is possible for the same neutron
- # port to map to different back-end ports over time, this should not
- # occur whilst a mapping already exists
- current = get_nsx_switch_and_port_id(session, neutron_id)
- if current[1] == nsx_port_id:
- LOG.debug(_("Port mapping for %s already available"), neutron_id)
- else:
- raise
+ with excutils.save_and_reraise_exception() as ctxt:
+ session.rollback()
+ # do not complain if the same exact mapping is being added,
+ # otherwise re-raise because even though it is possible for the
+ # same neutron port to map to different back-end ports over time,
+ # this should not occur whilst a mapping already exists
+ current = get_nsx_switch_and_port_id(session, neutron_id)
+ if current[1] == nsx_port_id:
+ LOG.debug(_("Port mapping for %s already available"),
+ neutron_id)
+ ctxt.reraise = False
except db_exc.DBError:
- # rollback for any other db error
- session.rollback()
- raise
+ with excutils.save_and_reraise_exception():
+ # rollback for any other db error
+ session.rollback()
return mapping
from neutron.common import exceptions as n_exc
from neutron.openstack.common.db import exception as db_exc
+from neutron.openstack.common import excutils
from neutron.openstack.common import log as logging
from neutron.plugins.vmware.api_client import exception as api_exc
from neutron.plugins.vmware.common import exceptions as p_exc
context, network_id, raise_on_err=raise_on_err)
return obj.lsn_id if obj else None
except p_exc.LsnNotFound:
- if self.sync_on_missing:
- lsn_id = super(PersistentLsnManager, self).lsn_get(
- context, network_id, raise_on_err=raise_on_err)
- self.lsn_save(context, network_id, lsn_id)
- return lsn_id
- if raise_on_err:
- raise
+ with excutils.save_and_reraise_exception() as ctxt:
+ ctxt.reraise = False
+ if self.sync_on_missing:
+ lsn_id = super(PersistentLsnManager, self).lsn_get(
+ context, network_id, raise_on_err=raise_on_err)
+ self.lsn_save(context, network_id, lsn_id)
+ return lsn_id
+ if raise_on_err:
+ ctxt.reraise = True
def lsn_save(self, context, network_id, lsn_id):
"""Save LSN-Network mapping to the DB."""
try:
self.lsn_save(context, network_id, lsn_id)
except p_exc.NsxPluginException:
- super(PersistentLsnManager, self).lsn_delete(context, lsn_id)
- raise
+ with excutils.save_and_reraise_exception():
+ super(PersistentLsnManager, self).lsn_delete(context, lsn_id)
return lsn_id
def lsn_delete(self, context, lsn_id):
context, subnet_id, raise_on_err=raise_on_err)
return (obj.lsn_id, obj.lsn_port_id) if obj else (None, None)
except p_exc.LsnPortNotFound:
- if self.sync_on_missing:
- lsn_id, lsn_port_id = (
- super(PersistentLsnManager, self).lsn_port_get(
- context, network_id, subnet_id,
- raise_on_err=raise_on_err))
- mac_addr = lsn_api.lsn_port_info_get(
- self.cluster, lsn_id, lsn_port_id)['mac_address']
- self.lsn_port_save(
- context, lsn_port_id, subnet_id, mac_addr, lsn_id)
- return (lsn_id, lsn_port_id)
- if raise_on_err:
- raise
+ with excutils.save_and_reraise_exception() as ctxt:
+ ctxt.reraise = False
+ if self.sync_on_missing:
+ lsn_id, lsn_port_id = (
+ super(PersistentLsnManager, self).lsn_port_get(
+ context, network_id, subnet_id,
+ raise_on_err=raise_on_err))
+ mac_addr = lsn_api.lsn_port_info_get(
+ self.cluster, lsn_id, lsn_port_id)['mac_address']
+ self.lsn_port_save(
+ context, lsn_port_id, subnet_id, mac_addr, lsn_id)
+ return (lsn_id, lsn_port_id)
+ if raise_on_err:
+ ctxt.reraise = True
def lsn_port_get_by_mac(self, context, network_id, mac, raise_on_err=True):
try:
context, mac, raise_on_err=raise_on_err)
return (obj.lsn_id, obj.lsn_port_id) if obj else (None, None)
except p_exc.LsnPortNotFound:
- if self.sync_on_missing:
- lsn_id, lsn_port_id = (
- super(PersistentLsnManager, self).lsn_port_get_by_mac(
- context, network_id, mac,
- raise_on_err=raise_on_err))
- subnet_id = lsn_api.lsn_port_info_get(
- self.cluster, lsn_id, lsn_port_id).get('subnet_id')
- self.lsn_port_save(
- context, lsn_port_id, subnet_id, mac, lsn_id)
- return (lsn_id, lsn_port_id)
- if raise_on_err:
- raise
+ with excutils.save_and_reraise_exception() as ctxt:
+ ctxt.reraise = False
+ if self.sync_on_missing:
+ lsn_id, lsn_port_id = (
+ super(PersistentLsnManager, self).lsn_port_get_by_mac(
+ context, network_id, mac,
+ raise_on_err=raise_on_err))
+ subnet_id = lsn_api.lsn_port_info_get(
+ self.cluster, lsn_id, lsn_port_id).get('subnet_id')
+ self.lsn_port_save(
+ context, lsn_port_id, subnet_id, mac, lsn_id)
+ return (lsn_id, lsn_port_id)
+ if raise_on_err:
+ ctxt.reraise = True
def lsn_port_save(self, context, lsn_port_id, subnet_id, mac_addr, lsn_id):
"""Save LSN Port information to the DB."""
self.lsn_port_save(context, lsn_port_id, subnet_info['subnet_id'],
subnet_info['mac_address'], lsn_id)
except p_exc.NsxPluginException:
- super(PersistentLsnManager, self).lsn_port_delete(
- context, lsn_id, lsn_port_id)
- raise
+ with excutils.save_and_reraise_exception():
+ super(PersistentLsnManager, self).lsn_port_delete(
+ context, lsn_id, lsn_port_id)
return lsn_port_id
def lsn_port_delete(self, context, lsn_id, lsn_port_id):
from neutron.db import db_base_plugin_v2
from neutron.db import l3_db
from neutron.extensions import external_net
+from neutron.openstack.common import excutils
from neutron.openstack.common import log as logging
from neutron.plugins.vmware.common import exceptions as p_exc
from neutron.plugins.vmware.dhcp_meta import constants as d_const
try:
handler(context, network_id, subnet_id, host_data)
except p_exc.PortConfigurationError:
- if action == 'create_port':
- db_base_plugin_v2.NeutronDbPluginV2.delete_port(
- plugin, context, port['id'])
- raise
+ with excutils.save_and_reraise_exception():
+ if action == 'create_port':
+ db_base_plugin_v2.NeutronDbPluginV2.delete_port(
+ plugin, context, port['id'])
LOG.info(_("DHCP for port %s configured successfully"), port['id'])
try:
handler(context, network_id, subnet_id, host_data)
except p_exc.PortConfigurationError:
- if not is_delete:
- db_base_plugin_v2.NeutronDbPluginV2.delete_port(
- plugin, context, port['id'])
- raise
+ with excutils.save_and_reraise_exception():
+ if not is_delete:
+ db_base_plugin_v2.NeutronDbPluginV2.delete_port(
+ plugin, context, port['id'])
LOG.info(_("Metadata for port %s configured successfully"), port['id'])
plugin.lsn_manager.lsn_metadata_configure(
context, subnet_id, is_enabled)
except p_exc.NsxPluginException:
- if is_enabled:
- l3_db.L3_NAT_db_mixin.remove_router_interface(
- plugin, context, router_id, interface)
- raise
+ with excutils.save_and_reraise_exception():
+ if is_enabled:
+ l3_db.L3_NAT_db_mixin.remove_router_interface(
+ plugin, context, router_id, interface)
LOG.info(_("Metadata for router %s handled successfully"), router_id)
from neutron.common import constants
from neutron.common import exceptions
+from neutron.openstack.common import excutils
from neutron.openstack.common import log
from neutron.plugins.vmware.common import utils
from neutron.plugins.vmware.nsxlib import _build_uri_path
try:
do_request(HTTP_DELETE, path, cluster=cluster)
except exceptions.NotFound:
- # This is not necessarily an error condition
- LOG.warn(_("Unable to find security profile %s on NSX backend"),
- spid)
- raise
+ with excutils.save_and_reraise_exception():
+ # This is not necessarily an error condition
+ LOG.warn(_("Unable to find security profile %s on NSX backend"),
+ spid)
# Ensure this method is executed only once
self._is_default_net_gw_in_sync = True
except Exception:
- LOG.exception(_("Unable to process default l2 gw service:%s"),
- def_l2_gw_uuid)
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_("Unable to process default l2 gw service:%s"),
+ def_l2_gw_uuid)
def _build_ip_address_list(self, context, fixed_ips, subnet_ids=None):
"""Build ip_addresses data structure for logical router port.
destination_ip_addresses=internal_ip)
except api_exc.NsxApiException:
- LOG.exception(_("An error occurred while removing NAT rules "
- "on the NSX platform for floating ip:%s"),
- floating_ip_address)
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_("An error occurred while removing NAT rules "
+ "on the NSX platform for floating ip:%s"),
+ floating_ip_address)
except nsx_exc.NatRuleMismatch:
# Do not surface to the user
LOG.warning(_("An incorrect number of matching NAT rules "
"resource was not found"),
{'neutron_id': device_id, 'nsx_id': nsx_device_id})
except api_exc.NsxApiException:
- LOG.exception(_("Removal of gateway device: %(neutron_id)s "
- "failed on NSX backend (NSX id:%(nsx_id)s). "
- "Neutron and NSX states have diverged."),
- {'neutron_id': device_id,
- 'nsx_id': nsx_device_id})
- # In this case a 500 should be returned
- raise
+ with excutils.save_and_reraise_exception():
+ # In this case a 500 should be returned
+ LOG.exception(_("Removal of gateway device: %(neutron_id)s "
+ "failed on NSX backend (NSX id:%(nsx_id)s). "
+ "Neutron and NSX states have diverged."),
+ {'neutron_id': device_id,
+ 'nsx_id': nsx_device_id})
def create_security_group(self, context, security_group, default_sg=False):
"""Create security group.
self.vcns_driver.update_ipsec_config(
edge_id, sites, enabled=vpn_service.admin_state_up)
except exceptions.VcnsBadRequest:
- LOG.exception(_("Bad or unsupported Input request!"))
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_("Bad or unsupported Input request!"))
except exceptions.VcnsApiException:
- msg = (_("Failed to update ipsec VPN configuration "
- "with vpnservice: %(vpnservice_id)s on vShield Edge: "
- "%(edge_id)s") % {'vpnservice_id': vpnservice_id,
- 'edge_id': edge_id})
- LOG.exception(msg)
- raise
+ with excutils.save_and_reraise_exception():
+ msg = (_("Failed to update ipsec VPN configuration "
+ "with vpnservice: %(vpnservice_id)s on vShield Edge: "
+ "%(edge_id)s") % {'vpnservice_id': vpnservice_id,
+ 'edge_id': edge_id})
+ LOG.exception(msg)
def create_vpnservice(self, context, vpnservice):
LOG.debug(_("create_vpnservice() called"))
# License for the specific language governing permissions and limitations
# under the License.
+from neutron.openstack.common import excutils
from neutron.openstack.common import log as logging
from neutron.plugins.vmware.vshield.common import (
exceptions as vcns_exc)
try:
self.vcns.update_ipsec_config(edge_id, ipsec_config)
except vcns_exc.VcnsApiException:
- LOG.exception(_("Failed to update ipsec vpn configuration "
- "with edge_id: %s"), edge_id)
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_("Failed to update ipsec vpn configuration "
+ "with edge_id: %s"), edge_id)
def delete_ipsec_config(self, edge_id):
try:
except vcns_exc.ResourceNotFound:
LOG.warning(_("IPsec config not found on edge: %s"), edge_id)
except vcns_exc.VcnsApiException:
- LOG.exception(_("Failed to delete ipsec vpn configuration "
- "with edge_id: %s"), edge_id)
- raise
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_("Failed to delete ipsec vpn configuration "
+ "with edge_id: %s"), edge_id)
def get_ipsec_config(self, edge_id):
return self.vcns.get_ipsec_config(edge_id)