]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Cisco plugin should check for switch - vlan bindings
authorArvind Somya <asomya@cisco.com>
Mon, 30 Sep 2013 17:56:59 +0000 (13:56 -0400)
committerArvind Somya <asomya@cisco.com>
Tue, 1 Oct 2013 14:00:22 +0000 (10:00 -0400)
This commit fixes the issue where the Cisco plugin tries to create a
vlan twice on a switch if the first create is not bound to a port.
Also fixes an issue where the plugin tried to untrunk vlans from
a port for SVI interfaces.

Change-Id: Ifb13eb65d667367cffe120e1761d34f09b6d356d
Fixes: Bug #1233300
neutron/plugins/cisco/nexus/cisco_nexus_plugin_v2.py
neutron/tests/unit/cisco/test_nexus_plugin.py

index 548ba260bdd76a0e135cc3a851d68124a42162bb..4b9306240c88eb5c14f61acbf5605cad55f89b3b 100644 (file)
@@ -103,6 +103,17 @@ class NexusPlugin(L2DevicePluginBase):
             vlan_created = False
             vlan_trunked = False
             eport_id = '%s:%s' % (etype, port_id)
+            # Check for switch vlan bindings
+            try:
+                # This vlan has already been created on this switch
+                # via another operation, like SVI bindings.
+                nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
+                vlan_created = True
+                auto_create = False
+            except cisco_exc.NexusPortBindingNotFound:
+                # No changes, proceed as normal
+                pass
+
             try:
                 nxos_db.get_port_vlan_switch_binding(eport_id, vlan_id,
                                                      switch_ip)
@@ -282,6 +293,7 @@ class NexusPlugin(L2DevicePluginBase):
             etype, nexus_port = '', ''
             if row['port_id'] == 'router':
                 etype, nexus_port = 'vlan', row['port_id']
+                auto_untrunk = False
             else:
                 etype, nexus_port = row['port_id'].split(':')
 
index a8507797d8b68e953aae7205ba348b1c3af84190..84e819f770bd150a6d066afeda00d9584da40a9b 100644 (file)
@@ -141,9 +141,9 @@ class TestCiscoNexusPlugin(base.BaseTestCase):
             db.configure_db()
 
         # Use a mock netconf client
-        mock_ncclient = mock.Mock()
+        self.mock_ncclient = mock.Mock()
         self.patch_obj = mock.patch.dict('sys.modules',
-                                         {'ncclient': mock_ncclient})
+                                         {'ncclient': self.mock_ncclient})
         self.patch_obj.start()
 
         with mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin,
@@ -261,8 +261,45 @@ class TestCiscoNexusPlugin(base.BaseTestCase):
                                                       subnet_id,
                                                       gateway_ip,
                                                       router_id)
+        try:
+            self.assertRaises(
+                cisco_exc.SubnetInterfacePresent,
+                self._cisco_nexus_plugin.add_router_interface,
+                vlan_name, vlan_id, subnet_id, gateway_ip, router_id)
+        finally:
+            self._cisco_nexus_plugin.remove_router_interface(vlan_id,
+                                                             router_id)
 
-        self.assertRaises(
-            cisco_exc.SubnetInterfacePresent,
-            self._cisco_nexus_plugin.add_router_interface,
-            vlan_name, vlan_id, subnet_id, gateway_ip, router_id)
+    def test_nexus_add_port_after_router_interface(self):
+        """Tests creating a port after a router interface.
+
+        Test creating a port after an SVI router interface has
+        been created. Only a trunk call should be invoked and the
+        plugin should not attempt to recreate the vlan.
+        """
+        vlan_name = self.vlan_name
+        vlan_id = self.vlan_id
+        gateway_ip = '10.0.0.1/24'
+        router_id = '00000R1'
+        subnet_id = '00001'
+
+        self._cisco_nexus_plugin.add_router_interface(vlan_name,
+                                                      vlan_id,
+                                                      subnet_id,
+                                                      gateway_ip,
+                                                      router_id)
+        # Create a network on the switch
+        self._cisco_nexus_plugin.create_network(
+            self.network1, self.attachment1)
+
+        # Grab a list of all mock calls from ncclient
+        last_cfgs = (self.mock_ncclient.manager.connect().
+                     edit_config.mock_calls)
+
+        # The last ncclient call should be for trunking and the second
+        # to last call should be creating the SVI interface
+        last_cfg = last_cfgs[-1][2]['config']
+        self.assertIn('allowed', last_cfg)
+
+        slast_cfg = last_cfgs[-2][2]['config']
+        self.assertIn('10.0.0.1/24', slast_cfg)