From: Robert Pothier Date: Wed, 3 Sep 2014 15:09:15 +0000 (-0400) Subject: ML2 Cisco Nexus MD: Fix UT to send one create vlan message X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=eacd1fc6b2cb3175f603cdd80d7b59dbe9b0719b;p=openstack-build%2Fneutron-build.git ML2 Cisco Nexus MD: Fix UT to send one create vlan message 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 --- diff --git a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py b/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py index e7d7d4583..2f355f6a3 100644 --- a/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py +++ b/neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py @@ -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.