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: Vitaliy Mysak <vitaliy.mysak@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/460974 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
a15dcb0bf0
commit
9b81498be8
@ -38,16 +38,19 @@ 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:
|
||||
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
|
||||
self.sock = socket.socket(af, socktype, proto)
|
||||
self.sock.connect(sa)
|
||||
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
|
||||
self.sock = socket.socket(af, socktype, proto)
|
||||
self.sock.connect(sa)
|
||||
else:
|
||||
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:
|
||||
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))
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user