Change in vdsm[ovirt-3.5]: vdscli: allow a connection with a configurable timeout

ykaplan at redhat.com ykaplan at redhat.com
Thu Mar 19 12:58:29 UTC 2015


Hello Dan Kenigsberg,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/38940

to review the following change.

Change subject: vdscli: allow a connection with a configurable timeout
......................................................................

vdscli: allow a connection with a configurable timeout

Add an option to connect to vdscli with any configurable
timeout, to allow the user a larger timeout than the
default ssl 60 seconds.
Especially useful for long duration storage operations.

Change-Id: I10829e7491c1e3c917080664c0eea643f054247e
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1190207
Signed-off-by: Yeela Kaplan <ykaplan at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/38751
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
---
M lib/vdsm/SecureXMLRPCServer.py
M lib/vdsm/sslutils.py
M lib/vdsm/vdscli.py.in
3 files changed, 21 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/40/38940/1

diff --git a/lib/vdsm/SecureXMLRPCServer.py b/lib/vdsm/SecureXMLRPCServer.py
index 8805f87..96b009a 100644
--- a/lib/vdsm/SecureXMLRPCServer.py
+++ b/lib/vdsm/SecureXMLRPCServer.py
@@ -35,7 +35,7 @@
 import SocketServer
 import logging
 
-from sslutils import SSLServerSocket
+from sslutils import SSLServerSocket, SOCKET_DEFAULT_TIMEOUT
 
 from .utils import IPXMLRPCRequestHandler, IPXMLRPCServer
 
@@ -76,7 +76,7 @@
 
 class VerifyingHTTPSConnection(httplib.HTTPSConnection):
     def __init__(self, host, port=None, key_file=None, cert_file=None,
-                 strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
+                 strict=None, timeout=SOCKET_DEFAULT_TIMEOUT,
                  ca_certs=None, cert_reqs=ssl.CERT_REQUIRED):
         httplib.HTTPSConnection.__init__(self, host, port, key_file, cert_file,
                                          strict, timeout)
@@ -98,12 +98,14 @@
 
 class VerifyingSafeTransport(xmlrpclib.SafeTransport):
     def __init__(self, use_datetime=0, key_file=None, cert_file=None,
-                 ca_certs=None, cert_reqs=ssl.CERT_REQUIRED):
+                 ca_certs=None, cert_reqs=ssl.CERT_REQUIRED
+                 timeout=SOCKET_DEFAULT_TIMEOUT):
         xmlrpclib.SafeTransport.__init__(self, use_datetime)
         self.key_file = key_file
         self.cert_file = cert_file
         self.ca_certs = ca_certs
         self.cert_reqs = cert_reqs
+        self._timeout = timeout
 
     def make_connection(self, host):
         """Return VerifyingHTTPS object that is aware of ca_certs, and will
@@ -114,12 +116,14 @@
         if hasattr(xmlrpclib.SafeTransport, "single_request"):   # Python 2.7
             return VerifyingHTTPSConnection(
                 chost, None, key_file=self.key_file, strict=None,
-                cert_file=self.cert_file, ca_certs=self.ca_certs,
+                cert_file=self.cert_file, timeout=self._timeout,
+                ca_certs=self.ca_certs,
                 cert_reqs=self.cert_reqs)
         else:
             return VerifyingHTTPS(
                 chost, None, key_file=self.key_file,
-                cert_file=self.cert_file, ca_certs=self.ca_certs,
+                cert_file=self.cert_file, timeout=self._timeout,
+                ca_certs=self.ca_certs,
                 cert_reqs=self.cert_reqs)
 
 
@@ -127,7 +131,8 @@
     _connection_class = VerifyingHTTPSConnection
 
     def __init__(self, host='', port=None, key_file=None, cert_file=None,
-                 strict=None, ca_certs=None, cert_reqs=ssl.CERT_REQUIRED):
+                 strict=None, timeout=SOCKET_DEFAULT_TIMEOUT,
+                 ca_certs=None, cert_reqs=ssl.CERT_REQUIRED):
         """A ca_cert-aware HTTPS object,
         that creates a VerifyingHTTPSConnection
         """
@@ -141,6 +146,7 @@
                                            key_file=key_file,
                                            cert_file=cert_file,
                                            strict=strict,
+                                           timeout=timeout,
                                            ca_certs=ca_certs,
                                            cert_reqs=cert_reqs))
 
diff --git a/lib/vdsm/sslutils.py b/lib/vdsm/sslutils.py
index 8cbaad0..a058c77 100644
--- a/lib/vdsm/sslutils.py
+++ b/lib/vdsm/sslutils.py
@@ -28,6 +28,7 @@
 
 
 DEFAULT_ACCEPT_TIMEOUT = 5
+SOCKET_DEFAULT_TIMEOUT = socket._GLOBAL_DEFAULT_TIMEOUT
 
 
 class SSLSocket(object):
diff --git a/lib/vdsm/vdscli.py.in b/lib/vdsm/vdscli.py.in
index 8e3922f..4f5b6d7 100644
--- a/lib/vdsm/vdscli.py.in
+++ b/lib/vdsm/vdscli.py.in
@@ -93,6 +93,8 @@
 
 def connect(hostPort=None, useSSL=None, tsPath=None,
             TransportClass=SecureXMLRPCServer.VerifyingSafeTransport):
+            timeout=sslutils.SOCKET_DEFAULT_TIMEOUT):
+
     hostPort = cannonizeHostPort(hostPort)
     if useSSL is None:
         useSSL = d_useSSL
@@ -108,10 +110,15 @@
                 raise Exception("No permission to read file: %s" % f)
 
         transport = TransportClass(key_file=KEYFILE,
-                                   cert_file=CERTFILE, ca_certs=CACERT)
+                                   cert_file=CERTFILE, ca_certs=CACERT,
+                                   timeout=timeout)
         server = xmlrpclib.ServerProxy('https://%s' % hostPort,
                                        wrap_transport(transport))
     else:
+        # TODO: add timeout option for HTTP connection
+        if timeout is not sslutils.SOCKET_DEFAULT_TIMEOUT:
+            raise NotImplementedError('timeout is not supported in'
+                                      ' plaintext connection')
         transport = wrap_transport(SingleRequestTransport())
         server = xmlrpclib.Server('http://%s' % hostPort, transport)
     return server


-- 
To view, visit https://gerrit.ovirt.org/38940
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I10829e7491c1e3c917080664c0eea643f054247e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Yeela Kaplan <ykaplan at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>


More information about the vdsm-patches mailing list