From 3bf82af866004a0e9458038aa25a4184236dac36 Mon Sep 17 00:00:00 2001 From: Pawel Kaminski Date: Fri, 24 May 2019 04:58:54 -0400 Subject: [PATCH] script/rpc: Display request when rpc throws exception. This change will allow easier debugging of what parameters are sent to spdk target. It will also help to analyse which commands will fail if multiple commands are sent to rpc.py. Change-Id: I8e75b5edce791a1fc41e83664add8893f4c1bbfb Signed-off-by: Pawel Kaminski Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/455636 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- scripts/rpc.py | 19 +++++++++++-------- scripts/rpc/client.py | 6 ++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/rpc.py b/scripts/rpc.py index 4d775237c1..40c6b0b798 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -1801,21 +1801,24 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse print("{} is deprecated, use {} instead.".format(name, deprecated_aliases[name]), file=sys.stderr) def call_rpc_func(args): - try: - args.func(args) - check_called_name(args.called_rpc_name) - except JSONRPCException as ex: - print("Exception:") - print(ex.message) - exit(1) + args.func(args) + check_called_name(args.called_rpc_name) def execute_script(parser, client, fd): + executed_rpc = "" for rpc_call in map(str.rstrip, fd): if not rpc_call.strip(): continue + executed_rpc = "\n".join([executed_rpc, rpc_call]) args = parser.parse_args(shlex.split(rpc_call)) args.client = client - call_rpc_func(args) + try: + call_rpc_func(args) + except JSONRPCException as ex: + print("Exception:") + print(executed_rpc.strip() + " <<<") + print(ex.message) + exit(1) args = parser.parse_args() args.client = rpc.client.JSONRPCClient(args.server_addr, args.port, args.timeout, log_level=getattr(logging, args.verbose.upper())) diff --git a/scripts/rpc/client.py b/scripts/rpc/client.py index 58ab33f9c3..6907b8b616 100644 --- a/scripts/rpc/client.py +++ b/scripts/rpc/client.py @@ -139,7 +139,7 @@ class JSONRPCClient(object): def call(self, method, params=None): self._logger.debug("call('%s')" % method) - self.send(method, params) + req_id = self.send(method, params) try: response = self.recv() except JSONRPCException as e: @@ -151,7 +151,9 @@ class JSONRPCClient(object): raise e if 'error' in response: - msg = "\n".join(["Got JSON-RPC error response", + msg = "\n".join(["request:", "%s" % json.dumps({**{"method": method, "req_id": req_id}, + **params}, indent=2), + "Got JSON-RPC error response", "response:", json.dumps(response['error'], indent=2)]) raise JSONRPCException(msg)