Don't use a connection pool unless provided
To prevent left over TCP connections from keystoneclient not correctly cleaning up we shouldn't use a connection pool. This is not ideal but it was a relatively new addition so shouldn't affect performance. When we are able to find a long term solution to keystoneclient's other problems we can move back to using a connection pool. Change-Id: I45678ef89b88eea90ea04de1e3170f584b51fd8f Closes-Bug: #1282089
This commit is contained in:
@@ -28,6 +28,22 @@ def request(url, method='GET', **kwargs):
|
|||||||
return Session().request(url, method=method, **kwargs)
|
return Session().request(url, method=method, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class _FakeRequestSession(object):
|
||||||
|
"""This object is a temporary hack that should be removed later.
|
||||||
|
|
||||||
|
Keystoneclient has a cyclical dependency with its managers which is
|
||||||
|
preventing it from being cleaned up correctly. This is always bad but when
|
||||||
|
we switched to doing connection pooling this object wasn't getting cleaned
|
||||||
|
either and so we had left over TCP connections hanging around.
|
||||||
|
|
||||||
|
Until we can fix the client cleanup we rollback the use of a requests
|
||||||
|
session and do individual connections like we used to.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def request(self, *args, **kwargs):
|
||||||
|
return requests.request(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Session(object):
|
class Session(object):
|
||||||
|
|
||||||
user_agent = None
|
user_agent = None
|
||||||
@@ -75,7 +91,7 @@ class Session(object):
|
|||||||
for forever/never. (optional, default to 30)
|
for forever/never. (optional, default to 30)
|
||||||
"""
|
"""
|
||||||
if not session:
|
if not session:
|
||||||
session = requests.Session()
|
session = _FakeRequestSession()
|
||||||
|
|
||||||
self.auth = auth
|
self.auth = auth
|
||||||
self.session = session
|
self.session = session
|
||||||
|
@@ -14,7 +14,6 @@ import mock
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from keystoneclient import httpclient
|
from keystoneclient import httpclient
|
||||||
from keystoneclient import session
|
|
||||||
from keystoneclient.tests import utils
|
from keystoneclient.tests import utils
|
||||||
|
|
||||||
|
|
||||||
@@ -50,7 +49,7 @@ class ClientTest(utils.TestCase):
|
|||||||
self.request_patcher.start()
|
self.request_patcher.start()
|
||||||
self.addCleanup(self.request_patcher.stop)
|
self.addCleanup(self.request_patcher.stop)
|
||||||
|
|
||||||
@mock.patch.object(session.requests.Session, 'request')
|
@mock.patch.object(requests, 'request')
|
||||||
def test_get(self, MOCK_REQUEST):
|
def test_get(self, MOCK_REQUEST):
|
||||||
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
||||||
cl = get_authed_client()
|
cl = get_authed_client()
|
||||||
@@ -69,7 +68,7 @@ class ClientTest(utils.TestCase):
|
|||||||
# Automatic JSON parsing
|
# Automatic JSON parsing
|
||||||
self.assertEqual(body, {"hi": "there"})
|
self.assertEqual(body, {"hi": "there"})
|
||||||
|
|
||||||
@mock.patch.object(session.requests.Session, 'request')
|
@mock.patch.object(requests, 'request')
|
||||||
def test_post(self, MOCK_REQUEST):
|
def test_post(self, MOCK_REQUEST):
|
||||||
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
||||||
cl = get_authed_client()
|
cl = get_authed_client()
|
||||||
@@ -86,7 +85,7 @@ class ClientTest(utils.TestCase):
|
|||||||
self.assertEqual(mock_kwargs['cert'], ('cert.pem', 'key.pem'))
|
self.assertEqual(mock_kwargs['cert'], ('cert.pem', 'key.pem'))
|
||||||
self.assertEqual(mock_kwargs['verify'], 'ca.pem')
|
self.assertEqual(mock_kwargs['verify'], 'ca.pem')
|
||||||
|
|
||||||
@mock.patch.object(session.requests.Session, 'request')
|
@mock.patch.object(requests, 'request')
|
||||||
def test_post_auth(self, MOCK_REQUEST):
|
def test_post_auth(self, MOCK_REQUEST):
|
||||||
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
||||||
cl = httpclient.HTTPClient(
|
cl = httpclient.HTTPClient(
|
||||||
|
@@ -441,7 +441,7 @@ class ShellTest(utils.TestCase):
|
|||||||
'endpoints': [],
|
'endpoints': [],
|
||||||
})
|
})
|
||||||
request_mock = mock.MagicMock(return_value=response_mock)
|
request_mock = mock.MagicMock(return_value=response_mock)
|
||||||
with mock.patch.object(session.requests.Session, 'request',
|
with mock.patch.object(session.requests, 'request',
|
||||||
request_mock):
|
request_mock):
|
||||||
shell(('--timeout 2 --os-token=blah --os-endpoint=blah'
|
shell(('--timeout 2 --os-token=blah --os-endpoint=blah'
|
||||||
' --os-auth-url=blah.com endpoint-list'))
|
' --os-auth-url=blah.com endpoint-list'))
|
||||||
|
Reference in New Issue
Block a user