Merge "Trivial: mock sleep in introspection tests"
This commit is contained in:
commit
2c82cc93f1
@ -12,7 +12,9 @@
|
||||
# limitations under the License.
|
||||
|
||||
import datetime
|
||||
import time
|
||||
|
||||
import fixtures
|
||||
import futurist
|
||||
import mock
|
||||
from oslo_concurrency import lockutils
|
||||
@ -190,6 +192,8 @@ class NodeTest(InventoryTest):
|
||||
started_at=datetime.datetime(1, 1, 1),
|
||||
node=self.node, ports=self.ports)
|
||||
self.node_info.node = mock.Mock(return_value=self.node)
|
||||
self.sleep_fixture = self.useFixture(
|
||||
fixtures.MockPatchObject(time, 'sleep', autospec=True))
|
||||
|
||||
|
||||
class NodeStateTest(NodeTest):
|
||||
|
@ -14,7 +14,6 @@
|
||||
import collections
|
||||
import time
|
||||
|
||||
import eventlet
|
||||
from ironicclient import exceptions
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
@ -48,7 +47,6 @@ class BaseTest(test_base.NodeTest):
|
||||
return cli
|
||||
|
||||
|
||||
@mock.patch.object(eventlet.greenthread, 'sleep', lambda _: None)
|
||||
@mock.patch.object(firewall, 'update_filters', autospec=True)
|
||||
@mock.patch.object(node_cache, 'start_introspection', autospec=True)
|
||||
@mock.patch.object(ir_utils, 'get_client', autospec=True)
|
||||
@ -266,9 +264,8 @@ class TestIntrospect(BaseTest):
|
||||
self.assertFalse(start_mock.called)
|
||||
self.assertFalse(self.node_info.acquire_lock.called)
|
||||
|
||||
@mock.patch.object(time, 'sleep')
|
||||
@mock.patch.object(time, 'time')
|
||||
def test_introspection_delay(self, time_mock, sleep_mock, client_mock,
|
||||
def test_introspection_delay(self, time_mock, client_mock,
|
||||
start_mock, filters_mock):
|
||||
time_mock.return_value = 42
|
||||
introspect._LAST_INTROSPECTION_TIME = 40
|
||||
@ -279,7 +276,7 @@ class TestIntrospect(BaseTest):
|
||||
|
||||
introspect.introspect(self.uuid)
|
||||
|
||||
sleep_mock.assert_called_once_with(8)
|
||||
self.sleep_fixture.mock.assert_called_once_with(8)
|
||||
cli.node.set_boot_device.assert_called_once_with(self.uuid,
|
||||
'pxe',
|
||||
persistent=False)
|
||||
@ -288,11 +285,11 @@ class TestIntrospect(BaseTest):
|
||||
# updated to the current time.time()
|
||||
self.assertEqual(42, introspect._LAST_INTROSPECTION_TIME)
|
||||
|
||||
@mock.patch.object(time, 'sleep')
|
||||
@mock.patch.object(time, 'time')
|
||||
def test_introspection_delay_not_needed(self, time_mock, sleep_mock,
|
||||
client_mock, start_mock,
|
||||
filters_mock):
|
||||
def test_introspection_delay_not_needed(
|
||||
self, time_mock, client_mock,
|
||||
start_mock, filters_mock):
|
||||
|
||||
time_mock.return_value = 100
|
||||
introspect._LAST_INTROSPECTION_TIME = 40
|
||||
CONF.set_override('introspection_delay', 10)
|
||||
@ -302,7 +299,7 @@ class TestIntrospect(BaseTest):
|
||||
|
||||
introspect.introspect(self.uuid)
|
||||
|
||||
self.assertFalse(sleep_mock.called)
|
||||
self.sleep_fixture.mock().assert_not_called()
|
||||
cli.node.set_boot_device.assert_called_once_with(self.uuid,
|
||||
'pxe',
|
||||
persistent=False)
|
||||
@ -311,11 +308,9 @@ class TestIntrospect(BaseTest):
|
||||
# updated to the current time.time()
|
||||
self.assertEqual(100, introspect._LAST_INTROSPECTION_TIME)
|
||||
|
||||
@mock.patch.object(time, 'sleep')
|
||||
@mock.patch.object(time, 'time')
|
||||
def test_introspection_delay_custom_drivers(self, time_mock, sleep_mock,
|
||||
client_mock, start_mock,
|
||||
filters_mock):
|
||||
def test_introspection_delay_custom_drivers(
|
||||
self, time_mock, client_mock, start_mock, filters_mock):
|
||||
self.node.driver = 'foobar'
|
||||
time_mock.return_value = 42
|
||||
introspect._LAST_INTROSPECTION_TIME = 40
|
||||
@ -327,7 +322,7 @@ class TestIntrospect(BaseTest):
|
||||
|
||||
introspect.introspect(self.uuid)
|
||||
|
||||
sleep_mock.assert_called_once_with(8)
|
||||
self.sleep_fixture.mock.assert_called_once_with(8)
|
||||
cli.node.set_boot_device.assert_called_once_with(self.uuid,
|
||||
'pxe',
|
||||
persistent=False)
|
||||
|
Loading…
Reference in New Issue
Block a user