Merge "split monkey_patching form import"

This commit is contained in:
Zuul 2025-04-25 19:21:45 +00:00 committed by Gerrit Code Review
commit 4085069c23
6 changed files with 29 additions and 22 deletions

View File

@ -17,7 +17,9 @@
"""
WSGI middleware for OpenStack API controllers.
"""
import nova.monkey_patch # noqa
# autopep8: off
from nova import monkey_patch ; monkey_patch.patch() # noqa
# autopep8: on
from oslo_log import log as logging
import routes

View File

@ -12,5 +12,5 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import nova.monkey_patch # noqa
from nova import monkey_patch
monkey_patch.patch()

View File

@ -20,8 +20,16 @@
import os
MONKEY_PATCHED = False
def is_patched():
return MONKEY_PATCHED
def _monkey_patch():
if is_patched():
return
# NOTE(mdbooth): Anything imported here will not be monkey patched. It is
# important to take care not to import anything here which requires monkey
# patching.
@ -61,10 +69,13 @@ def _monkey_patch():
', '.join(problems))
# NOTE(mdbooth): This workaround is required to avoid breaking sphinx. See
# separate comment in doc/source/conf.py. It may also be useful for other
# non-nova utilities. Ideally the requirement for this workaround will be
# removed as soon as possible, so do not rely on, or extend it.
if (os.environ.get('OS_NOVA_DISABLE_EVENTLET_PATCHING', '').lower()
def patch():
# NOTE(mdbooth): This workaround is required to avoid breaking sphinx. See
# separate comment in doc/source/conf.py. It may also be useful for other
# non-nova utilities. Ideally the requirement for this workaround will be
# removed as soon as possible, so do not rely on, or extend it.
if (os.environ.get('OS_NOVA_DISABLE_EVENTLET_PATCHING', '').lower()
not in ('1', 'true', 'yes')):
_monkey_patch()
_monkey_patch()
global MONKEY_PATCHED
MONKEY_PATCHED = True

View File

@ -20,8 +20,9 @@ Allows overriding of flags for use of fakes, and some black magic for
inline callbacks.
"""
import nova.monkey_patch # noqa
# autopep8: off
from nova import monkey_patch ; monkey_patch.patch() # noqa
# autopep8: on
import abc
import builtins

View File

@ -58,6 +58,7 @@ from nova.db.api import api as api_db_api
from nova.db.main import api as main_db_api
from nova.db import migration
from nova import exception
from nova import monkey_patch
from nova import objects
from nova.objects import base as obj_base
from nova.objects import service as service_obj
@ -1919,7 +1920,7 @@ class ReaderWriterLock(lockutils.ReaderWriterLock):
"""
def __init__(self, *a, **kw):
eventlet_patched = eventlet.patcher.is_monkey_patched('thread')
eventlet_patched = monkey_patch.is_patched()
mpatch = fixtures.MonkeyPatch(
'threading.current_thread', eventlet.getcurrent)
with mpatch if eventlet_patched else contextlib.ExitStack():

View File

@ -11,13 +11,5 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
:mod:`functional` -- Nova functional tests
=====================================================
.. automodule:: nova.tests.functional
:platform: Unix
"""
import nova.monkey_patch # noqa
from nova import monkey_patch
monkey_patch.patch()