]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Cisco N1kv: Remove vmnetwork delete REST call on last port delete
authorAbhishek Raut <abhraut@cisco.com>
Sat, 13 Sep 2014 02:56:40 +0000 (19:56 -0700)
committerAbhishek Raut <abhraut@cisco.com>
Sat, 18 Oct 2014 09:17:09 +0000 (02:17 -0700)
Remove the vm network delete call to the VSM on final port call and
ensure that vm network is deleted from the database when the port count
becomes 0.

Change-Id: I6c08a099adfce2fdba8eefec6aadeb68a780ac37
Closes-Bug: 1373547
(cherry picked from commit 4e1c4cbcd71833095534bea9ff7617c582c300d2)

neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py
neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py

index 236822d2173aea2c2053af0dec73c3a6f52764ef..16c53660f598f1991208eadd506128b05adf4b7a 100644 (file)
@@ -847,8 +847,6 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
         LOG.debug(_('_send_delete_port_request: %s'), port['id'])
         n1kvclient = n1kv_client.Client()
         n1kvclient.delete_n1kv_port(vm_network['name'], port['id'])
-        if vm_network['port_count'] == 0:
-            n1kvclient.delete_vm_network(vm_network['name'])
 
     def _get_segmentation_id(self, context, id):
         """
index e412dfc7e68d86dc0e3f8fbf598d00edf06f9a07..0a64ba1090956ed2b6a71a0bcc692e277fa575ae 100644 (file)
@@ -793,6 +793,24 @@ class TestN1kvPorts(test_plugin.TestPortsV2,
             # for network object clean up to succeed.
             client_patch.stop()
 
+    def test_delete_last_port_vmnetwork_cleanup(self):
+        """Test whether VMNetwork is cleaned up from db on last port delete."""
+        db_session = db.get_session()
+        with self.port() as port:
+            pt = port['port']
+            self.assertIsNotNone(n1kv_db_v2.
+                                 get_vm_network(db_session,
+                                                pt['n1kv:profile_id'],
+                                                pt['network_id']))
+            req = self.new_delete_request('ports', port['port']['id'])
+            req.get_response(self.api)
+            # Verify VMNetwork is cleaned up from the database on port delete.
+            self.assertRaises(c_exc.VMNetworkNotFound,
+                              n1kv_db_v2.get_vm_network,
+                              db_session,
+                              pt['n1kv:profile_id'],
+                              pt['network_id'])
+
 
 class TestN1kvPolicyProfiles(N1kvPluginTestCase):
     def setUp(self):