diff --git a/nova/tests/unit/test_utils.py b/nova/tests/unit/test_utils.py index 723ce834a0b3..897cbebb3e75 100644 --- a/nova/tests/unit/test_utils.py +++ b/nova/tests/unit/test_utils.py @@ -218,12 +218,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 e6eda16c72d0..41347bf5f746 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -563,30 +563,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. @@ -627,12 +603,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):