NSX: Fix foreign key constraint delete provider network

The cascade delete on the tz_network_bindings table is not
taking effect with the NSX plugin. In order to fix this, this
will require a db migration. This patch allows us to provide a
fix for this by deleting the tz_network_bindings within a transaction
to avoid the foreign key constraint. This patch fixes it this way so
that it can be backported to icehouse. Later a patch will be pushed with a
migration which corrects the db schema.

Closes-bug: #1367032

Change-Id: I19d389acc710224baff79ad114fab756b2e21cfc
This commit is contained in:
Aaron Rosen 2014-09-08 16:08:30 -07:00
parent e2be33f3b1
commit 0c7a28d7f6
3 changed files with 11 additions and 1 deletions

View File

@ -40,6 +40,11 @@ def get_network_bindings_by_vlanid(session, vlan_id):
all())
def delete_network_bindings(session, network_id):
return (session.query(models.TzNetworkBinding).
filter_by(network_id=network_id).delete())
def add_network_binding(session, network_id, binding_type, phy_uuid, vlan_id):
with session.begin(subtransactions=True):
binding = models.TzNetworkBinding(network_id, binding_type,

View File

@ -996,6 +996,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
context.session, self.cluster, id)
with context.session.begin(subtransactions=True):
self._process_l3_delete(context, id)
nsx_db.delete_network_bindings(context.session, id)
super(NsxPluginV2, self).delete_network(context, id)
# Do not go to NSX for external networks

View File

@ -14,6 +14,7 @@
# under the License.
from oslo.config import cfg
import webob.exc
from neutron.extensions import multiprovidernet as mpnet
from neutron.extensions import providernet as pnet
@ -23,7 +24,7 @@ from neutron.tests.unit.vmware import test_nsx_plugin
class TestProvidernet(test_nsx_plugin.NsxPluginV2TestCase):
def test_create_provider_network_default_physical_net(self):
def test_create_delete_provider_network_default_physical_net(self):
data = {'network': {'name': 'net1',
'admin_state_up': True,
'tenant_id': 'admin',
@ -33,6 +34,9 @@ class TestProvidernet(test_nsx_plugin.NsxPluginV2TestCase):
net = self.deserialize(self.fmt, network_req.get_response(self.api))
self.assertEqual(net['network'][pnet.NETWORK_TYPE], 'vlan')
self.assertEqual(net['network'][pnet.SEGMENTATION_ID], 411)
req = self.new_delete_request('networks', net['network']['id'])
res = req.get_response(self.api)
self.assertEqual(res.status_int, webob.exc.HTTPNoContent.code)
def test_create_provider_network(self):
data = {'network': {'name': 'net1',