From 4c2b0f9f8de610b95134ebff7dbe089556af5a40 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Mon, 10 Nov 2025 13:56:34 +0100 Subject: [PATCH] Remove tpool_execute as it is unused The previous commits removed all the users for nova.utils.tpool_execute so this patch removes that utility. This also allows us to inline the _pass_context helper as now it is only used by spawn_on. Change-Id: I8520ccf4b5526543681c8c3864aaeef501462e9e Signed-off-by: Balazs Gibizer --- nova/tests/unit/test_utils.py | 6 ----- nova/utils.py | 41 +++++++++++------------------------ 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/nova/tests/unit/test_utils.py b/nova/tests/unit/test_utils.py index 32827593a5d5..1cd58bdf67c9 100644 --- a/nova/tests/unit/test_utils.py +++ b/nova/tests/unit/test_utils.py @@ -216,12 +216,6 @@ class GenericUtilsTestCase(test.NoDBTestCase): utils.ssh_execute('remotehost', 'ls', '-l') mock_execute.assert_called_once_with(*expected_args) - @mock.patch('nova.utils.generate_uid') - def test_tpool_execute(self, mock_generate): - expected_kargs = {'size': 12} - utils.tpool_execute(utils.generate_uid, 'mytopic', size=12) - mock_generate.assert_called_once_with('mytopic', **expected_kargs) - def test_generate_hostid(self): host = 'host' project_id = '9b9e3c847e904b0686e8ffb20e4c6381' diff --git a/nova/utils.py b/nova/utils.py index 41ad9388e0b6..99b7d0e9f340 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -562,30 +562,6 @@ def _serialize_profile_info(): return trace_info -def _pass_context(runner, func, *args, **kwargs): - """Generalised passthrough method - It will grab the context from the threadlocal store and add it to - the store on the runner. This allows for continuity in logging the - context when using this method to spawn a new thread through the - runner function - """ - - _context = common_context.get_current() - profiler_info = _serialize_profile_info() - - @functools.wraps(func) - def context_wrapper(*args, **kwargs): - # NOTE: If update_store is not called after spawning a thread, it won't - # be available for the logger to pull from threadlocal storage. - if _context is not None: - _context.update_store() - if profiler_info and profiler: - profiler.init(**profiler_info) - return func(*args, **kwargs) - - return runner(context_wrapper, *args, **kwargs) - - def spawn(func, *args, **kwargs) -> futurist.Future: """Passthrough method for eventlet.spawn. @@ -626,12 +602,21 @@ def spawn_on(executor, func, *args, **kwargs) -> futurist.Future: "queued. If this happens repeatedly then the size of the pool is " "too small for the load or there are stuck threads filling the " "pool.", executor.name, func) - return _pass_context(executor.submit, func, *args, **kwargs) + _context = common_context.get_current() + profiler_info = _serialize_profile_info() -def tpool_execute(func, *args, **kwargs): - """Run func in a native thread""" - return _pass_context(tpool.execute, func, *args, **kwargs) + @functools.wraps(func) + def context_wrapper(*args, **kwargs): + # NOTE: If update_store is not called after spawning a thread, it won't + # be available for the logger to pull from threadlocal storage. + if _context is not None: + _context.update_store() + if profiler_info and profiler: + profiler.init(**profiler_info) + return func(*args, **kwargs) + + return executor.submit(context_wrapper, *args, **kwargs) def is_none_string(val):