Reviewed-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
Has checked, the indent of /host is None, it is different with other
resource.
I think your code is OK.
also I think the follow code maybe also OK, but I do not test.
This depends on which you prefer.
Thanks.
$ git diff
diff --git a/src/kimchi/control/host.py b/src/kimchi/control/host.py
index 50edc71..3acf567 100644
--- a/src/kimchi/control/host.py
+++ b/src/kimchi/control/host.py
@@ -34,8 +34,8 @@ from kimchi.template import render
@UrlSubNode("host", True, ['POST'])
class Host(Resource):
def __init__(self, model, id=None):
- super(Host, self).__init__(model, id)
- self.uri_fmt = '/host/%s'
+ super(Host, self).__init__(model, "host")
+ self.uri_fmt = '/%s'
self.reboot = self.generate_action_handler('reboot')
self.shutdown = self.generate_action_handler('shutdown')
self.stats = HostStats(self.model)
On 02/26/2014 01:20 AM, Aline Manera wrote:
From: Aline Manera <alinefm(a)br.ibm.com>
The following error is raised when the user tried to reboot the host
system:
Request Headers:
AUTHORIZATION: Basic YWxpbmVmbTowaG5lKjI4ZGljSA==
Content-Length: 2
HOST: localhost:8000
Remote-Addr: 127.0.0.1
ACCEPT: application/json
USER-AGENT: curl/7.27.0
Content-Type: application/json
[25/Feb/2014:14:05:28] HTTP Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in
respond
response.body = self.handler()
File "/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188,
in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 34, in
__call__
return self.callable(*self.args, **self.kwargs)
File "/home/alinefm/kimchi/src/kimchi/control/base.py", line 79, in wrapper
for arg in self.model_args])
AttributeError: 'NoneType' object has no attribute 'encode'
It is because /host resource has no parameter and fails to encode() the
None value.
So fix it by verifying the parameter is not None in order to make the
encode() call.
Signed-off-by: Aline Manera <alinefm(a)br.ibm.com>
---
src/kimchi/control/base.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index 91a70ae..5d1f380 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -75,9 +75,13 @@ class Resource(object):
fn = getattr(self.model, model_fn(self, action_name))
ident = fn(*model_args)
self._redirect(ident)
- uri_params = tuple([urllib2.quote(arg.encode('utf-8'),
safe="")
- for arg in self.model_args])
- raise internal_redirect(self.uri_fmt % uri_params)
+ 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))
except MissingParameter, e:
raise cherrypy.HTTPError(400, e.message)
except InvalidParameter, e:
--
Thanks and best regards!
Sheldon Feng(冯少合)<shaohef(a)linux.vnet.ibm.com>
IBM Linux Technology Center