From 8df4ac798e3decdad58330c1e78855d4c182210b Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Wed, 22 Jun 2016 21:17:22 -0700 Subject: [PATCH] NSX|V: fix broken unit tests Commit 1af862791ef83d2d67d71a4db6d37b919accb3d5 broke us. A general run of thumb is that in most cases when tests rely on IP's/MAC's we should set the enable_dhcp=False. The reason for this is that the upstream code does not have the DHCP port automatically allocated. Change-Id: Ibc762b17e256faa03c00eeeab75aefaa16e08592 --- vmware_nsx/tests/unit/nsx_v/test_plugin.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vmware_nsx/tests/unit/nsx_v/test_plugin.py b/vmware_nsx/tests/unit/nsx_v/test_plugin.py index 43cd542542..7118d5b459 100644 --- a/vmware_nsx/tests/unit/nsx_v/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v/test_plugin.py @@ -674,6 +674,20 @@ class TestPortsV2(NsxVPluginV2TestCase, VIF_TYPE = nsx_constants.VIF_TYPE_DVS HAS_PORT_FILTER = True + def test_duplicate_mac_generation(self): + # simulate duplicate mac generation to make sure DBDuplicate is retried + responses = ['12:34:56:78:00:00', '12:34:56:78:00:00', + '12:34:56:78:00:01'] + with mock.patch('neutron.common.utils.get_random_mac', + side_effect=responses) as grand_mac: + with self.subnet(enable_dhcp=False) as s: + with self.port(subnet=s) as p1, self.port(subnet=s) as p2: + self.assertEqual('12:34:56:78:00:00', + p1['port']['mac_address']) + self.assertEqual('12:34:56:78:00:01', + p2['port']['mac_address']) + self.assertEqual(3, grand_mac.call_count) + def test_get_ports_count(self): with self.port(), self.port(), self.port(), self.port() as p: tenid = p['port']['tenant_id']