[PATCH] [Wok 0/2] Fixes on server initialization

Aline Manera (2): Bug fix: Set application options globally on Server() instead of wokd command Bug fix: Do not allow specifying model instance directly to Server() src/wok/server.py | 16 +++++++++------- src/wokd.in | 7 ------- tests/utils.py | 5 +---- 3 files changed, 10 insertions(+), 18 deletions(-) -- 2.9.3

wokd is a command line tool which relies on Server() instance to start up the web server. To run tests, the wokd command is not used. Instead of that, the Server() instance handles the application options. So instead of setting the options globally on wokd command, do that on Server() to make it used overwhere. This bug was introcuded by 713fd5caa and noticed while running Kimchi tests. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- src/wok/server.py | 7 +++++++ src/wokd.in | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/wok/server.py b/src/wok/server.py index 9b49c1a..f64a6a2 100644 --- a/src/wok/server.py +++ b/src/wok/server.py @@ -61,6 +61,13 @@ def set_no_cache(): class Server(object): def __init__(self, options): + # Update config.config with the command line values + # So the whole application will have access to accurate values + for sec in config.config.sections(): + for item in config.config.options(sec): + if hasattr(options, item): + config.config.set(sec, item, str(getattr(options, item))) + # Check proxy configuration check_proxy_config() diff --git a/src/wokd.in b/src/wokd.in index b701f34..29586a0 100644 --- a/src/wokd.in +++ b/src/wokd.in @@ -78,13 +78,6 @@ def main(options): setattr(options, 'access_log', os.path.join(options.log_dir, ACCESS_LOG)) setattr(options, 'error_log', os.path.join(options.log_dir, ERROR_LOG)) - # Update config.config with the command line values - # So the whole application will have access to accurate values - for sec in config.config.sections(): - for item in config.config.options(sec): - if hasattr(options, item): - config.config.set(sec, item, str(getattr(options, item))) - # Add non-option arguments setattr(options, 'max_body_size', config.config.get('server', 'max_body_size')) -- 2.9.3

The model instance represents which logic will be set for each REST API available in the server configuration. It was there for testing matters and wrongly used in the plugins tests as it has been using to set the plugin model instance for Wok APIs (?) To avoid problems, remove that capability. Also updates run_server() to remove the model parameter. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- src/wok/server.py | 9 ++------- tests/utils.py | 5 +---- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/wok/server.py b/src/wok/server.py index f64a6a2..d99b91f 100644 --- a/src/wok/server.py +++ b/src/wok/server.py @@ -146,19 +146,14 @@ class Server(object): if not dev_env: cherrypy.config.update({'environment': 'production'}) - if hasattr(options, 'model'): - model_instance = options.model - else: - model_instance = model.Model() - for ident, node in sub_nodes.items(): if node.url_auth: cfg = self.configObj ident = "/%s" % ident cfg[ident] = {'tools.wokauth.on': True} - self.app = cherrypy.tree.mount(WokRoot(model_instance, dev_env), - options.server_root, self.configObj) + cherrypy.tree.mount(WokRoot(model.Model(), dev_env), + options.server_root, self.configObj) self._load_plugins() cherrypy.lib.sessions.init() diff --git a/tests/utils.py b/tests/utils.py index 739434f..9c18637 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -88,7 +88,7 @@ if sys.version_info[:2] == (2, 6): unittest.TestCase.assertNotIn = assertNotIn -def run_server(test_mode, model=None, environment='dev', server_root=''): +def run_server(test_mode, environment='dev', server_root=''): args = type('_', (object,), {'cherrypy_port': 8010, 'max_body_size': '4*1024', @@ -97,9 +97,6 @@ def run_server(test_mode, model=None, environment='dev', server_root=''): 'log_level': 'debug', 'session_timeout': 10, 'server_root': server_root})() - if model is not None: - setattr(args, 'model', model) - s = wok.server.Server(args) t = threading.Thread(target=s.start) t.setDaemon(True) -- 2.9.3

Reviewed-By: Lucio Correia <luciojhc@linux.vnet.ibm.com> On 07/02/2017 16:34, Aline Manera wrote:
Aline Manera (2): Bug fix: Set application options globally on Server() instead of wokd command Bug fix: Do not allow specifying model instance directly to Server()
src/wok/server.py | 16 +++++++++------- src/wokd.in | 7 ------- tests/utils.py | 5 +---- 3 files changed, 10 insertions(+), 18 deletions(-)
-- Lucio Correia
participants (2)
-
Aline Manera
-
Lucio Correia