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 <pawelx.kaminski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/455636
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Pawel Kaminski 2019-05-24 04:58:54 -04:00 committed by Jim Harris
parent 5dc25edde0
commit 3bf82af866
2 changed files with 15 additions and 10 deletions

View File

@ -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()))

View File

@ -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)