import os
from oslo.config import cfg
+from sqlalchemy import exc as sql_exc
from sqlalchemy.orm import exc as sa_exc
import webob.exc
from neutron.extensions import portsecurity as psec
from neutron.extensions import providernet as pnet
from neutron.extensions import securitygroup as ext_sg
+from neutron.openstack.common.db import exception as db_exc
from neutron.openstack.common import excutils
from neutron.openstack.common import lockutils
from neutron.plugins.common import constants as plugin_const
context, port_data['id'],
selected_lswitch and selected_lswitch['uuid'],
lport and lport['uuid'])
+ except db_exc.DBError as e:
+ if (port_data['device_owner'] == constants.DEVICE_OWNER_DHCP and
+ isinstance(e.inner_exception, sql_exc.IntegrityError)):
+ msg = (_("Concurrent network deletion detected; Back-end Port "
+ "%(nsx_id)s creation to be rolled back for Neutron "
+ "port: %(neutron_id)s")
+ % {'nsx_id': lport['uuid'],
+ 'neutron_id': port_data['id']})
+ LOG.warning(msg)
+ if selected_lswitch and lport:
+ try:
+ nvplib.delete_port(self.cluster,
+ selected_lswitch['uuid'],
+ lport['uuid'])
+ except q_exc.NotFound:
+ LOG.debug(_("NSX Port %s already gone"), lport['uuid'])
def _nvp_delete_port(self, context, port_data):
# FIXME(salvatore-orlando): On the NVP platform we do not really have
import mock
import netaddr
from oslo.config import cfg
+from sqlalchemy import exc as sql_exc
import webob.exc
from neutron.api.v2 import attributes
from neutron.extensions import securitygroup as secgrp
from neutron import manager
from neutron.manager import NeutronManager
+from neutron.openstack.common.db import exception as db_exc
from neutron.openstack.common import uuidutils
from neutron.plugins.nicira.common import exceptions as nvp_exc
from neutron.plugins.nicira.common import sync
webob.exc.HTTPInternalServerError.code)
self._verify_no_orphan_left(net_id)
+ def test_create_port_db_error_no_orphan_left(self):
+ db_exception = db_exc.DBError(
+ inner_exception=sql_exc.IntegrityError(mock.ANY,
+ mock.ANY,
+ mock.ANY))
+ with mock.patch.object(nicira_db, 'add_neutron_nsx_port_mapping',
+ side_effect=db_exception):
+ with self.network() as net:
+ with self.port(device_owner='network:dhcp'):
+ self._verify_no_orphan_left(net['network']['id'])
+
def test_create_port_maintenance_returns_503(self):
with self.network() as net:
with mock.patch.object(nvplib, 'do_request',