From 32ed01448bbd05fcea210ffd9ceb49ae2b09d4a5 Mon Sep 17 00:00:00 2001 From: Javier Pena Date: Tue, 18 Apr 2017 12:03:13 +0200 Subject: Set valid inspection_dhcp_wait_timeout value in tests inspection_dhcp_wait_timeout is defined as IntOpt, but its value was set in tests to 0.01. This was ok until oslo.config started enforcing types in [1], after that unit tests fail for test_timeout. Fixing by setting the value to 1, and mocking time-related functions to avoid a longer wait. [1] https://review.openstack.org/328692 Change-Id: I732c4aa3d1760c3159d9672e3fae81f8bd72497c --- ironic_python_agent/tests/unit/test_inspector.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'ironic_python_agent/tests') diff --git a/ironic_python_agent/tests/unit/test_inspector.py b/ironic_python_agent/tests/unit/test_inspector.py index 0847e581..179bf9f3 100644 --- a/ironic_python_agent/tests/unit/test_inspector.py +++ b/ironic_python_agent/tests/unit/test_inspector.py @@ -483,10 +483,12 @@ class TestWaitForDhcp(test_base.BaseTestCase): self.assertEqual(1, mocked_sleep.call_count) self.assertEqual(2, mocked_dispatch.call_count) - @mock.patch.object(inspector, '_DHCP_RETRY_INTERVAL', 0.01) - def test_timeout(self, mocked_dispatch): + @mock.patch.object(time, 'sleep', autospec=True) + @mock.patch.object(time, 'time', autospec=True, + side_effect=[1.0, 1.1, 3.1, 3.2]) + def test_timeout(self, mocked_time, mocked_sleep, mocked_dispatch): CONF.set_override('inspection_dhcp_all_interfaces', True) - CONF.set_override('inspection_dhcp_wait_timeout', 0.02) + CONF.set_override('inspection_dhcp_wait_timeout', 1) mocked_dispatch.return_value = [ hardware.NetworkInterface(name='em0', mac_addr='abcd', @@ -496,8 +498,11 @@ class TestWaitForDhcp(test_base.BaseTestCase): ] self.assertFalse(inspector.wait_for_dhcp()) - mocked_dispatch.assert_called_with('list_network_interfaces') + mocked_sleep.assert_called_once_with(inspector._DHCP_RETRY_INTERVAL) + # time.time() was called 3 times explicitly in wait_for_dhcp(), + # and 1 in LOG.warning() + self.assertEqual(4, mocked_time.call_count) def test_disabled(self, mocked_dispatch): CONF.set_override('inspection_dhcp_wait_timeout', 0) -- cgit v1.2.1