Commit 6ef78fe6 authored by Vitaliy Mysak's avatar Vitaliy Mysak Committed by Darek Stojaczyk
Browse files

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 <module>
    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: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/462020


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 9b81498b
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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: