From 4dd42c9d55fb1e70f8e1d06199a2c7614742b82a Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 11 Jun 2009 11:59:57 +0200 Subject: [PATCH] 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: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- daemons/ganeti-noded | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index b9b51df80..2137d1bec 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -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 -------------------------- -- GitLab