From ff4459ed6bcaa26bc4df9873577ccad9578a89fc Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Fri, 14 Jun 2019 16:20:03 -0700 Subject: [PATCH] Move call to global_conf_callback after loadapp() Otherwise, paste complains about not being able to interpolate values into the replication_semaphore. As long as it gets dropped in before we fork(), I think it's OK? Closes-Bug: 1691075 Change-Id: Ib7e065c47871876786bcc9ff39737f5d1bb3c12c --- swift/common/wsgi.py | 2 +- test/unit/common/test_wsgi.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index b63895c587..53729223db 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -1048,9 +1048,9 @@ def run_wsgi(conf_path, app_section, *args, **kwargs): # Ensure the configuration and application can be loaded before proceeding. global_conf = {'log_name': log_name} + loadapp(conf_path, global_conf=global_conf) if 'global_conf_callback' in kwargs: kwargs['global_conf_callback'](conf, global_conf) - loadapp(conf_path, global_conf=global_conf) # set utils.FALLOCATE_RESERVE if desired utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \ diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index d99877cc3b..5df749eecb 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -780,25 +780,34 @@ class TestWSGI(unittest.TestCase): 'logger', 'log_name') + loadapp_conf = [] + to_inject = object() # replication_timeout injects non-string data + def _global_conf_callback(preloaded_app_conf, global_conf): calls['_global_conf_callback'] += 1 self.assertEqual( preloaded_app_conf, {'__file__': 'test', 'workers': 0}) self.assertEqual(global_conf, {'log_name': 'log_name'}) - global_conf['test1'] = 'one' + global_conf['test1'] = to_inject def _loadapp(uri, name=None, **kwargs): calls['_loadapp'] += 1 - self.assertTrue('global_conf' in kwargs) - self.assertEqual(kwargs['global_conf'], - {'log_name': 'log_name', 'test1': 'one'}) + self.assertIn('global_conf', kwargs) + loadapp_conf.append(kwargs['global_conf']) + # global_conf_callback hasn't been called yet + self.assertNotIn('test1', kwargs['global_conf']) + + def _run_server(*args, **kwargs): + # but by the time that we actually *run* the server, it has + self.assertEqual(loadapp_conf, + [{'log_name': 'log_name', 'test1': to_inject}]) with mock.patch.object(wsgi, '_initrp', _initrp), \ mock.patch.object(wsgi, 'get_socket'), \ 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', _run_server), \ mock.patch('swift.common.utils.eventlet') as _utils_evt: wsgi.run_wsgi('conf_file', 'app_section', global_conf_callback=_global_conf_callback)