Mock out the correct greenthread sleep method

It seems at some point oslo_service loopingcall started using
eventletutils from oslo_utils to sleep during the loopingcall
retries, and some untittests started taking up to 40 seconds
to complete. This change mocks out the correct method offering
significant speedup to unittests' run time.

The EventletEvent class is introduced to eventletutils in version
3.38.0 so lower constraints are bumped as well.

Change-Id: Id7e6ff2a4748b5301e2259acdc760ac7f56b96c3
This commit is contained in:
Vladyslav Drok 2019-11-20 15:41:18 +01:00
parent 306aaccca6
commit 68a5e31a54
10 changed files with 37 additions and 28 deletions

View File

@ -27,7 +27,8 @@ ibmc_client = importutils.try_import('ibmc_client')
ibmc_error = importutils.try_import('ibmc_client.exceptions')
@mock.patch('eventlet.greenthread.sleep', lambda _t: None)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait',
lambda *args, **kwargs: None)
class IBMCPowerTestCase(base.IBMCTestCase):
def test_get_properties(self):
@ -183,7 +184,8 @@ class IBMCPowerTestCase(base.IBMCTestCase):
sorted(supported_power_states))
@mock.patch('eventlet.greenthread.sleep', lambda _t: None)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait',
lambda *args, **kwargs: None)
class IBMCPowerRebootTestCase(base.IBMCTestCase):
@mock.patch.object(ibmc_client, 'connect', autospec=True)

View File

@ -22,7 +22,8 @@ from ironic.tests.unit.drivers.modules.ibmc import base
ibmc_client = importutils.try_import('ibmc_client')
@mock.patch('eventlet.greenthread.sleep', lambda _t: None)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait',
lambda *args, **kwargs: None)
class IBMCVendorTestCase(base.IBMCTestCase):
def setUp(self):

View File

@ -50,7 +50,8 @@ class IRMCPowerInternalMethodsTestCase(test_common.BaseIRMCTest):
self.assertFalse(irmc_power._is_expected_power_state(
target_state, boot_status_value))
@mock.patch('eventlet.greenthread.sleep', lambda n: None)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait',
lambda *args, **kwargs: None)
@mock.patch('ironic.drivers.modules.irmc.power.snmp.SNMPClient',
spec_set=True, autospec=True)
def test__wait_power_state_soft_power_off(self, snmpclient_mock):
@ -69,7 +70,8 @@ class IRMCPowerInternalMethodsTestCase(test_common.BaseIRMCTest):
self.assertEqual(states.POWER_OFF, task.node.power_state)
self.assertEqual(states.NOSTATE, task.node.target_power_state)
@mock.patch('eventlet.greenthread.sleep', lambda n: None)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait',
lambda *args, **kwargs: None)
@mock.patch('ironic.drivers.modules.irmc.power.snmp.SNMPClient',
spec_set=True, autospec=True)
def test__wait_power_state_soft_reboot(self, snmpclient_mock):
@ -88,7 +90,8 @@ class IRMCPowerInternalMethodsTestCase(test_common.BaseIRMCTest):
self.assertEqual(states.POWER_ON, task.node.power_state)
self.assertEqual(states.NOSTATE, task.node.target_power_state)
@mock.patch('eventlet.greenthread.sleep', lambda n: None)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait',
lambda *args, **kwargs: None)
@mock.patch('ironic.drivers.modules.irmc.power.snmp.SNMPClient',
spec_set=True, autospec=True)
def test__wait_power_state_timeout(self, snmpclient_mock):

View File

@ -42,7 +42,8 @@ class NoBiosSystem(object):
resource=self)
@mock.patch('eventlet.greenthread.sleep', lambda _t: None)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait',
lambda *args, **kwargs: None)
class RedfishBiosTestCase(db_base.DbTestCase):
def setUp(self):

View File

@ -36,7 +36,8 @@ sushy = importutils.try_import('sushy')
INFO_DICT = db_utils.get_test_redfish_info()
@mock.patch('eventlet.greenthread.sleep', lambda _t: None)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait',
lambda *args, **kwargs: None)
class RedfishVirtualMediaBootTestCase(db_base.DbTestCase):
def setUp(self):

View File

@ -30,7 +30,8 @@ sushy = importutils.try_import('sushy')
INFO_DICT = db_utils.get_test_redfish_info()
@mock.patch('eventlet.greenthread.sleep', lambda _t: None)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait',
lambda *args, **kwargs: None)
class RedfishPowerTestCase(db_base.DbTestCase):
def setUp(self):

View File

@ -1348,7 +1348,7 @@ class IPMIToolPrivateMethodTestCase(Base):
kill_on_timeout=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
@mock.patch('eventlet.greenthread.sleep', autospec=True)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True)
def test__power_on_max_retries(self, sleep_mock, mock_exec):
self.config(command_retry_timeout=2, group='ipmi')
@ -1370,7 +1370,7 @@ class IPMIToolPrivateMethodTestCase(Base):
self.assertEqual(expected, mock_exec.call_args_list)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
@mock.patch('eventlet.greenthread.sleep', autospec=True)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True)
def test__soft_power_off(self, sleep_mock, mock_exec):
def side_effect(driver_info, command, **kwargs):
@ -1390,7 +1390,7 @@ class IPMIToolPrivateMethodTestCase(Base):
self.assertEqual(states.POWER_OFF, state)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
@mock.patch('eventlet.greenthread.sleep', autospec=True)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True)
def test__soft_power_off_max_retries(self, sleep_mock, mock_exec):
def side_effect(driver_info, command, **kwargs):
@ -1412,7 +1412,7 @@ class IPMIToolPrivateMethodTestCase(Base):
@mock.patch.object(ipmi, '_power_status', autospec=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
@mock.patch('eventlet.greenthread.sleep', autospec=True)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True)
def test___set_and_wait_no_needless_status_polling(
self, sleep_mock, mock_exec, mock_status):
# Check that if the call to power state change fails, it doesn't

View File

@ -747,7 +747,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_called_once_with(driver._snmp_oid())
self.assertEqual(states.POWER_OFF, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_on_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for the state to change following a power on
mock_client = mock_get_client.return_value
@ -761,7 +761,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_off_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for the state to change following a power off
mock_client = mock_get_client.return_value
@ -775,7 +775,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_OFF, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_on_invalid_state(self, mock_sleep, mock_get_client):
# Ensure driver retries when querying unexpected states following a
# power on
@ -790,7 +790,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_off_invalid_state(self, mock_sleep, mock_get_client):
# Ensure driver retries when querying unexpected states following a
# power off
@ -851,7 +851,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
driver.value_power_off)
mock_client.get.assert_called_once_with(driver._snmp_oid())
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_on_timeout(self, mock_sleep, mock_get_client):
# Ensure that a power on consistency poll timeout causes an error
mock_client = mock_get_client.return_value
@ -865,7 +865,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_off_timeout(self, mock_sleep, mock_get_client):
# Ensure that a power off consistency poll timeout causes an error
mock_client = mock_get_client.return_value
@ -894,7 +894,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_reset_off_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for the power off state change following a power
# reset
@ -911,7 +911,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_reset_on_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for the power on state change following a power
# reset
@ -928,7 +928,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_reset_off_delay_on_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for both state changes following a power reset
mock_client = mock_get_client.return_value
@ -945,7 +945,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_reset_off_invalid_state(self, mock_sleep, mock_get_client):
# Ensure driver retries when querying unexpected states following a
# power off during a reset
@ -960,7 +960,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_reset_on_invalid_state(self, mock_sleep, mock_get_client):
# Ensure driver retries when querying unexpected states following a
# power on during a reset
@ -977,7 +977,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_reset_off_timeout(self, mock_sleep, mock_get_client):
# Ensure that a power off consistency poll timeout during a reset
# causes an error
@ -992,7 +992,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep", autospec=True)
@mock.patch("oslo_utils.eventletutils.EventletEvent.wait", autospec=True)
def test_power_reset_on_timeout(self, mock_sleep, mock_get_client):
# Ensure that a power on consistency poll timeout during a reset
# causes an error

View File

@ -37,7 +37,7 @@ oslo.rootwrap==5.8.0
oslo.serialization==2.18.0
oslo.service==1.24.0
oslo.upgradecheck==0.1.0
oslo.utils==3.33.0
oslo.utils==3.38.0
oslo.versionedobjects==1.31.2
oslotest==3.2.0
osprofiler==1.5.0

View File

@ -29,7 +29,7 @@ oslo.reports>=1.18.0 # Apache-2.0
oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
oslo.service!=1.28.1,>=1.24.0 # Apache-2.0
oslo.upgradecheck>=0.1.0 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0
oslo.utils>=3.38.0 # Apache-2.0
osprofiler>=1.5.0 # Apache-2.0
os-traits>=0.4.0 # Apache-2.0
pecan!=1.0.2,!=1.0.3,!=1.0.4,!=1.2,>=1.0.0 # BSD