From b9baf7dbc8d1b32f7bf4bafe48da02ded32078be Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Thu, 2 Nov 2023 10:40:42 -0700 Subject: [PATCH] eventlet monkey patch in unit tests earlier It's important for consistent behavior to monkey_patch eventlet before importing anything. While it makes an attempt to green any existing created objects or locks, that code is buggy and fails in some cases -- especially around rlocks. It's not my belief that this resolves any specific bugs, but this does reflect a better overall practice. Change-Id: I57b2c91f9853287a08ee79ac87ae6e1767ddfb6f --- ironic/tests/unit/__init__.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ironic/tests/unit/__init__.py b/ironic/tests/unit/__init__.py index 9b42693939..96a25958c9 100644 --- a/ironic/tests/unit/__init__.py +++ b/ironic/tests/unit/__init__.py @@ -22,15 +22,20 @@ :platform: Unix """ -# TODO(tenbrae): move eventlet imports to ironic.__init__ once we move to PBR - import eventlet -from oslo_config import cfg -from oslo_log import log -from ironic import objects -eventlet.monkey_patch() +# NOTE(JayF): We must green all python stdlib modules before anything else +# is imported for consistent behavior. For instance, sqlalchemy +# creates a threading.RLock early, and if it was imported before +eventlet.monkey_patch() # noqa + + +from oslo_config import cfg # noqa E402 +from oslo_log import log # noqa E402 + +from ironic import objects # noqa E402 + log.register_options(cfg.CONF) log.setup(cfg.CONF, 'ironic')