]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: Fix foreign key constraint delete provider network
authorAaron Rosen <aaronorosen@gmail.com>
Mon, 8 Sep 2014 23:08:30 +0000 (16:08 -0700)
committerAaron Rosen <aaronorosen@gmail.com>
Mon, 27 Oct 2014 10:50:56 +0000 (03:50 -0700)
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
neutron/plugins/vmware/plugins/base.py
neutron/tests/unit/vmware/extensions/test_providernet.py

index 6326460046786c7d4f2ea842a166d221cd4ff977..67f516fbf75d011a65d9221db1ed527b19160031 100644 (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,
index c6a629a6af6953e1d2d9a8337ae724fc826c4b37..97ac72dcf8efc8d851a5ac2a5dcea1ea25f07962 100644 (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
index f6057f14511ed4efc7dec76234ac3f8a65c8e4e3..00738f06630bcc0bac04bba084af1321f1950657 100644 (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',