summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGorka Eguileor <geguileo@redhat.com>2022-08-19 10:58:10 +0200
committerEric Harney <eharney@redhat.com>2022-09-21 16:57:56 -0400
commit81cde9def95afae3f039cce22c781ce3a6a3e28a (patch)
tree2718f80325072ce039cd12ab25ca14c3e954b472
parentfc9fd8a7ada48a1c2bc762b18814c1008b9f1df4 (diff)
downloadcinder-81cde9def95afae3f039cce22c781ce3a6a3e28a.tar.gz
Tests: Monkey patch before logs are loaded
Our tests don't do the eventlet monkey patching in the same way that the Cinder services -backup, scheduler, volume- do. This patch changes this by doing the monkey patching as soon as possible, before cinder OVOs are loaded and bring in a number of oslo libraries. When copying the initialization part from the Cinder commands a fix for 'current_thread' is also copied. Change-Id: I6c44d557466dfcb1f6507917eb88959e2ff388df (cherry picked from commit 81f117c55d8327df6cbea993be087a6de17641e3)
-rw-r--r--cinder/tests/unit/__init__.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/cinder/tests/unit/__init__.py b/cinder/tests/unit/__init__.py
index cff971fd9..9a999cb9f 100644
--- a/cinder/tests/unit/__init__.py
+++ b/cinder/tests/unit/__init__.py
@@ -22,12 +22,27 @@
:platform: Unix
"""
+import os
+
import eventlet
+# Monkey patching must go before the oslo.log import, otherwise
+# oslo.context will not use greenthread thread local and all greenthreads
+# will share the same context.
+if os.name == 'nt':
+ # eventlet monkey patching the os module causes subprocess.Popen to fail
+ # on Windows when using pipes due to missing non-blocking IO support.
+ eventlet.monkey_patch(os=False)
+else:
+ eventlet.monkey_patch()
+# Monkey patch the original current_thread to use the up-to-date _active
+# global variable. See https://bugs.launchpad.net/bugs/1863021 and
+# https://github.com/eventlet/eventlet/issues/592
+import __original_module_threading as orig_threading # pylint: disable=E0401
+import threading # noqa
+orig_threading.current_thread.__globals__['_active'] = threading._active
from cinder import objects
-eventlet.monkey_patch()
-
# NOTE(alaski): Make sure this is done after eventlet monkey patching otherwise
# the threading.local() store used in oslo_messaging will be initialized to
# threadlocal storage rather than greenthread local. This will cause context