From 16b8a7cad9fb65478c65c00a5f26ca1417314ed0 Mon Sep 17 00:00:00 2001 From: Grzegorz Grasza Date: Thu, 17 Jul 2025 16:57:33 +0200 Subject: [PATCH] Remove eventlet dependency and migrate to threading This change removes eventlet dependency from Barbican and migrates to using threading-based execution instead. Signed-off-by: Grzegorz Grasza Change-Id: Ieb65928bbc1595d8f968c9d79117e0346dcb3733 --- barbican/cmd/keystone_listener.py | 26 +++++--------------- barbican/cmd/retry_scheduler.py | 18 +------------- barbican/cmd/worker.py | 23 +++++------------ barbican/common/config.py | 6 +++++ barbican/queue/__init__.py | 3 --- barbican/tests/queue/test_retry_scheduler.py | 15 +++++------ requirements.txt | 3 +-- 7 files changed, 28 insertions(+), 66 deletions(-) diff --git a/barbican/cmd/keystone_listener.py b/barbican/cmd/keystone_listener.py index 10975f12c..65498e266 100644 --- a/barbican/cmd/keystone_listener.py +++ b/barbican/cmd/keystone_listener.py @@ -15,35 +15,18 @@ # limitations under the License. """ -Barbican Keystone notification listener server. +Server startup application for barbican-keystone-listener """ - -import eventlet -import os import sys -# Oslo messaging notification server uses eventlet. -# -# To have remote debugging, thread module needs to be disabled. -# eventlet.monkey_patch(thread=False) -eventlet.monkey_patch() - -# 'Borrowed' from the Glance project: -# If ../barbican/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), - os.pardir, - os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'barbican', '__init__.py')): - sys.path.insert(0, possible_topdir) - - from barbican.common import config from barbican import queue from barbican.queue import keystone_listener from barbican import version from oslo_log import log +from oslo_service.backend import BackendType +from oslo_service.backend import init_backend from oslo_service import service @@ -56,6 +39,9 @@ def main(): try: config.setup_remote_pydev_debug() + # Ensure oslo.service uses the threading backend early + init_backend(BackendType.THREADING) + CONF = config.CONF CONF(sys.argv[1:], project='barbican', version=version.version_info.version_string) diff --git a/barbican/cmd/retry_scheduler.py b/barbican/cmd/retry_scheduler.py index 115cd03bd..f3f946a38 100644 --- a/barbican/cmd/retry_scheduler.py +++ b/barbican/cmd/retry_scheduler.py @@ -16,26 +16,10 @@ # limitations under the License. """ -Barbican worker server, running a periodic retry/scheduler process. +Server startup application for barbican-retry-scheduler """ - -import eventlet -import os import sys -# Oslo messaging RPC server uses eventlet. -eventlet.monkey_patch() - -# 'Borrowed' from the Glance project: -# If ../barbican/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), - os.pardir, - os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'barbican', '__init__.py')): - sys.path.insert(0, possible_topdir) - - from barbican.common import config from barbican import queue from barbican.queue import retry_scheduler diff --git a/barbican/cmd/worker.py b/barbican/cmd/worker.py index a5d8b6cc4..163d39ed2 100644 --- a/barbican/cmd/worker.py +++ b/barbican/cmd/worker.py @@ -16,32 +16,18 @@ # limitations under the License. """ -Barbican worker server. +Server startup application for barbican-worker """ - -import eventlet -import os import sys -# Oslo messaging RPC server uses eventlet. -eventlet.monkey_patch() - -# 'Borrowed' from the Glance project: -# If ../barbican/__init__.py exists, add ../ to Python search path, so that -# it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), - os.pardir, - os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'barbican', '__init__.py')): - sys.path.insert(0, possible_topdir) - - from barbican.common import config from barbican import queue from barbican.queue import server from barbican import version from oslo_log import log +from oslo_service.backend import BackendType +from oslo_service.backend import init_backend from oslo_service import service @@ -52,6 +38,9 @@ def fail(returncode, e): def main(): try: + # Ensure oslo.service uses the threading backend early + init_backend(BackendType.THREADING) + CONF = config.CONF CONF(sys.argv[1:], project='barbican', version=version.version_info.version_string) diff --git a/barbican/common/config.py b/barbican/common/config.py index b847895ed..0aa362658 100644 --- a/barbican/common/config.py +++ b/barbican/common/config.py @@ -24,6 +24,8 @@ from oslo_config import cfg from oslo_db import options as db_options from oslo_log import log from oslo_middleware import cors +from oslo_service.backend import BackendType +from oslo_service.backend import register_backend_default_hook from barbican import i18n as u import barbican.version @@ -322,6 +324,10 @@ CONF = new_config() LOG = logging.getLogger(__name__) parse_args(CONF) +# Register default backend hook to prefer threading if not initialized +# elsewhere +register_backend_default_hook(lambda: BackendType.THREADING) + # Adding global scope dict for all different configs created in various # modules. In barbican, each plugin module creates its own *new* config # instance so its error prone to share/access config values across modules diff --git a/barbican/queue/__init__.py b/barbican/queue/__init__.py index e7051e851..aa17e18d4 100644 --- a/barbican/queue/__init__.py +++ b/barbican/queue/__init__.py @@ -81,7 +81,6 @@ def get_server(target, endpoints, serializer=None): return messaging.get_rpc_server(TRANSPORT, target, endpoints, - executor='eventlet', serializer=serializer, access_policy=access_policy) @@ -110,8 +109,6 @@ def get_notification_server(targets, endpoints, serializer=None): TRANSPORT._require_driver_features(requeue=allow_requeue) dispatcher = notify_dispatcher.NotificationDispatcher(endpoints, serializer) - # we don't want blocking executor so use eventlet as executor choice return listener.NotificationServer(TRANSPORT, targets, dispatcher, - executor='eventlet', pool=pool_name, allow_requeue=allow_requeue) diff --git a/barbican/tests/queue/test_retry_scheduler.py b/barbican/tests/queue/test_retry_scheduler.py index 204516b11..3d7c637e6 100644 --- a/barbican/tests/queue/test_retry_scheduler.py +++ b/barbican/tests/queue/test_retry_scheduler.py @@ -14,7 +14,6 @@ import time from unittest import mock -import eventlet from oslo_utils import timeutils from barbican.model import models @@ -24,10 +23,6 @@ from barbican.tests import database_utils from barbican.tests import utils -# Oslo messaging RPC server uses eventlet. -eventlet.monkey_patch() - - INITIAL_DELAY_SECONDS = 5.0 NEXT_RETRY_SECONDS = 5.0 @@ -60,12 +55,16 @@ class WhenRunningPeriodicServerRetryLogic(database_utils.RepositoryTestCase): self.queue_client = mock.MagicMock() + self.timer_patcher = mock.patch( + 'oslo_service.threadgroup.ThreadGroup.add_dynamic_timer') + self.timer_patcher.start() + self.periodic_server = retry_scheduler.PeriodicServer( queue_resource=self.queue_client) def tearDown(self): super(WhenRunningPeriodicServerRetryLogic, self).tearDown() - self.periodic_server.stop() + self.timer_patcher.stop() def test_should_perform_retry_processing_no_tasks(self): interval = self.periodic_server._check_retry_tasks() @@ -185,7 +184,9 @@ class WhenRunningPeriodicServer(utils.BaseTestCase): def test_should_have_invoked_periodic_task_twice(self): # Wait a bit longer than the initial delay plus retry interval. - time.sleep(INITIAL_DELAY_SECONDS + 2 * NEXT_RETRY_SECONDS) + # Use a small epsilon to avoid crossing into a third invocation on + # slower runtimes (e.g., Python 3.10 scheduling jitter). + time.sleep(INITIAL_DELAY_SECONDS + 2 * NEXT_RETRY_SECONDS - 0.2) self.assertEqual(2, self.periodic_server.invoke_count) diff --git a/requirements.txt b/requirements.txt index b8c07d482..4db369d86 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,6 @@ alembic>=0.8.10 # MIT cffi>=1.7.0 # MIT cryptography>=2.1 # BSD/Apache-2.0 -eventlet>=0.27.0 # MIT jsonschema>=3.2.0 # MIT oslo.config>=6.4.0 # Apache-2.0 oslo.context>=2.22.0 # Apache-2.0 @@ -16,7 +15,7 @@ oslo.middleware>=3.31.0 # Apache-2.0 oslo.log>=4.3.0 # Apache-2.0 oslo.policy>=4.5.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 -oslo.service!=1.28.1,>=1.24.0 # Apache-2.0 +oslo.service[threading]>=4.2.0 # Apache-2.0 oslo.upgradecheck>=1.3.0 # Apache-2.0 oslo.utils>=7.0.0 # Apache-2.0 oslo.versionedobjects>=1.31.2 # Apache-2.0