summaryrefslogtreecommitdiff
path: root/ironic_python_agent/tests
diff options
context:
space:
mode:
authorJavier Pena <jpena@redhat.com>2017-04-18 12:03:13 +0200
committerJavier Pena <jpena@redhat.com>2017-04-25 12:12:49 +0200
commit32ed01448bbd05fcea210ffd9ceb49ae2b09d4a5 (patch)
treebb262eb8a4e7b960cdc1a0eab38b2569d8787793 /ironic_python_agent/tests
parent92c33a0f477d7b1528beb2e143b326bf30a0f397 (diff)
downloadironic-python-agent-32ed01448bbd05fcea210ffd9ceb49ae2b09d4a5.tar.gz
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
Diffstat (limited to 'ironic_python_agent/tests')
-rw-r--r--ironic_python_agent/tests/unit/test_inspector.py13
1 files changed, 9 insertions, 4 deletions
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)