Commit 9b81498b authored by Vitaliy Mysak's avatar Vitaliy Mysak Committed by Darek Stojaczyk
Browse files

rpc.py: check if port is None during client init



RPC client constructor accepts optional port,
  but does not check if it's None in case of
  remote connection.
This patch adds the check and new error message
  related to it.

Case where port is unexpectedly None
  can be reproduced by starting spdkcli
  when SPDK socket does not exist.

Change-Id: I46e0b99547204c6fdeac421e5de9d6991387e207
Signed-off-by: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/460974


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent a15dcb0b
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -38,7 +38,8 @@ class JSONRPCClient(object):
                self._logger.debug("Trying to connect to UNIX socket: %s", addr)
                self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
                self.sock.connect(addr)
            elif ':' in addr:
            elif port:
                if ':' in addr:
                    self._logger.debug("Trying to connect to IPv6 address addr:%s, port:%i", addr, port)
                    for res in socket.getaddrinfo(addr, port, socket.AF_INET6, socket.SOCK_STREAM, socket.SOL_TCP):
                        af, socktype, proto, canonname, sa = res
@@ -48,6 +49,8 @@ class JSONRPCClient(object):
                    self._logger.debug("Trying to connect to IPv4 address addr:%s, port:%i'", addr, port)
                    self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    self.sock.connect((addr, port))
            else:
                raise socket.error("Unix socket '%s' does not exist" % addr)
        except socket.error as ex:
            raise JSONRPCException("Error while connecting to %s\n"
                                   "Error details: %s" % (addr, ex))