From 0dc5d9f77e0d14f57ead1f53b9e2ad0a68faf786 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Mon, 8 Sep 2014 16:08:30 -0700 Subject: [PATCH] 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 --- neutron/plugins/vmware/dbexts/db.py | 5 +++++ neutron/plugins/vmware/plugins/base.py | 1 + neutron/tests/unit/vmware/extensions/test_providernet.py | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/vmware/dbexts/db.py b/neutron/plugins/vmware/dbexts/db.py index 632646004..67f516fbf 100644 --- a/neutron/plugins/vmware/dbexts/db.py +++ b/neutron/plugins/vmware/dbexts/db.py @@ -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, diff --git a/neutron/plugins/vmware/plugins/base.py b/neutron/plugins/vmware/plugins/base.py index c6a629a6a..97ac72dcf 100644 --- a/neutron/plugins/vmware/plugins/base.py +++ b/neutron/plugins/vmware/plugins/base.py @@ -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 diff --git a/neutron/tests/unit/vmware/extensions/test_providernet.py b/neutron/tests/unit/vmware/extensions/test_providernet.py index f6057f145..00738f066 100644 --- a/neutron/tests/unit/vmware/extensions/test_providernet.py +++ b/neutron/tests/unit/vmware/extensions/test_providernet.py @@ -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', -- 2.45.2