]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fixes cisco nexus plugin delete network issue
authorRohit Agarwalla <roagarwa@cisco.com>
Fri, 24 Aug 2012 10:48:22 +0000 (03:48 -0700)
committerRohit Agarwalla <roagarwa@cisco.com>
Fri, 24 Aug 2012 20:24:42 +0000 (13:24 -0700)
Fixes bug 1039687

Removes the vlan from the nexus interface corresponding to the network that has been deleted.
unit tests added.

Change-Id: Ib58a01c7b5bbdd7aac8591b4fb4db123cbe8f55b

quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py
quantum/plugins/cisco/nexus/cisco_nexus_snippets.py
quantum/plugins/cisco/tests/unit/v2/test_nexus_plugin.py [new file with mode: 0644]

index a99785f262bd5ec1a1e1daf3612eca8c35b17373..e9ed3812e8d4b5eb3aba8c3eba2f91e04f8d8c04 100644 (file)
@@ -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)
 
index 7983cb9f7ecfe3065ffe430b74ef04d16edcbb22..5bad67b90814d846bedf9ea329478e72ff98fc12 100644 (file)
@@ -125,19 +125,17 @@ CMD_NO_VLAN_INT_SNIPPET = """
               <interface>%s</interface>
               <__XML__MODE_if-ethernet-switch>
                 <switchport></switchport>
-                <no>
                 <switchport>
                   <trunk>
                     <allowed>
                       <vlan>
-                        <__XML__BLK_Cmd_switchport_trunk_allowed_allow-vlans>
-                          <allow-vlans>%s</allow-vlans>
-                        </__XML__BLK_Cmd_switchport_trunk_allowed_allow-vlans>
+                        <remove>
+                          <vlan>%s</vlan>
+                        </remove>
                       </vlan>
                     </allowed>
                   </trunk>
                 </switchport>
-               </no>
               </__XML__MODE_if-ethernet-switch>
             </ethernet>
           </interface>
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 (file)
index 0000000..4ef51c8
--- /dev/null
@@ -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)