Provide single step check if eventlet is monkey_patched
Currently to perform such check we need to check if eventlet is available first, that give us two steps, but it is desired to check this at once. This change is to remove the function here: [1] https://github.com/openstack/oslo.messaging/blob/master/oslo_messaging/_drivers/pika_driver/pika_commons.py#L37 Also will be useful in zmq-driver. Change-Id: Ie24ecb54946bfba465d293185ebfda25691a8701
This commit is contained in:
parent
f082a5b859
commit
a99969ef8a
@ -127,3 +127,14 @@ def warn_eventlet_not_patched(expected_patched_modules=None,
|
||||
" spurious or unexpected lock-ups"
|
||||
" and/or hangs)" % (not_patched, what),
|
||||
RuntimeWarning, stacklevel=3)
|
||||
|
||||
|
||||
def is_monkey_patched(module):
|
||||
"""Determines safely is eventlet patching for module enabled or not
|
||||
:param module: String, module name
|
||||
:return Bool, True if module is patched, False otherwise
|
||||
"""
|
||||
|
||||
if _patcher is None:
|
||||
return False
|
||||
return _patcher.is_monkey_patched(module)
|
||||
|
@ -78,6 +78,17 @@ class EventletUtilsTest(test_base.BaseTestCase):
|
||||
eventletutils.warn_eventlet_not_patched(['os'])
|
||||
self.assertEqual(0, len(capture))
|
||||
|
||||
@mock.patch("oslo_utils.eventletutils._patcher")
|
||||
def test_eventlet_is_patched(self, mock_patcher):
|
||||
mock_patcher.is_monkey_patched.return_value = True
|
||||
self.assertTrue(eventletutils.is_monkey_patched('os'))
|
||||
mock_patcher.is_monkey_patched.return_value = False
|
||||
self.assertFalse(eventletutils.is_monkey_patched('os'))
|
||||
|
||||
@mock.patch("oslo_utils.eventletutils._patcher", None)
|
||||
def test_eventlet_no_patcher(self):
|
||||
self.assertFalse(eventletutils.is_monkey_patched('os'))
|
||||
|
||||
@mock.patch("oslo_utils.eventletutils._patcher")
|
||||
def test_partially_patched_warning(self, mock_patcher):
|
||||
is_patched = set()
|
||||
|
Loading…
Reference in New Issue
Block a user