diff --git a/oslo_utils/eventletutils.py b/oslo_utils/eventletutils.py index 2d2a299f..fc3080a0 100644 --- a/oslo_utils/eventletutils.py +++ b/oslo_utils/eventletutils.py @@ -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) diff --git a/oslo_utils/tests/test_eventletutils.py b/oslo_utils/tests/test_eventletutils.py index 28a30ffa..1b588d0f 100644 --- a/oslo_utils/tests/test_eventletutils.py +++ b/oslo_utils/tests/test_eventletutils.py @@ -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()