[Kimchi-devel] [PATCH] [WoK 08/10] /config/plugins: exclude 'sample' plug-in when not in test_mode

Aline Manera alinefm at linux.vnet.ibm.com
Wed Jan 25 17:29:59 UTC 2017



On 01/20/2017 03:32 PM, dhbarboza82 at gmail.com wrote:
> From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>
> The 'sample' plug-in matches the criteria for a valid disabled
> plug-in. However 'sample' is a plug-in made for demonstration
> purposes and it is not supposed to be shown in WoK with other
> 'real' plug-ins.
>
> This patch adds the test_mode option in cherrypy.config inside
> server.py, making it readable across other modules. This option
> is then read at 'get_plugins' of utils.py and, if the server isn't
> running in test_mode, discard the sample plug-in entry. Othewise
> (unit tests using run_server for example) we can safely show it.
>
> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
> ---
>   src/wok/server.py | 7 ++++++-
>   src/wok/utils.py  | 4 ++++
>   2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/src/wok/server.py b/src/wok/server.py
> index 48f455b..2065dc4 100644
> --- a/src/wok/server.py
> +++ b/src/wok/server.py
> @@ -1,7 +1,7 @@
>   #
>   # Project Wok
>   #
> -# Copyright IBM Corp, 2015-2016
> +# Copyright IBM Corp, 2015-2017
>   #
>   # Code derived from Project Kimchi
>   #
> @@ -139,6 +139,11 @@ class Server(object):
>           if not dev_env:
>               cherrypy.config.update({'environment': 'production'})

> +        test_mode = False
> +        if hasattr(options, 'test') and options.test is True:
> +            test_mode = True
> +        cherrypy.config.update({'test_mode': test_mode})
> +

I don't think we need to use cherrypy to handle a information only 
needed for configuraiton.
Why do not pass it as parameter to get_enabled_plugins function() ?

>           if hasattr(options, 'model'):
>               model_instance = options.model
>           else:
> diff --git a/src/wok/utils.py b/src/wok/utils.py
> index e67b608..d841371 100644
> --- a/src/wok/utils.py
> +++ b/src/wok/utils.py
> @@ -88,6 +88,10 @@ def get_plugins(enabled_only=False):
>           return
>       for name in dir_contents:
>           if os.path.isdir(os.path.join(plugin_dir, name)):
> +            test_mode = cherrypy.config.get('test_mode', False)
> +            if name == 'sample' and not test_mode:
> +                continue
> +
>               plugin_config = load_plugin_conf(name)
>               if not plugin_config:
>                   continue



More information about the Kimchi-devel mailing list