summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago da Silva <thiago@redhat.com>2018-02-08 18:18:15 -0500
committerThiago da Silva <thiago@redhat.com>2018-02-26 14:10:19 +0000
commit3d12a10cc48a6895e5308756be6060523377ae3f (patch)
treea13a04d582f054b626cb28c2958c6bbaac212765
parent700a6756da70026fbffe3977bd40fc73404b5e25 (diff)
downloadswift-3d12a10cc48a6895e5308756be6060523377ae3f.tar.gz
Move eventlet patch before call to loadapp
Ran into an eventlet bug[0] while integration Swift/Barbican in TripleO. It is very similar to a previous bug related to keystonemiddleware[1]. Suggestion from urllib3[2] is to patch eventlet "as early as possible". Traceback[3] shows that urllib3 is being imported before the eventlet patch, so moved the patch to before the loadapp call. [0] - http://paste.openstack.org/show/658046/ [1] - https://bugs.launchpad.net/swift/+bug/1662473 [2] - https://github.com/shazow/urllib3/issues/1104 [3] - https://gist.github.com/thiagodasilva/12dad7dc4f940b046dd0863b6f82a78b Change-Id: I74e580f31349bdefd187cc5d6770a7041a936bef (cherry picked from commit c9410c7dd482cc1faefdfd9d9c83d225e7d28e8f)
-rw-r--r--swift/common/wsgi.py4
-rw-r--r--test/unit/common/test_wsgi.py29
2 files changed, 15 insertions, 18 deletions
diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py
index c078ac9d7..3057762c8 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 073dbe012..44b7e3977 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')