From 6ef78fe661c7856ffd3e63ccbb1412b48ad4a6dc Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Mon, 15 Jul 2019 17:03:10 +0000 Subject: [PATCH] spdkcli: handle intialiazation error Catch exceptions during RPC client initialization to display meaningful error message. Withouth this change, user gets stacktrace when e.g. SPDK application is not running. Before: ``` Traceback (most recent call last): File "scripts/rpc/client.py", line 53, in __init__ raise socket.error("Unix socket '%s' does not exist" % addr) OSError: Unix socket '/var/tmp/spdk.sock' does not exist During handling of the above exception, another exception occurred: Traceback (most recent call last): File "scripts/spdkcli.py", line 74, in main() File "scripts/spdkcli.py", line 47, in main with rpc.client.JSONRPCClient(args.socket) as client: File "scripts/rpc/client.py", line 56, in __init__ "Error details: %s" % (addr, ex)) rpc.client.JSONRPCException: Error while connecting to /var/tmp/spdk.sock Error details: Unix socket '/var/tmp/spdk.sock' does not exist ``` After: ``` Error while connecting to /var/tmp/spdk.sock Error details: Unix socket '/var/tmp/spdk.sock' does not exist. SPDK not running? ``` Change-Id: I65862965b68acf3bd4709de598f04de49da27de2 Signed-off-by: Vitaliy Mysak Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/462020 Tested-by: SPDK CI Jenkins Reviewed-by: Karol Latecki Reviewed-by: Darek Stojaczyk Reviewed-by: Shuhei Matsumoto --- scripts/spdkcli.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/spdkcli.py b/scripts/spdkcli.py index 743ed0607..5a668c26b 100755 --- a/scripts/spdkcli.py +++ b/scripts/spdkcli.py @@ -44,7 +44,13 @@ def main(): help="commands to execute by SPDKCli as one-line command") args = parser.parse_args() - with rpc.client.JSONRPCClient(args.socket) as client: + try: + client = rpc.client.JSONRPCClient(args.socket) + except JSONRPCException as e: + spdk_shell.log.error("%s. SPDK not running?" % e) + sys.exit(1) + + with client: root_node = UIRoot(client, spdk_shell) root_node.verbose = args.verbose try: