support urllib3 newer DEFAULT_TIMEOUT
urllib3 1.x used to accept socket._GLOBAL_DEFAULT_TIMEOUT as a sentinal object to mean "no configured timeout". In urllib3 2.x, urllib3 uses its own _DEFAULT_TIMEOUT sentinal object, and it rejects socket._GLOBAL_DEFAULT_TIMEOUT. Assign our own DEFAULT_TIMEOUT constant to the newer object if it exists, and fall back to the old behavior on old urllib3 versions. Co-authored-by: Vsevolod Fedorov <vsevolod.fedorov@gmail.com> Closes-Bug: #2018567 Change-Id: Ic626ba0e8ed79eec3a63ffab6cc02f91aa545ab1
This commit is contained in:
parent
628c3d00e9
commit
ba9f06e0c2
@ -58,6 +58,7 @@ import warnings
|
||||
import multi_key_dict
|
||||
import requests
|
||||
import requests.exceptions as req_exc
|
||||
import urllib3.util.timeout
|
||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||
from six.moves.http_client import BadStatusLine
|
||||
from six.moves.urllib.error import URLError
|
||||
@ -91,6 +92,7 @@ LAUNCHER_COMMAND = 'hudson.slaves.CommandLauncher'
|
||||
LAUNCHER_JNLP = 'hudson.slaves.JNLPLauncher'
|
||||
LAUNCHER_WINDOWS_SERVICE = 'hudson.os.windows.ManagedWindowsServiceLauncher'
|
||||
DEFAULT_HEADERS = {'Content-Type': 'text/xml; charset=utf-8'}
|
||||
DEFAULT_TIMEOUT = getattr(urllib3.util.timeout, '_DEFAULT_TIMEOUT', socket._GLOBAL_DEFAULT_TIMEOUT)
|
||||
|
||||
# REST Endpoints
|
||||
INFO = 'api/json'
|
||||
@ -300,7 +302,7 @@ class Jenkins(object):
|
||||
_timeout_warning_issued = False
|
||||
|
||||
def __init__(self, url, username=None, password=None,
|
||||
timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
|
||||
timeout=DEFAULT_TIMEOUT):
|
||||
'''Create handle to Jenkins instance.
|
||||
|
||||
All methods will raise :class:`JenkinsException` on failure.
|
||||
@ -2247,7 +2249,7 @@ class Jenkins(object):
|
||||
raise ValueError("Timeout must be >= 0 not %d" % timeout)
|
||||
|
||||
if (not self._timeout_warning_issued and
|
||||
self.timeout != socket._GLOBAL_DEFAULT_TIMEOUT and
|
||||
self.timeout != DEFAULT_TIMEOUT and
|
||||
timeout < self.timeout):
|
||||
warnings.warn("Requested timeout to wait for jenkins to resume "
|
||||
"normal operations is less than configured "
|
||||
|
@ -1,5 +1,4 @@
|
||||
import json
|
||||
import socket
|
||||
|
||||
from mock import patch
|
||||
import six
|
||||
@ -68,7 +67,7 @@ class JenkinsConstructorTest(JenkinsTestBase):
|
||||
|
||||
def test_default_timeout(self):
|
||||
j = jenkins.Jenkins('{0}'.format(self.base_url))
|
||||
self.assertEqual(j.timeout, socket._GLOBAL_DEFAULT_TIMEOUT)
|
||||
self.assertEqual(j.timeout, jenkins.DEFAULT_TIMEOUT)
|
||||
|
||||
def test_custom_timeout(self):
|
||||
j = jenkins.Jenkins('{0}'.format(self.base_url), timeout=300)
|
||||
|
Loading…
Reference in New Issue
Block a user