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 <xek@redhat.com>
Change-Id: Ieb65928bbc1595d8f968c9d79117e0346dcb3733
This commit is contained in:
Grzegorz Grasza
2025-08-18 13:40:38 +02:00
parent bfd1e72bf0
commit 16b8a7cad9
7 changed files with 28 additions and 66 deletions
+6 -20
View File
@@ -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)
+1 -17
View File
@@ -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
+6 -17
View File
@@ -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)
+6
View File
@@ -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
-3
View File
@@ -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)
+8 -7
View File
@@ -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)
+1 -2
View File
@@ -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