Skip to content

Commit

Permalink
python: Don't raise an Exception on failure to connect via SSL.
Browse files Browse the repository at this point in the history
With other socket types, trying to connect and failing will return
an error code, but if an SSL Stream is used, then when
check_connection_completion(sock) is called, SSL will raise an
exception that doesn't derive from socket.error which is handled.

This adds handling for SSL.SysCallError which has the same
arguments as socket.error (errno, string). A future enhancement
could be to go through SSLStream class and implement error
checking for all of the possible exceptions similar to how
lib/stream-ssl.c's interpret_ssl_error() works across the various
methods that are implemented.

Fixes: d90ed7d ("python: Add SSL support to the python ovs client library")
Signed-off-by: Terry Wilson <twilson@redhat.com>
Acked-by: Thomas Neuman <thomas.neuman@nutanix.com>
Acked-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
  • Loading branch information
otherwiseguy authored and igsilya committed Nov 16, 2020
1 parent e9495d4 commit 9d17f7b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions python/ovs/stream.py
Expand Up @@ -134,6 +134,10 @@ def __init__(self, socket, name, status, pipe=None, is_server=False):
IPTOS_PREC_INTERNETCONTROL = 0xc0
DSCP_DEFAULT = IPTOS_PREC_INTERNETCONTROL >> 2

@staticmethod
def check_connection_completion(sock):
return ovs.socket_util.check_connection_completion(sock)

@staticmethod
def open(name, dscp=DSCP_DEFAULT):
"""Attempts to connect a stream to a remote peer. 'name' is a
Expand Down Expand Up @@ -191,7 +195,7 @@ def open(name, dscp=DSCP_DEFAULT):
if error:
return error, None
else:
err = ovs.socket_util.check_connection_completion(sock)
err = cls.check_connection_completion(sock)
if err == errno.EAGAIN or err == errno.EINPROGRESS:
status = errno.EAGAIN
err = 0
Expand Down Expand Up @@ -253,7 +257,7 @@ def close(self):

def __scs_connecting(self):
if self.socket is not None:
retval = ovs.socket_util.check_connection_completion(self.socket)
retval = self.check_connection_completion(self.socket)
assert retval != errno.EINPROGRESS
elif sys.platform == 'win32':
if self.retry_connect:
Expand Down Expand Up @@ -753,6 +757,13 @@ def _open(suffix, dscp):


class SSLStream(Stream):
@staticmethod
def check_connection_completion(sock):
try:
return Stream.check_connection_completion(sock)
except SSL.SysCallError as e:
return ovs.socket_util.get_exception_errno(e)

@staticmethod
def needs_probes():
return True
Expand Down

0 comments on commit 9d17f7b

Please sign in to comment.