From ade2511df2bd2a9ecb7caec734d91e62052c933f Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 1 May 2019 09:01:35 -0700 Subject: [PATCH] scripts/rpc.py: allow users to pipe multiple requests Users can now pipe a large number of requests to rpc.py, separated by newlines - each line will be executed as if it was passed to rpc.py individually. There is significant savings using this feature when executing multiple requests through rpc.py. On my system, a loop of 30 RPCs related to setting up 10 NVMf subsystems takes 5 seconds when executed one at a time. With this new feature, it takes less than 1 second. Signed-off-by: Jim Harris Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452770 (master) (cherry picked from commit 363fe506bc6fcc50f58b160d8cfa24eececcfd41) Change-Id: Iec957ca67461af8e8c41aee47e1d113714b22d3d Signed-off-by: Tomasz Zawadzki Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/457220 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk --- scripts/rpc.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/rpc.py b/scripts/rpc.py index 65521da34..02f6e83c7 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -1800,6 +1800,15 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse print(ex.message) exit(1) + def execute_script(parser, client, fd): + for rpc_call in map(str.rstrip, fd): + args = parser.parse_args(rpc_call.split()) + args.client = client + call_rpc_func(args) + args = parser.parse_args() args.client = rpc.client.JSONRPCClient(args.server_addr, args.port, args.timeout, log_level=getattr(logging, args.verbose.upper())) - call_rpc_func(args) + if hasattr(args, 'func'): + call_rpc_func(args) + else: + execute_script(parser, args.client, sys.stdin)