From 0afb72e8831b8c46a3e3aa53addcc05617241a60 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Mon, 3 Nov 2025 11:58:38 +0100 Subject: [PATCH] Move monkey_patch from init to the entrypoints This move is needed so that we can define a per service default for monkey patching. And yes, the single line with both noqa and autopep8 decorators are needed to convince autopep8 that this code is OK to be at the start of the file. After moving the monkey_patching earlier in the wsgi entrypoint I needed to move the functional test monkey_patching call earlier too to keep the early enough for the test where the wsgi entry point is not directly imported Change-Id: Idedd2a440adc1cde1e8ffe6636854d5a891e66d2 Signed-off-by: Balazs Gibizer --- nova/api/openstack/__init__.py | 3 --- nova/cmd/__init__.py | 16 ---------------- nova/cmd/baseproxy.py | 3 +++ nova/cmd/compute.py | 3 +++ nova/cmd/conductor.py | 3 +++ nova/cmd/manage.py | 3 +++ nova/cmd/novncproxy.py | 3 +++ nova/cmd/policy.py | 3 +++ nova/cmd/scheduler.py | 3 +++ nova/cmd/serialproxy.py | 4 ++++ nova/cmd/spicehtml5proxy.py | 3 +++ nova/cmd/status.py | 3 +++ nova/test.py | 4 ---- nova/tests/functional/__init__.py | 17 +++++++++++++++++ nova/wsgi/metadata.py | 3 +++ nova/wsgi/osapi_compute.py | 3 +++ 16 files changed, 54 insertions(+), 23 deletions(-) diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index 74630165bc..58c77f2667 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -17,9 +17,6 @@ """ WSGI middleware for OpenStack API controllers. """ -# autopep8: off -from nova import monkey_patch ; monkey_patch.patch() # noqa -# autopep8: on from oslo_log import log as logging import routes diff --git a/nova/cmd/__init__.py b/nova/cmd/__init__.py index aad40a00f4..e69de29bb2 100644 --- a/nova/cmd/__init__.py +++ b/nova/cmd/__init__.py @@ -1,16 +0,0 @@ -# Copyright (c) 2019 Red Hat, Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -from nova import monkey_patch -monkey_patch.patch() diff --git a/nova/cmd/baseproxy.py b/nova/cmd/baseproxy.py index 9260df8323..9c8d298bce 100644 --- a/nova/cmd/baseproxy.py +++ b/nova/cmd/baseproxy.py @@ -16,6 +16,9 @@ """Base proxy module used to create compatible consoles for OpenStack Nova.""" +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on import os import sys diff --git a/nova/cmd/compute.py b/nova/cmd/compute.py index 58e765667b..5f4f83694f 100644 --- a/nova/cmd/compute.py +++ b/nova/cmd/compute.py @@ -15,6 +15,9 @@ # under the License. """Starter script for Nova Compute.""" +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on import shlex import sys diff --git a/nova/cmd/conductor.py b/nova/cmd/conductor.py index d4c260fb83..19b9576ef5 100644 --- a/nova/cmd/conductor.py +++ b/nova/cmd/conductor.py @@ -13,6 +13,9 @@ # under the License. """Starter script for Nova Conductor.""" +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on import sys diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index d55e4dbbc8..0c21ac7605 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -20,6 +20,9 @@ """ CLI interface for nova management. """ +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on import collections from contextlib import contextmanager diff --git a/nova/cmd/novncproxy.py b/nova/cmd/novncproxy.py index 7d4234ad10..de3b79fe3a 100644 --- a/nova/cmd/novncproxy.py +++ b/nova/cmd/novncproxy.py @@ -17,6 +17,9 @@ Websocket proxy that is compatible with OpenStack Nova noVNC consoles. Leverages websockify.py by Joel Martin """ +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on import sys diff --git a/nova/cmd/policy.py b/nova/cmd/policy.py index 4273463fd9..22aef3afe6 100644 --- a/nova/cmd/policy.py +++ b/nova/cmd/policy.py @@ -16,6 +16,9 @@ """ CLI interface for nova policy rule commands. """ +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on import functools import os diff --git a/nova/cmd/scheduler.py b/nova/cmd/scheduler.py index d96716974e..62a5c9750c 100644 --- a/nova/cmd/scheduler.py +++ b/nova/cmd/scheduler.py @@ -15,6 +15,9 @@ # under the License. """Starter script for Nova Scheduler.""" +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on import sys diff --git a/nova/cmd/serialproxy.py b/nova/cmd/serialproxy.py index 8b93abf2ee..c4f37f6223 100644 --- a/nova/cmd/serialproxy.py +++ b/nova/cmd/serialproxy.py @@ -17,6 +17,10 @@ Websocket proxy that is compatible with OpenStack Nova Serial consoles. Leverages websockify.py by Joel Martin. Based on nova-novncproxy. """ +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on + import sys from nova.cmd import baseproxy diff --git a/nova/cmd/spicehtml5proxy.py b/nova/cmd/spicehtml5proxy.py index 1365215be5..9e87b164ed 100644 --- a/nova/cmd/spicehtml5proxy.py +++ b/nova/cmd/spicehtml5proxy.py @@ -17,6 +17,9 @@ Websocket proxy that is compatible with OpenStack Nova SPICE HTML5 consoles. Leverages websockify.py by Joel Martin """ +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on import sys diff --git a/nova/cmd/status.py b/nova/cmd/status.py index e4ab21298c..cb656b890c 100644 --- a/nova/cmd/status.py +++ b/nova/cmd/status.py @@ -15,6 +15,9 @@ """ CLI interface for nova status commands. """ +# autopep8: off +from nova import monkey_patch; monkey_patch.patch() # noqa +# autopep8: on import functools import sys diff --git a/nova/test.py b/nova/test.py index eca3e2c151..27ef979d9a 100644 --- a/nova/test.py +++ b/nova/test.py @@ -20,10 +20,6 @@ Allows overriding of flags for use of fakes, and some black magic for inline callbacks. """ -# autopep8: off -from nova import monkey_patch ; monkey_patch.patch() # noqa -# autopep8: on - import abc import builtins import collections diff --git a/nova/tests/functional/__init__.py b/nova/tests/functional/__init__.py index e69de29bb2..c8712ebd08 100644 --- a/nova/tests/functional/__init__.py +++ b/nova/tests/functional/__init__.py @@ -0,0 +1,17 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# autopep8: off +from nova import monkey_patch ; monkey_patch.patch() # noqa +# autopep8: on diff --git a/nova/wsgi/metadata.py b/nova/wsgi/metadata.py index fec9ba1be8..f70598233a 100644 --- a/nova/wsgi/metadata.py +++ b/nova/wsgi/metadata.py @@ -11,6 +11,9 @@ # under the License. """WSGI application entry-point for Nova Metadata API.""" +# autopep8: off +from nova import monkey_patch ; monkey_patch.patch() # noqa +# autopep8: on import threading diff --git a/nova/wsgi/osapi_compute.py b/nova/wsgi/osapi_compute.py index 12403b746e..00e5f6fcba 100644 --- a/nova/wsgi/osapi_compute.py +++ b/nova/wsgi/osapi_compute.py @@ -11,6 +11,9 @@ # under the License. """WSGI application entry-point for Nova Compute API.""" +# autopep8: off +from nova import monkey_patch ; monkey_patch.patch() # noqa +# autopep8: on import threading