From 10902f1da22d74dff62b1255c5d700f417b4a99b Mon Sep 17 00:00:00 2001 From: Abhishek Raut Date: Fri, 12 Sep 2014 19:56:40 -0700 Subject: [PATCH] Cisco N1kv: Remove vmnetwork delete REST call on last port delete 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 --- .../plugins/cisco/n1kv/n1kv_neutron_plugin.py | 2 -- .../tests/unit/cisco/n1kv/test_n1kv_plugin.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py index 236822d217..16c53660f5 100644 --- a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py +++ b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py @@ -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): """ diff --git a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py index e412dfc7e6..0a64ba1090 100644 --- a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py +++ b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py @@ -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):