]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
ML2 Cisco Nexus MD: Fix UT to send one create vlan message
authorRobert Pothier <rpothier@cisco.com>
Wed, 3 Sep 2014 15:09:15 +0000 (11:09 -0400)
committerRobert Pothier <rpothier@cisco.com>
Tue, 30 Sep 2014 14:17:41 +0000 (10:17 -0400)
With the commit of https://review.openstack.org/#/c/113009,
test_nexus_add_trunk needs to have the device_id set to
a unique value. Combining test_nexus_add_trunk and
test_nexus_enable_vlan_cmd to reduce duplicate code,
which fixes the original issue.

Change-Id: I4191a6880ec0f43365aacb638a92a0dd3e1e80aa
Closes-Bug: 1364976

neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py

index e7d7d45835f4bc1612972ada5035d6550799badf..2f355f6a3714cef8630cec2099c8359b176e909f 100644 (file)
@@ -354,61 +354,45 @@ class TestCiscoPortsV2(CiscoML2MechanismTestCase,
     def test_nexus_enable_vlan_cmd(self):
         """Verify the syntax of the command to enable a vlan on an intf.
 
-        Confirm that for the first VLAN configured on a Nexus interface,
-        the command string sent to the switch does not contain the
-        keyword 'add'.
-
-        Confirm that for the second VLAN configured on a Nexus interface,
-        the command string sent to the switch contains the keyword 'add'.
-
-        """
-        # First vlan should be configured without 'add' keyword
-        with self._create_resources():
-            self.assertTrue(self._is_vlan_configured(
-                vlan_creation_expected=True,
-                add_keyword_expected=False))
-            self.mock_ncclient.reset_mock()
-            self.mock_bound_segment.return_value = BOUND_SEGMENT2
-
-            # Second vlan should be configured with 'add' keyword
-            with self._create_resources(name=NETWORK_NAME_2,
-                                        device_id=DEVICE_ID_2,
-                                        cidr=CIDR_2):
-                self.assertTrue(self._is_vlan_configured(
-                    vlan_creation_expected=True,
-                    add_keyword_expected=True))
-
-            # Return to first segment for delete port calls.
-            self.mock_bound_segment.return_value = BOUND_SEGMENT1
-
-    def test_nexus_add_trunk(self):
-        """Verify syntax to enable a vlan on an interface.
-
-        Test also verifies that the vlan interface is not created.
-
         Test of the following ml2_conf_cisco_ini config:
         [ml2_mech_cisco_nexus:1.1.1.1]
         hostA=1/1
-        hostB=1/2
+        hostB=1/2 (second pass only)
         where vlan_id = 100
 
-        Confirm that for the first host configured on a Nexus interface,
+        Confirm that for the first VLAN configured on a Nexus interface,
         the command string sent to the switch does not contain the
         keyword 'add'.
 
-        Confirm that for the second host configured on a Nexus interface,
-        the command staring sent to the switch contains does not contain
-        the keyword 'name' [signifies vlan intf creation].
+        Confirm that for the second VLAN configured on a Nexus interface,
+        the command string sent to the switch contains the keyword 'add'
+        if it is on the same host. Confirm it does not contain the
+        keyword 'add' when on different hosts.
 
         """
-        with self._create_resources(name='net1', cidr=CIDR_1):
-            self.assertTrue(self._is_in_last_nexus_cfg(['allowed', 'vlan']))
-            self.assertFalse(self._is_in_last_nexus_cfg(['add']))
-            with self._create_resources(name='net2',
-                                        cidr=CIDR_2, host_id=COMP_HOST_NAME_2):
-                self.assertTrue(
-                    self._is_in_last_nexus_cfg(['allowed', 'vlan']))
-                self.assertFalse(self._is_in_last_nexus_cfg(['name']))
+        hosts = [COMP_HOST_NAME, COMP_HOST_NAME_2]
+        for host in hosts:
+            # First vlan should be configured without 'add' keyword
+            with self._create_resources():
+                self.assertTrue(self._is_vlan_configured(
+                    vlan_creation_expected=True,
+                    add_keyword_expected=False))
+                self.mock_ncclient.reset_mock()
+                self.mock_bound_segment.return_value = BOUND_SEGMENT2
+
+                # Second vlan should be configured with 'add' keyword
+                # when on a single host.
+                with self._create_resources(name=NETWORK_NAME_2,
+                    device_id=DEVICE_ID_2,
+                    cidr=CIDR_2,
+                    host_id=host):
+                    self.assertTrue(self._is_vlan_configured(
+                        vlan_creation_expected=True,
+                        add_keyword_expected=(host == COMP_HOST_NAME)
+                    ))
+
+                # Return to first segment for delete port calls.
+                self.mock_bound_segment.return_value = BOUND_SEGMENT1
 
     def test_ncclient_version_detect(self):
         """Test ability to handle connection to old and new-style ncclient.