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
3 changed files with 21 additions and 6 deletions

View File

@@ -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

View File

@@ -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(

View File

@@ -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'))