Commit 3247bbac authored by Iustin Pop's avatar Iustin Pop
Browse files

rpc: Add a method for easy check of remote results

The patch adds a new method to the rpc.RpcResult class called
"RemoteFailMsg" which is useful for the RPC calls which return a
(status, payload) style result.

Reviewed-by: imsnah
parent 56e7640c
......@@ -123,6 +123,32 @@ class RpcResult(object):
raise errors.OpExecError("Call '%s' to node '%s' has failed: %s" %
(, self.node, self.error))
def RemoteFailMsg(self):
"""Check if the remote procedure failed.
This is valid only for RPC calls which return result of the form
(status, data | error_msg).
@return: empty string for succcess, otherwise an error message
def _EnsureErr(val):
"""Helper to ensure we return a 'True' value for error."""
if val:
return val
return "No error information"
if self.failed:
return _EnsureErr(self.error)
if not isinstance(, (tuple, list)):
return "Invalid result type (%s)" % type(
if len( != 2:
return "Invalid result length (%d), expected 2" % len(
if not[0]:
return _EnsureErr([1])
return ""
class Client:
"""RPC Client class.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment