From cf6e714bc3c68a8b9d788370fbdee4df6764e936 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Tue, 16 Feb 2010 17:17:38 -0500 Subject: Oh FFS. lazr.restful 0.9.18 totally broke our shit by introducing multiversioned web services. In concept, that's a great idea, but in (current as of 0.9.18) practice it sucks because it /forces/ us to adopt multiversions when really I could care less. After gobs of painful experimentation, this passes all the tests. I guess that means it's right . Another, more reasonable fix is to re-order when logging is initialized. This is moved to the start of initialize_2() because in the test environment, we don't want to initialize the loggers until after the test configuration has been pushed. Otherwise, because of the changes to support the FHS, logging will go to the wrong place. This really only affects tests, since in operational mode, initialize always happens immediately one after another. --- src/mailman/core/initialize.py | 19 +++++---- src/mailman/rest/configuration.py | 21 ++++++++-- src/mailman/rest/configure.zcml | 14 ++++++- src/mailman/rest/publication.py | 4 ++ src/mailman/rest/urls.py | 8 ++-- src/mailman/rest/webservice.py | 84 ++++++++++++++++++++++++--------------- 6 files changed, 101 insertions(+), 49 deletions(-) diff --git a/src/mailman/core/initialize.py b/src/mailman/core/initialize.py index 7c03a61db..e55e97ee5 100644 --- a/src/mailman/core/initialize.py +++ b/src/mailman/core/initialize.py @@ -87,19 +87,15 @@ def search_for_configuration_file(): # initialization, but before database initialization. Generally all other # code will just call initialize(). -def initialize_1(config_path=None, propagate_logs=None): +def initialize_1(config_path=None): """First initialization step. * Zope component architecture * The configuration system * Run-time directories - * The logging subsystem - * Internationalization :param config_path: The path to the configuration file. :type config_path: string - :param propagate_logs: Should the log output propagate to stderr? - :type propagate_logs: boolean or None """ zcml = resource_string('mailman.config', 'configure.zcml') xmlconfig.string(zcml) @@ -119,13 +115,12 @@ def initialize_1(config_path=None, propagate_logs=None): # For the test suite, force this back to not using a config file. config_path = None mailman.config.config.load(config_path) - # Create the queue and log directories if they don't already exist. - mailman.core.logging.initialize(propagate_logs) -def initialize_2(debug=False): +def initialize_2(debug=False, propagate_logs=None): """Second initialization step. + * Logging * Pre-hook * Rules * Chains @@ -134,7 +129,11 @@ def initialize_2(debug=False): :param debug: Should the database layer be put in debug mode? :type debug: boolean + :param propagate_logs: Should the log output propagate to stderr? + :type propagate_logs: boolean or None """ + # Create the queue and log directories if they don't already exist. + mailman.core.logging.initialize(propagate_logs) # Run the pre-hook if there is one. config = mailman.config.config if config.mailman.pre_hook: @@ -172,6 +171,6 @@ def initialize_3(): def initialize(config_path=None, propagate_logs=None): - initialize_1(config_path, propagate_logs) - initialize_2() + initialize_1(config_path) + initialize_2(propagate_logs=propagate_logs) initialize_3() diff --git a/src/mailman/rest/configuration.py b/src/mailman/rest/configuration.py index df756d76a..30e2607cb 100644 --- a/src/mailman/rest/configuration.py +++ b/src/mailman/rest/configuration.py @@ -55,18 +55,33 @@ class AdminWebServiceConfiguration(BaseWSGIWebServiceConfiguration): """See `IWebServiceConfiguration`.""" return as_boolean(config.webservice.use_https) - # This should match the major.minor Mailman version. - service_version_uri_prefix = '{0.MAJOR_REV}.{0.MINOR_REV}'.format(version) + # We currently have only one active version; the first entry in this list + # should match the major.minor Mailman version. The second entry is just + # an alias for the 'floating' development version. + active_versions = [ + '{0.MAJOR_REV}.{0.MINOR_REV}'.format(version), + 'dev', + ] code_revision = version.VERSION @property def show_tracebacks(self): """See `IWebServiceConfiguration`.""" return config.webservice.show_tracebacks - + default_batch_size = 50 max_batch_size = 300 def get_request_user(self): """See `IWebServiceConfiguration`.""" return None + + @property + def hostname(self): + """See `IWebServiceConfiguration`.""" + return config.webservice.hostname + + @property + def port(self): + """See `IWebServiceConfiguration`.""" + return int(config.webservice.port) diff --git a/src/mailman/rest/configure.zcml b/src/mailman/rest/configure.zcml index fff1b5bac..7fecf4608 100644 --- a/src/mailman/rest/configure.zcml +++ b/src/mailman/rest/configure.zcml @@ -5,8 +5,7 @@ - - + @@ -35,6 +34,12 @@ factory="mailman.rest.urls.FallbackURLMapper" /> + + + %s', name, next_step) - return next_step + return top_names.get(name) + + +class AdminWebServiceApplication(WSGIApplication): + """A WSGI application for the admin REST interface.""" + + # The only thing we need to override is the publication class. + publication_class = AdminWebServicePublication - class AdminWebServiceWSGIRequestHandler(WSGIRequestHandler): """Handler class which just logs output to the right place.""" @@ -99,8 +118,11 @@ class AdminWebServiceWSGIRequestHandler(WSGIRequestHandler): log.info('%s - - %s', self.address_string(), format % args) + def make_server(): """Create the WSGI admin REST server.""" + register_versioned_request_utility(I30Version, '3.0') + register_versioned_request_utility(IDevVersion, 'dev') host = config.webservice.hostname port = int(config.webservice.port) server = WSGIServer((host, port), AdminWebServiceWSGIRequestHandler) -- cgit v1.3.1