Separate wsgi init from web-front-end activation

Separate the request processor initialization steps
    Load common settings from conf
    Set the logger
    Load the request processor
from the web front end server application step

On branch bp/wsgi-application-interface-7
   modified:   swift/common/wsgi.py

Implements Blueprint:   wsgi-application-interface

Change-Id: I25fabad8846cd644e4bf1e1bd9c2e568512e12e5
This commit is contained in:
David Hadas 2012-10-23 17:05:40 +02:00 committed by Darrell Bishop
parent d70d3092c0
commit 9efa9be167

View File

@ -104,41 +104,23 @@ def get_socket(conf, default_port=8080):
# TODO: pull pieces of this out to test
def run_wsgi(conf_file, app_section, *args, **kwargs):
"""
Loads common settings from conf, then instantiates app and runs
the server using the specified number of workers.
Runs the server using the specified number of workers.
:param conf_file: Path to paste.deploy style configuration file
:param app_section: App name from conf file to load config from
"""
# Load configuration, Set logger and Load request processor
try:
conf = appconfig('config:%s' % conf_file, name=app_section)
except Exception, e:
print "Error trying to load config %s: %s" % (conf_file, e)
(app, conf, logger, log_name) = \
init_request_processor(conf_file, app_section, *args, **kwargs)
except ConfigFileError, e:
print e
return
validate_configuration()
# pre-configure logger
log_name = conf.get('log_name', app_section)
if 'logger' in kwargs:
logger = kwargs.pop('logger')
else:
logger = get_logger(conf, log_name,
log_to_console=kwargs.pop('verbose', False),
log_route='wsgi')
# disable fallocate if desired
if config_true_value(conf.get('disable_fallocate', 'no')):
disable_fallocate()
# bind to address and port
sock = get_socket(conf, default_port=kwargs.get('default_port', 8080))
# remaining tasks should not require elevated privileges
drop_privileges(conf.get('user', 'swift'))
# Ensure the application can be loaded before proceeding.
loadapp('config:%s' % conf_file, global_conf={'log_name': log_name})
# redirect errors to logger and close stdio
capture_stdio(logger)
@ -152,7 +134,6 @@ def run_wsgi(conf_file, app_section, *args, **kwargs):
wsgi.WRITE_TIMEOUT = int(conf.get('client_timeout') or 60)
eventlet.hubs.use_hub('poll')
eventlet.patcher.monkey_patch(all=False, socket=True)
monkey_patch_mimetools()
app = loadapp('config:%s' % conf_file,
global_conf={'log_name': log_name})
pool = GreenPool(size=1024)
@ -214,6 +195,47 @@ def run_wsgi(conf_file, app_section, *args, **kwargs):
logger.notice('Exited')
class ConfigFileError(Exception):
pass
def init_request_processor(conf_file, app_section, *args, **kwargs):
"""
Loads common settings from conf
Sets the logger
Loads the request processor
:param conf_file: Path to paste.deploy style configuration file
:param app_section: App name from conf file to load config from
:returns the loaded application entry point
:raises ConfigFileError: Exception is raised for config file error
"""
try:
conf = appconfig('config:%s' % conf_file, name=app_section)
except Exception, e:
raise ConfigFileError("Error trying to load config %s: %s" %
(conf_file, e))
validate_configuration()
# pre-configure logger
log_name = conf.get('log_name', app_section)
if 'logger' in kwargs:
logger = kwargs.pop('logger')
else:
logger = get_logger(conf, log_name,
log_to_console=kwargs.pop('verbose', False),
log_route='wsgi')
# disable fallocate if desired
if config_true_value(conf.get('disable_fallocate', 'no')):
disable_fallocate()
monkey_patch_mimetools()
app = loadapp('config:%s' % conf_file, global_conf={'log_name': log_name})
return (app, conf, logger, log_name)
class WSGIContext(object):
"""
This class provides a means to provide context (scope) for a middleware