Merge "Don't use a connection pool unless provided"

This commit is contained in:
Jenkins 2014-03-23 16:17:13 +00:00 committed by Gerrit Code Review
commit ce342dc6c9
3 changed files with 21 additions and 6 deletions

@ -28,6 +28,22 @@ def request(url, method='GET', **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):
user_agent = None
@ -75,7 +91,7 @@ class Session(object):
for forever/never. (optional, default to 30)
"""
if not session:
session = requests.Session()
session = _FakeRequestSession()
self.auth = auth
self.session = session

@ -14,7 +14,6 @@ import mock
import requests
from keystoneclient import httpclient
from keystoneclient import session
from keystoneclient.tests import utils
@ -50,7 +49,7 @@ class ClientTest(utils.TestCase):
self.request_patcher.start()
self.addCleanup(self.request_patcher.stop)
@mock.patch.object(session.requests.Session, 'request')
@mock.patch.object(requests, 'request')
def test_get(self, MOCK_REQUEST):
MOCK_REQUEST.return_value = FAKE_RESPONSE
cl = get_authed_client()
@ -69,7 +68,7 @@ class ClientTest(utils.TestCase):
# Automatic JSON parsing
self.assertEqual(body, {"hi": "there"})
@mock.patch.object(session.requests.Session, 'request')
@mock.patch.object(requests, 'request')
def test_post(self, MOCK_REQUEST):
MOCK_REQUEST.return_value = FAKE_RESPONSE
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['verify'], 'ca.pem')
@mock.patch.object(session.requests.Session, 'request')
@mock.patch.object(requests, 'request')
def test_post_auth(self, MOCK_REQUEST):
MOCK_REQUEST.return_value = FAKE_RESPONSE
cl = httpclient.HTTPClient(

@ -441,7 +441,7 @@ class ShellTest(utils.TestCase):
'endpoints': [],
})
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):
shell(('--timeout 2 --os-token=blah --os-endpoint=blah'
' --os-auth-url=blah.com endpoint-list'))