From 8fcacdc7c74f5ac68e8e55ea8c15918c452411fe Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Wed, 23 Jul 2014 09:14:56 +1000 Subject: [PATCH] Move fake session to HTTPClient The fake session object is to prevent a cyclical dependency between HTTPClient and the session from leaving hanging session objects around. This is still necessary if you construct a client the old way however if you are using the session properly then there is no cyclical dependency and so we shouldn't prevent people using the connection pooling advantages of the session. Related-Bug: #1282089 Change-Id: Ifca2c7ddd95a81af01ee43246ecc8e74abf95602 --- keystoneclient/httpclient.py | 18 ++++++++++++++++++ keystoneclient/session.py | 18 +----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/keystoneclient/httpclient.py b/keystoneclient/httpclient.py index 48e12b7cf..cab60bc08 100644 --- a/keystoneclient/httpclient.py +++ b/keystoneclient/httpclient.py @@ -22,6 +22,7 @@ OpenStack Client interface. Handles the REST calls and responses. import logging import pkg_resources +import requests from six.moves.urllib import parse as urlparse try: @@ -66,6 +67,22 @@ USER_AGENT = client_session.USER_AGENT request = client_session.request +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 HTTPClient(baseclient.Client, base.BaseAuthPlugin): version = None @@ -238,6 +255,7 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin): self._auth_token = None if not session: + kwargs['session'] = _FakeRequestSession() session = client_session.Session.construct(kwargs) session.auth = self diff --git a/keystoneclient/session.py b/keystoneclient/session.py index 5426d991a..12362d57f 100644 --- a/keystoneclient/session.py +++ b/keystoneclient/session.py @@ -49,22 +49,6 @@ 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 @@ -113,7 +97,7 @@ class Session(object): for forever/never. (optional, default to 30) """ if not session: - session = _FakeRequestSession() + session = requests.Session() self.auth = auth self.session = session