diff --git a/nova/api/openstack/wsgi_app.py b/nova/api/openstack/wsgi_app.py index 3fef2df2bc57..bad600a0e08d 100644 --- a/nova/api/openstack/wsgi_app.py +++ b/nova/api/openstack/wsgi_app.py @@ -23,11 +23,13 @@ from nova import context from nova import exception from nova import objects from nova import service +from nova import utils CONF = cfg.CONF CONFIG_FILES = ['api-paste.ini', 'nova.conf'] +utils.monkey_patch() objects.register_all() diff --git a/nova/cmd/__init__.py b/nova/cmd/__init__.py index 1b1ddf772c12..8b0ed86cb74f 100644 --- a/nova/cmd/__init__.py +++ b/nova/cmd/__init__.py @@ -13,20 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import eventlet -from oslo_utils import importutils -from six.moves import reload_module +from nova import utils -from nova import debugger - -if debugger.enabled(): - # turn off thread patching to enable the remote debugger - eventlet.monkey_patch(os=False, thread=False) -else: - eventlet.monkey_patch(os=False) - -# NOTE(rgerganov): oslo.context is storing a global thread-local variable -# which keeps the request context for the current thread. If oslo.context is -# imported before calling monkey_patch(), then this thread-local won't be -# green. To workaround this, reload the module after calling monkey_patch() -reload_module(importutils.import_module('oslo_context.context')) +utils.monkey_patch() diff --git a/nova/utils.py b/nova/utils.py index 5c161987ef4e..eac44964e10e 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -48,8 +48,10 @@ from oslo_utils import timeutils from oslo_utils import units import six from six.moves import range +from six.moves import reload_module import nova.conf +from nova import debugger from nova import exception from nova.i18n import _, _LE, _LI, _LW import nova.network @@ -1296,3 +1298,18 @@ def generate_hostid(host, project_id): sha_hash = hashlib.sha224(data) return sha_hash.hexdigest() return "" + + +def monkey_patch(): + if debugger.enabled(): + # turn off thread patching to enable the remote debugger + eventlet.monkey_patch(os=False, thread=False) + else: + eventlet.monkey_patch(os=False) + + # NOTE(rgerganov): oslo.context is storing a global thread-local variable + # which keeps the request context for the current thread. If oslo.context + # is imported before calling monkey_patch(), then this thread-local won't + # be green. To workaround this, reload the module after calling + # monkey_patch() + reload_module(importutils.import_module('oslo_context.context'))