Commit 8ad4ec2f authored by Łukasz Nowak's avatar Łukasz Nowak

Implement default timeout for slap communication.

Currently slap library was coded with optimistic assumption, that remote system
are not failing. But in order not to block library caller it is required to
setup timeout on socket operations, with default different than infinity.
parent 19a22a86
......@@ -413,13 +413,14 @@ class ConnectionHelper:
check given master-url argument, and make sure that IPv6 is enabled on \
your machine and that the server is available. The original error was:"
def __init__(self, connection_wrapper, host, path, key_file=None,
cert_file=None, master_ca_file=None):
cert_file=None, master_ca_file=None, timeout=None):
self.connection_wrapper = connection_wrapper
self.host = host
self.path = path
self.key_file = key_file
self.cert_file = cert_file
self.master_ca_file = master_ca_file
self.timeout = timeout
def getComputerInformation(self, computer_id):
self.GET('/getComputerInformation?computer_id=%s' % computer_id)
......@@ -437,6 +438,9 @@ your machine and that the server is available. The original error was:"
self.connection = self.connection_wrapper(**connection_dict)
def GET(self, path):
try:
default_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(self.timeout)
try:
self.connect()
self.connection.request('GET', self.path + path)
......@@ -455,9 +459,14 @@ your machine and that the server is available. The original error was:"
message = 'Server responded with wrong code %s with %s' % \
(self.response.status, path)
raise ServerError(message)
finally:
socket.setdefaulttimeout(default_timeout)
def POST(self, path, parameter_dict,
content_type="application/x-www-form-urlencoded"):
try:
default_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(self.timeout)
try:
self.connect()
header_dict = {'Content-type': content_type}
......@@ -478,18 +487,20 @@ your machine and that the server is available. The original error was:"
message = 'Server responded with wrong code %s with %s' % \
(self.response.status, path)
raise ServerError(message)
finally:
socket.setdefaulttimeout(default_timeout)
class slap:
zope.interface.implements(interface.slap)
def initializeConnection(self, slapgrid_uri, key_file=None, cert_file=None,
master_ca_file=None):
master_ca_file=None, timeout=60):
self._initialiseConnectionHelper(slapgrid_uri, key_file, cert_file,
master_ca_file)
master_ca_file, timeout)
def _initialiseConnectionHelper(self, slapgrid_uri, key_file, cert_file,
master_ca_file):
master_ca_file, timeout):
SlapDocument._slapgrid_uri = slapgrid_uri
scheme, netloc, path, query, fragment = urlparse.urlsplit(
SlapDocument._slapgrid_uri)
......@@ -509,7 +520,7 @@ class slap:
connection_wrapper = httplib.HTTPSConnection
slap._connection_helper = \
SlapDocument._connection_helper = ConnectionHelper(connection_wrapper,
netloc, path, key_file, cert_file, master_ca_file)
netloc, path, key_file, cert_file, master_ca_file, timeout)
def _register(self, klass, *registration_argument_list):
if len(registration_argument_list) == 1 and type(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment