diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index c078ac9d7b..3057762c85 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -430,7 +430,6 @@ def run_server(conf, logger, sock, global_conf=None): wsgi.WRITE_TIMEOUT = int(conf.get('client_timeout') or 60) eventlet.hubs.use_hub(get_hub()) - utils.eventlet_monkey_patch() eventlet_debug = config_true_value(conf.get('eventlet_debug', 'no')) eventlet.debug.hub_exceptions(eventlet_debug) wsgi_logger = NullLogger() @@ -905,6 +904,9 @@ def run_wsgi(conf_path, app_section, *args, **kwargs): else: strategy = WorkersStrategy(conf, logger) + # patch event before loadapp + utils.eventlet_monkey_patch() + # Ensure the configuration and application can be loaded before proceeding. global_conf = {'log_name': log_name} if 'global_conf_callback' in kwargs: diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index 073dbe0123..44b7e3977e 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -475,7 +475,6 @@ class TestWSGI(unittest.TestCase): 'modify_wsgi_pipeline'), \ mock.patch('swift.common.wsgi.wsgi') as _wsgi, \ mock.patch('swift.common.wsgi.eventlet') as _wsgi_evt, \ - mock.patch('swift.common.utils.eventlet') as _utils_evt, \ mock.patch('swift.common.wsgi.inspect'): conf = wsgi.appconfig(conf_file) logger = logging.getLogger('test') @@ -485,10 +484,6 @@ class TestWSGI(unittest.TestCase): _wsgi.HttpProtocol.default_request_version) self.assertEqual(30, _wsgi.WRITE_TIMEOUT) _wsgi_evt.hubs.use_hub.assert_called_with(utils.get_hub()) - _utils_evt.patcher.monkey_patch.assert_called_with(all=False, - socket=True, - select=True, - thread=True) _wsgi_evt.debug.hub_exceptions.assert_called_with(False) self.assertTrue(_wsgi.server.called) args, kwargs = _wsgi.server.call_args @@ -562,7 +557,6 @@ class TestWSGI(unittest.TestCase): 'modify_wsgi_pipeline'), \ mock.patch('swift.common.wsgi.wsgi') as _wsgi, \ mock.patch('swift.common.wsgi.eventlet') as _wsgi_evt, \ - mock.patch('swift.common.utils.eventlet') as _utils_evt, \ mock.patch.dict('os.environ', {'TZ': ''}), \ mock.patch('swift.common.wsgi.inspect'), \ mock.patch('time.tzset'): @@ -576,10 +570,6 @@ class TestWSGI(unittest.TestCase): _wsgi.HttpProtocol.default_request_version) self.assertEqual(30, _wsgi.WRITE_TIMEOUT) _wsgi_evt.hubs.use_hub.assert_called_with(utils.get_hub()) - _utils_evt.patcher.monkey_patch.assert_called_with(all=False, - socket=True, - select=True, - thread=True) _wsgi_evt.debug.hub_exceptions.assert_called_with(False) self.assertTrue(_wsgi.server.called) args, kwargs = _wsgi.server.call_args @@ -617,7 +607,6 @@ class TestWSGI(unittest.TestCase): with mock.patch('swift.proxy.server.Application.' 'modify_wsgi_pipeline'), \ mock.patch('swift.common.wsgi.wsgi') as _wsgi, \ - mock.patch('swift.common.utils.eventlet') as _utils_evt, \ mock.patch('swift.common.wsgi.eventlet') as _wsgi_evt: mock_server = _wsgi.server _wsgi.server = lambda *args, **kwargs: mock_server( @@ -630,10 +619,6 @@ class TestWSGI(unittest.TestCase): _wsgi.HttpProtocol.default_request_version) self.assertEqual(30, _wsgi.WRITE_TIMEOUT) _wsgi_evt.hubs.use_hub.assert_called_with(utils.get_hub()) - _utils_evt.patcher.monkey_patch.assert_called_with(all=False, - socket=True, - select=True, - thread=True) _wsgi_evt.debug.hub_exceptions.assert_called_with(True) self.assertTrue(mock_server.called) args, kwargs = mock_server.call_args @@ -777,12 +762,17 @@ class TestWSGI(unittest.TestCase): mock.patch.object(wsgi, 'drop_privileges'), \ mock.patch.object(wsgi, 'loadapp', _loadapp), \ mock.patch.object(wsgi, 'capture_stdio'), \ - mock.patch.object(wsgi, 'run_server'): + mock.patch.object(wsgi, 'run_server'), \ + mock.patch('swift.common.utils.eventlet') as _utils_evt: wsgi.run_wsgi('conf_file', 'app_section', global_conf_callback=_global_conf_callback) self.assertEqual(calls['_global_conf_callback'], 1) self.assertEqual(calls['_loadapp'], 1) + _utils_evt.patcher.monkey_patch.assert_called_with(all=False, + socket=True, + select=True, + thread=True) def test_run_server_success(self): calls = defaultdict(lambda: 0) @@ -802,11 +792,16 @@ class TestWSGI(unittest.TestCase): mock.patch.object(wsgi, 'drop_privileges'), \ mock.patch.object(wsgi, 'loadapp', _loadapp), \ mock.patch.object(wsgi, 'capture_stdio'), \ - mock.patch.object(wsgi, 'run_server'): + mock.patch.object(wsgi, 'run_server'), \ + mock.patch('swift.common.utils.eventlet') as _utils_evt: rc = wsgi.run_wsgi('conf_file', 'app_section') self.assertEqual(calls['_initrp'], 1) self.assertEqual(calls['_loadapp'], 1) self.assertEqual(rc, 0) + _utils_evt.patcher.monkey_patch.assert_called_with(all=False, + socket=True, + select=True, + thread=True) @mock.patch('swift.common.wsgi.run_server') @mock.patch('swift.common.wsgi.WorkersStrategy')