From 72ef7b352c161925ed8f87e0764794b596e44658 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 (cherry picked from commit 4e1c4cbcd71833095534bea9ff7617c582c300d2) --- .../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 236822d21..16c53660f 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 e412dfc7e..0a64ba109 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): -- 2.45.2