Merge "VMware NSX: Fix db integrity error on dhcp port operations"

This commit is contained in:
Jenkins 2014-01-13 10:44:41 +00:00 committed by Gerrit Code Review
commit 68e13455de
2 changed files with 31 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import logging
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
@ -56,6 +57,7 @@ from neutron.extensions import portbindings as pbin
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
@ -490,6 +492,22 @@ class NvpPluginV2(addr_pair_db.AllowedAddressPairsMixin,
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

View File

@ -20,6 +20,7 @@ import contextlib
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
@ -36,6 +37,7 @@ from neutron.extensions import providernet as pnet
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
@ -250,6 +252,17 @@ class TestNiciraPortsV2(NiciraPluginV2TestCase,
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',