[Kimchi-devel] [PATCH] [WoK 2/5] reload API: control and model changes

Daniel Henrique Barboza dhbarboza82 at gmail.com
Thu Jan 19 18:06:56 UTC 2017



On 01/19/2017 12:28 PM, Daniel Henrique Barboza wrote:
>
>
> On 01/19/2017 11:31 AM, Aline Manera wrote:
>>
>>
>> On 01/18/2017 06:55 PM, dhbarboza82 at gmail.com wrote:
>>> From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>>>
>>> - added a new action handler called 'reload' in control/config.py
>>> - added a method 'reload' in model/config.py that calls
>>> 'cherrypy.engine.restart()'.
>>>
>>> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>>> ---
>>>   src/wok/control/config.py | 4 +++-
>>>   src/wok/model/config.py   | 7 ++++++-
>>>   2 files changed, 9 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/src/wok/control/config.py b/src/wok/control/config.py
>>> index 338306c..62218f9 100644
>>> --- a/src/wok/control/config.py
>>> +++ b/src/wok/control/config.py
>>> @@ -1,7 +1,7 @@
>>>   #
>>>   # Project Wok
>>>   #
>>> -# Copyright IBM Corp, 2016
>>> +# Copyright IBM Corp, 2016-2017
>>>   #
>>>   # This library is free software; you can redistribute it and/or
>>>   # modify it under the terms of the GNU Lesser General Public
>>> @@ -25,6 +25,8 @@ from wok.control.utils import UrlSubNode
>>>   class Config(Resource):
>>>       def __init__(self, model, id=None):
>>>           super(Config, self).__init__(model, id)
>>
>>> +        self.uri_fmt = '/config/%s'
>>
>> AFAIU, the self.uri_fmt is only required when you have an resource 
>> name which is not the case of /config API
>>
>> Do you have any specific reason to set it?
>
> I have the impression that the 'reload' action will not work if I 
> don't specify
> uri_fmt - at least this is why I remember noticing when I first wrote 
> it .
>
> I'll try removing it and if it works as intended I'll resend v5 
> without it.

As I've imagined, the uri_fmt is required. Removing it causes WoK to 
throw a 500
Internal Error in line 104 of control/base.py:

     def generate_action_handler(self, action_name, action_args=None,
                                 destructive=False):
         def _render_element(self, ident):
             self._redirect(ident)
             uri_params = []
             for arg in self.model_args:
                 if arg is None:
                     arg = ''
                 uri_params.append(urllib2.quote(arg.encode('utf-8'),
                                   safe=""))
             raise internal_redirect(self.uri_fmt % tuple(uri_params))

         return self._generate_action_handler_base(action_name, 
_render_element,
destructive=destructive,
action_args=action_args)


As we can see above, generate_action_handler uses a _render_element internal
function that raises an internal_redirect at self.uri_fmt % 
tuple(uri_params) . Removing
'uri_fmt' breaks this internal redirect.



>
>>
>> Also I'd say to you set self.admin_methods = [POST] so when my patch 
>> related to authorization get merged, the POST action will be 
>> protected for only sysadmins.
>
> I'll see if setting self.admin_methods = [POST] without the 'True' 
> argument
> in the @URLSubnode will not impact the current behavior (because setting
> to 'True' then the whole API is locked by authentication). If no harm 
> is done
> I'll add it in v5.
>
>
> Daniel

Just checked that we can safely add

self.admin_methods = ['POST']

without messing with the feature behavior.


I'll resend v5 with this addition.


>
>>
>>> +        self.reload = self.generate_action_handler('reload')
>>>
>>>       @property
>>>       def data(self):
>>> diff --git a/src/wok/model/config.py b/src/wok/model/config.py
>>> index 7e8ae4f..57c5ad8 100644
>>> --- a/src/wok/model/config.py
>>> +++ b/src/wok/model/config.py
>>> @@ -1,7 +1,7 @@
>>>   #
>>>   # Project Wok
>>>   #
>>> -# Copyright IBM Corp, 2016
>>> +# Copyright IBM Corp, 2016-2017
>>>   #
>>>   # This library is free software; you can redistribute it and/or
>>>   # modify it under the terms of the GNU Lesser General Public
>>> @@ -17,6 +17,8 @@
>>>   # License along with this library; if not, write to the Free Software
>>>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
>>> 02110-1301 USA
>>>
>>> +import cherrypy
>>> +
>>>   from wok.config import config, get_version
>>>
>>>
>>> @@ -30,3 +32,6 @@ class ConfigModel(object):
>>>                   'auth': config.get('authentication', 'method'),
>>>                   'server_root': config.get('server', 'server_root'),
>>>                   'version': get_version()}
>>> +
>>> +    def reload(self, name):
>>> +        cherrypy.engine.restart()
>>
>> _______________________________________________
>> 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