Merge "[eventlet-deprecation] Remove `common.utils.spawn`"
This commit is contained in:
@@ -921,26 +921,6 @@ def collect_profiler_info():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def spawn(func, *args, **kwargs):
|
|
||||||
"""As eventlet.spawn() but with osprofiler initialized in the new threads
|
|
||||||
|
|
||||||
osprofiler stores the profiler instance in thread local storage, therefore
|
|
||||||
in new threads (including eventlet threads) osprofiler comes uninitialized
|
|
||||||
by default. This spawn() is a stand-in replacement for eventlet.spawn()
|
|
||||||
but we re-initialize osprofiler in threads spawn()-ed.
|
|
||||||
"""
|
|
||||||
|
|
||||||
profiler_info = collect_profiler_info()
|
|
||||||
|
|
||||||
@functools.wraps(func)
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
if profiler_info:
|
|
||||||
profiler.init(**profiler_info)
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
|
|
||||||
return eventlet.spawn(wrapper, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def spawn_n(func, *args, **kwargs):
|
def spawn_n(func, *args, **kwargs):
|
||||||
"""See spawn() above"""
|
"""See spawn() above"""
|
||||||
|
|
||||||
|
|||||||
@@ -26,15 +26,12 @@ from neutron_lib import constants
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from osprofiler import profiler
|
from osprofiler import profiler
|
||||||
import testscenarios
|
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from neutron.common import utils
|
from neutron.common import utils
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
from neutron.tests.unit import tests
|
from neutron.tests.unit import tests
|
||||||
|
|
||||||
load_tests = testscenarios.load_tests_apply_scenarios
|
|
||||||
|
|
||||||
|
|
||||||
class _PortRange:
|
class _PortRange:
|
||||||
"""A linked list of port ranges."""
|
"""A linked list of port ranges."""
|
||||||
@@ -524,13 +521,7 @@ class TestRpBandwidthValidator(base.BaseTestCase):
|
|||||||
self.not_valid_rp_bandwidth, self.device_name_set)
|
self.not_valid_rp_bandwidth, self.device_name_set)
|
||||||
|
|
||||||
|
|
||||||
class SpawnWithOrWithoutProfilerTestCase(
|
class SpawnWithOrWithoutProfilerTestCase(base.BaseTestCase):
|
||||||
testscenarios.WithScenarios, base.BaseTestCase):
|
|
||||||
|
|
||||||
scenarios = [
|
|
||||||
('spawn', {'spawn_variant': utils.spawn}),
|
|
||||||
('spawn_n', {'spawn_variant': utils.spawn_n}),
|
|
||||||
]
|
|
||||||
|
|
||||||
def _compare_profilers_in_parent_and_in_child(self, init_profiler):
|
def _compare_profilers_in_parent_and_in_child(self, init_profiler):
|
||||||
|
|
||||||
@@ -546,8 +537,7 @@ class SpawnWithOrWithoutProfilerTestCase(
|
|||||||
if init_profiler:
|
if init_profiler:
|
||||||
profiler.init(hmac_key='fake secret')
|
profiler.init(hmac_key='fake secret')
|
||||||
|
|
||||||
self.spawn_variant(
|
utils.spawn_n(lambda: q.put(is_profiler_initialized('in-child')))
|
||||||
lambda: q.put(is_profiler_initialized('in-child')))
|
|
||||||
q.put(is_profiler_initialized('in-parent'))
|
q.put(is_profiler_initialized('in-parent'))
|
||||||
|
|
||||||
# Make sure in parent we start with an uninitialized profiler by
|
# Make sure in parent we start with an uninitialized profiler by
|
||||||
|
|||||||
Reference in New Issue
Block a user