[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 19:34:45 UTC 2017



On 01/25/2017 04:59 PM, Daniel Henrique Barboza wrote:
>
>
> On 01/25/2017 03:29 PM, Aline Manera wrote:
>>
>>
>> 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() ?
>
> I did that. I had to pass the same parameter along other functions as 
> well, get_plugins
> for example.
>
> I decided to go with this solution instead because I think it's 
> cleaner than passing it
> as a parameter from server.py. It also enables the info to be fetched 
> anywhere in the
> code, including plug-ins.
>

The plugins already have access to this info through server options as 
well. It is using that that Kimchi runs on MockModel when on --test.

> Also, the documentation about  cherrypy.config states:
>
> "
>         config: a file or dict containing application config. If this 
> contains
>             a [global] section, those entries will be used in the global
>             (site-wide) config.
> "
>
> So I think it's a good place to store the 'test_mode' info.
>
>>
>>>           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
>>
>> _______________________________________________
>> Kimchi-devel mailing list
>> Kimchi-devel at ovirt.org
>> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>



More information about the Kimchi-devel mailing list