From 734213b8e8177f505cd7d906a40402308c3bc205 Mon Sep 17 00:00:00 2001 From: Rohit Agarwalla Date: Fri, 24 Aug 2012 03:48:22 -0700 Subject: [PATCH] fixes cisco nexus plugin delete network issue Fixes bug 1039687 Removes the vlan from the nexus interface corresponding to the network that has been deleted. unit tests added. Change-Id: Ib58a01c7b5bbdd7aac8591b4fb4db123cbe8f55b --- .../cisco/nexus/cisco_nexus_plugin_v2.py | 11 +- .../cisco/nexus/cisco_nexus_snippets.py | 8 +- .../cisco/tests/unit/v2/test_nexus_plugin.py | 123 ++++++++++++++++++ 3 files changed, 132 insertions(+), 10 deletions(-) create mode 100644 quantum/plugins/cisco/tests/unit/v2/test_nexus_plugin.py diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py b/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py index a99785f26..e9ed3812e 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py @@ -100,9 +100,11 @@ class NexusPlugin(L2DevicePluginBase): """ LOG.debug("NexusPlugin:delete_network() called\n") vlan_id = None - context = kwargs[const.CONTEXT] - base_plugin_ref = kwargs[const.BASE_PLUGIN_REF] for key in kwargs: + if key == const.CONTEXT: + context = kwargs[const.CONTEXT] + if key == const.BASE_PLUGIN_REF: + base_plugin_ref = kwargs[const.BASE_PLUGIN_REF] if key == 'vlan_id': vlan_id = kwargs['vlan_id'] if vlan_id is None: @@ -111,13 +113,12 @@ class NexusPlugin(L2DevicePluginBase): ports_id = nxos_db.get_nexusport_binding(vlan_id) LOG.debug("NexusPlugin: Interfaces to be disassociated: %s" % ports_id) nxos_db.remove_nexusport_binding(vlan_id) - net = self._get_network(tenant_id, net_id, context, base_plugin_ref) - if net: + if net_id: self._client.delete_vlan( str(vlan_id), self._nexus_ip, self._nexus_username, self._nexus_password, self._nexus_ports, self._nexus_ssh_port) - return net + return net_id # Network not found raise exc.NetworkNotFound(net_id=net_id) diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py b/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py index 7983cb9f7..5bad67b90 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py @@ -125,19 +125,17 @@ CMD_NO_VLAN_INT_SNIPPET = """ %s <__XML__MODE_if-ethernet-switch> - - <__XML__BLK_Cmd_switchport_trunk_allowed_allow-vlans> - %s - + + %s + - diff --git a/quantum/plugins/cisco/tests/unit/v2/test_nexus_plugin.py b/quantum/plugins/cisco/tests/unit/v2/test_nexus_plugin.py new file mode 100644 index 000000000..4ef51c8c0 --- /dev/null +++ b/quantum/plugins/cisco/tests/unit/v2/test_nexus_plugin.py @@ -0,0 +1,123 @@ +# Copyright (c) 2012 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import logging +import unittest + +from quantum.common import exceptions as exc +from quantum.db import api as db +from quantum.plugins.cisco.common import cisco_constants as const +from quantum.plugins.cisco.common import cisco_credentials_v2 as creds +from quantum.plugins.cisco.db import network_db_v2 as cdb +from quantum.plugins.cisco.db import network_models_v2 +from quantum.plugins.cisco.nexus import cisco_nexus_plugin_v2 + + +LOG = logging.getLogger(__name__) + + +class TestNexusPlugin(unittest.TestCase): + + def setUp(self): + """ + Set up function + """ + self.tenant_id = "test_tenant_cisco1" + self.net_name = "test_network_cisco1" + self.net_id = 000007 + self.vlan_name = "q-" + str(self.net_id) + "vlan" + self.vlan_id = 267 + self.second_net_name = "test_network_cisco2" + self.second_net_id = 000005 + self.second_vlan_name = "q-" + str(self.second_net_id) + "vlan" + self.second_vlan_id = 265 + cdb.initialize() + creds.Store.initialize() + self._cisco_nexus_plugin = cisco_nexus_plugin_v2.NexusPlugin() + + def test_create_delete_network(self): + """ + Tests creation of two new Virtual Network. + Tests deletion of one Virtual Network. + This would result the following - + The Nexus device should have only one network + vlan configured on it's plugin configured + interfaces. + If running this test individually, run + test_nexus_clear_vlan after this test to clean + up the second vlan created by this test. + """ + LOG.debug("test_create_delete_network - START") + tenant_id = self.tenant_id + net_name = self.net_name + net_id = self.net_id + vlan_name = self.vlan_name + vlan_id = self.vlan_id + second_net_name = self.second_net_name + second_net_id = self.second_net_id + second_vlan_name = self.second_vlan_name + second_vlan_id = self.second_vlan_id + + new_net_dict = self._cisco_nexus_plugin.create_network( + tenant_id, net_name, net_id, + vlan_name, vlan_id, vlan_ids=str(vlan_id)) + + self.assertEqual(new_net_dict[const.NET_ID], net_id) + self.assertEqual(new_net_dict[const.NET_NAME], self.net_name) + self.assertEqual(new_net_dict[const.NET_VLAN_NAME], self.vlan_name) + self.assertEqual(new_net_dict[const.NET_VLAN_ID], self.vlan_id) + + vlan_ids = str(vlan_id) + "," + str(second_vlan_id) + new_net_dict = self._cisco_nexus_plugin.create_network( + tenant_id, second_net_name, second_net_id, + second_vlan_name, second_vlan_id, + vlan_ids=vlan_ids) + + self.assertEqual(new_net_dict[const.NET_ID], second_net_id) + self.assertEqual(new_net_dict[const.NET_NAME], self.second_net_name) + self.assertEqual(new_net_dict[const.NET_VLAN_NAME], + self.second_vlan_name) + self.assertEqual(new_net_dict[const.NET_VLAN_ID], self.second_vlan_id) + + netid = self._cisco_nexus_plugin.delete_network( + tenant_id, net_id, vlan_id=str(vlan_id)) + + self.assertEqual(netid, net_id) + + LOG.debug("test_create_delete_network - END") + + def test_nexus_clear_vlan(self): + """ + Test to clean up second vlan of nexus device + created by test_create_delete_network. This + test will fail if it is run individually. + """ + LOG.debug("test_nexus_clear_vlan - START") + tenant_id = self.tenant_id + second_net_id = self.second_net_id + second_vlan_id = self.second_vlan_id + + netid = self._cisco_nexus_plugin.delete_network( + tenant_id, second_net_id, + vlan_id=str(second_vlan_id)) + + self.assertEqual(netid, second_net_id) + + LOG.debug("test_nexus_clear_vlan - END") + + def tearDown(self): + """Clear the test environment""" + # Remove database contents + db.clear_db(network_models_v2.model_base.BASEV2) -- 2.45.2