From f240f77b582d4167729725180c96e0d4f81e125e Mon Sep 17 00:00:00 2001 From: Clinton Knight <cknight@netapp.com> Date: Tue, 13 Sep 2016 09:25:16 -0400 Subject: [PATCH] Fix flaky Neutron port binding unit tests A couple unit tests were attempting to test a wrapped method, and the tests failed randomly. It is straightforward, and preferable, to test the code with the decorator as it is called during normal operation. Change-Id: If0b92adcf974b4509424912f5fde1cf26ebfaf48 Closes-bug: #1622998 --- .../network/neutron/test_neutron_plugin.py | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/manila/tests/network/neutron/test_neutron_plugin.py b/manila/tests/network/neutron/test_neutron_plugin.py index 55682b619f..e994a9ddbb 100644 --- a/manila/tests/network/neutron/test_neutron_plugin.py +++ b/manila/tests/network/neutron/test_neutron_plugin.py @@ -691,7 +691,7 @@ class NeutronBindNetworkPluginTest(test.TestCase): self.mock_object(self.bind_plugin.neutron_api, 'show_port') self.bind_plugin.neutron_api.show_port.return_value = fake_neut_port - self.assertRaises(exception.ManilaException, + self.assertRaises(exception.NetworkException, self.bind_plugin._wait_for_ports_bind, [fake_neut_port, fake_neut_port], fake_share_server) @@ -701,19 +701,17 @@ class NeutronBindNetworkPluginTest(test.TestCase): self.sleep_mock.assert_not_called() @ddt.data(('DOWN', 'ACTIVE'), ('DOWN', 'DOWN'), ('ACTIVE', 'DOWN')) - @mock.patch.object(time, 'time', side_effect=[1, 1, 3]) - def test_wait_for_bind_two_ports_no_bind(self, state, time_mock): + def test_wait_for_bind_two_ports_no_bind(self, state): fake_neut_port1 = copy.copy(fake_neutron_port) fake_neut_port1['status'] = state[0] fake_neut_port2 = copy.copy(fake_neutron_port) fake_neut_port2['status'] = state[1] self.mock_object(self.bind_plugin.neutron_api, 'show_port') - self.bind_plugin.neutron_api.show_port.side_effect = [fake_neut_port1, - fake_neut_port2] + self.bind_plugin.neutron_api.show_port.side_effect = ( + [fake_neut_port1, fake_neut_port2] * 20) - self.assertRaises(exception.ManilaException, - self.bind_plugin._wait_for_ports_bind.__wrapped__, - self.bind_plugin, + self.assertRaises(exception.NetworkBindException, + self.bind_plugin._wait_for_ports_bind, [fake_neut_port1, fake_neut_port2], fake_share_server) @@ -1231,7 +1229,7 @@ class NeutronBindSingleNetworkPluginTest(test.TestCase): self.mock_object(self.bind_plugin.neutron_api, 'show_port') self.bind_plugin.neutron_api.show_port.return_value = fake_neut_port - self.assertRaises(exception.ManilaException, + self.assertRaises(exception.NetworkException, self.bind_plugin._wait_for_ports_bind, [fake_neut_port, fake_neut_port], fake_share_server) @@ -1241,19 +1239,17 @@ class NeutronBindSingleNetworkPluginTest(test.TestCase): self.sleep_mock.assert_not_called() @ddt.data(('DOWN', 'ACTIVE'), ('DOWN', 'DOWN'), ('ACTIVE', 'DOWN')) - @mock.patch.object(time, 'time', side_effect=[1, 1, 3]) - def test_wait_for_bind_two_ports_no_bind(self, state, time_mock): + def test_wait_for_bind_two_ports_no_bind(self, state): fake_neut_port1 = copy.copy(fake_neutron_port) fake_neut_port1['status'] = state[0] fake_neut_port2 = copy.copy(fake_neutron_port) fake_neut_port2['status'] = state[1] self.mock_object(self.bind_plugin.neutron_api, 'show_port') - self.bind_plugin.neutron_api.show_port.side_effect = [fake_neut_port1, - fake_neut_port2] + self.bind_plugin.neutron_api.show_port.side_effect = ( + [fake_neut_port1, fake_neut_port2] * 20) self.assertRaises(exception.NetworkBindException, - self.bind_plugin._wait_for_ports_bind.__wrapped__, - self.bind_plugin, + self.bind_plugin._wait_for_ports_bind, [fake_neut_port1, fake_neut_port2], fake_share_server)