Plumb allow_modify_pipeline through run_wsgi/run_server

Otherwise, there's no good way to launch a multi-worker, gatekeeper-less
proxy server.

Change-Id: I343609e5c0baeddf91facde463f4458c82fd3193
This commit is contained in:
Tim Burke 2021-08-13 12:28:07 -07:00
parent 901d2e15b7
commit 927691098e
2 changed files with 16 additions and 8 deletions

View File

@ -645,7 +645,8 @@ class SwiftHttpProxiedProtocol(SwiftHttpProtocol):
return environ
def run_server(conf, logger, sock, global_conf=None, ready_callback=None):
def run_server(conf, logger, sock, global_conf=None, ready_callback=None,
allow_modify_pipeline=True):
# Ensure TZ environment variable exists to avoid stat('/etc/localtime') on
# some platforms. This locks in reported times to UTC.
os.environ['TZ'] = 'UTC+0'
@ -665,7 +666,8 @@ def run_server(conf, logger, sock, global_conf=None, ready_callback=None):
else:
log_name = logger.name
global_conf = {'log_name': log_name}
app = loadapp(conf['__file__'], global_conf=global_conf)
app = loadapp(conf['__file__'], global_conf=global_conf,
allow_modify_pipeline=allow_modify_pipeline)
max_clients = int(conf.get('max_clients', '1024'))
pool = RestrictedGreenPool(size=max_clients)
@ -1046,6 +1048,9 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
:param conf_path: Path to paste.deploy style configuration file/directory
:param app_section: App name from conf file to load config from
:param allow_modify_pipeline: Boolean for whether the server should have
an opportunity to change its own pipeline.
Defaults to True
:returns: 0 if successful, nonzero otherwise
"""
# Load configuration, Set logger and Load request processor
@ -1088,6 +1093,8 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
if 'global_conf_callback' in kwargs:
kwargs['global_conf_callback'](conf, global_conf)
allow_modify_pipeline = kwargs.get('allow_modify_pipeline', True)
# set utils.FALLOCATE_RESERVE if desired
utils.FALLOCATE_RESERVE, utils.FALLOCATE_IS_PERCENT = \
utils.config_fallocate_value(conf.get('fallocate_reserve', '1%'))
@ -1099,7 +1106,8 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
no_fork_sock = strategy.no_fork_sock()
if no_fork_sock:
run_server(conf, logger, no_fork_sock, global_conf=global_conf,
ready_callback=strategy.signal_ready)
ready_callback=strategy.signal_ready,
allow_modify_pipeline=allow_modify_pipeline)
return 0
def stop_with_signal(signum, *args):
@ -1132,7 +1140,8 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
os.write(write_fd, b'ready')
os.close(write_fd)
run_server(conf, logger, sock, ready_callback=notify)
run_server(conf, logger, sock, ready_callback=notify,
allow_modify_pipeline=allow_modify_pipeline)
strategy.log_sock_exit(sock, sock_info)
return 0
else:

View File

@ -460,14 +460,13 @@ class TestWSGI(unittest.TestCase):
with open(conf_file, 'w') as f:
f.write(contents.replace('TEMPDIR', t))
_fake_rings(t)
with mock.patch('swift.proxy.server.Application.'
'modify_wsgi_pipeline'), \
mock.patch('swift.common.wsgi.wsgi') as _wsgi, \
with mock.patch('swift.common.wsgi.wsgi') as _wsgi, \
mock.patch('swift.common.wsgi.eventlet') as _wsgi_evt:
conf = wsgi.appconfig(conf_file)
logger = logging.getLogger('test')
sock = listen_zero()
wsgi.run_server(conf, logger, sock)
wsgi.run_server(conf, logger, sock,
allow_modify_pipeline=False)
_wsgi_evt.hubs.use_hub.assert_called_with(utils.get_hub())
_wsgi_evt.debug.hub_exceptions.assert_called_with(False)
self.assertTrue(_wsgi.server.called)