Skip to content
Snippets Groups Projects
Commit 4dd42c9d authored by Iustin Pop's avatar Iustin Pop
Browse files

Implement result-type restriction in ganeti-noded


Since all rpc calls were converted, we can now:
  - enforce result type to (status, data)
  - convert all unhandled exceptions to (False, str(err))

This makes sure that all unhandled errors are reported to rpc users.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 8e70b181
No related branches found
No related tags found
No related merge requests found
......@@ -93,7 +93,16 @@ class NodeHttpServer(http.server.HttpServer):
raise http.HttpNotFound()
try:
return method(req.request_body)
rvalue = method(req.request_body)
if not isinstance(rvalue, tuple):
return (False, "Invalid result from backend function: expected"
" tuple, got %s" % type(rvalue))
elif len(rvalue) != 2:
return (False, "Invalid result from backend function: expected"
" 2-element tuple, got tuple of length %d" % len(rvalue))
else:
return rvalue
except backend.RPCFail, err:
# our custom failure exception; str(err) works fine if the
# exception was constructed with a single argument, and in
......@@ -107,9 +116,9 @@ class NodeHttpServer(http.server.HttpServer):
# And return the error's arguments, which must be already in
# correct tuple format
return err.args
except:
except Exception, err:
logging.exception("Error in RPC call")
raise
return False, "Error while executing backend function: %s" % str(err)
# the new block devices --------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment