Skip to content

Commit 32ed014

Browse files
committed
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
1 parent 92c33a0 commit 32ed014

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ironic_python_agent/tests/unit/test_inspector.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,12 @@ def test_boot_only(self, mocked_sleep, mocked_dispatch):
483483
self.assertEqual(1, mocked_sleep.call_count)
484484
self.assertEqual(2, mocked_dispatch.call_count)
485485

486-
@mock.patch.object(inspector, '_DHCP_RETRY_INTERVAL', 0.01)
487-
def test_timeout(self, mocked_dispatch):
486+
@mock.patch.object(time, 'sleep', autospec=True)
487+
@mock.patch.object(time, 'time', autospec=True,
488+
side_effect=[1.0, 1.1, 3.1, 3.2])
489+
def test_timeout(self, mocked_time, mocked_sleep, mocked_dispatch):
488490
CONF.set_override('inspection_dhcp_all_interfaces', True)
489-
CONF.set_override('inspection_dhcp_wait_timeout', 0.02)
491+
CONF.set_override('inspection_dhcp_wait_timeout', 1)
490492

491493
mocked_dispatch.return_value = [
492494
hardware.NetworkInterface(name='em0', mac_addr='abcd',
@@ -496,8 +498,11 @@ def test_timeout(self, mocked_dispatch):
496498
]
497499

498500
self.assertFalse(inspector.wait_for_dhcp())
499-
500501
mocked_dispatch.assert_called_with('list_network_interfaces')
502+
mocked_sleep.assert_called_once_with(inspector._DHCP_RETRY_INTERVAL)
503+
# time.time() was called 3 times explicitly in wait_for_dhcp(),
504+
# and 1 in LOG.warning()
505+
self.assertEqual(4, mocked_time.call_count)
501506

502507
def test_disabled(self, mocked_dispatch):
503508
CONF.set_override('inspection_dhcp_wait_timeout', 0)

0 commit comments

Comments
 (0)