Deprecate create HTTPClient without session

The comments indicated that creating a HTTPClient without a
session is deprecated, but there was no warning generated.

bp deprecations

Change-Id: I44796cbff95a7bbdd6e7a58e5cfb8360bdae5477
This commit is contained in:
Brant Knudson
2015-07-26 09:52:16 -05:00
parent ee6d64a8fb
commit 42bd016e1f
5 changed files with 93 additions and 35 deletions

View File

@@ -148,6 +148,12 @@ class _KeystoneAdapter(adapter.LegacyJsonAdapter):
class HTTPClient(baseclient.Client, base.BaseAuthPlugin): class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
"""HTTP client """HTTP client
.. warning::
Creating an instance of this class without using the session argument
is deprecated as of the 1.7.0 release and may be removed in the 2.0.0
release.
:param string user_id: User ID for authentication. (optional) :param string user_id: User ID for authentication. (optional)
:param string username: Username for authentication. (optional) :param string username: Username for authentication. (optional)
:param string user_domain_id: User's domain ID for authentication. :param string user_domain_id: User's domain ID for authentication.
@@ -166,18 +172,32 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
:param string auth_url: Identity service endpoint for authorization. :param string auth_url: Identity service endpoint for authorization.
:param string region_name: Name of a region to select when choosing an :param string region_name: Name of a region to select when choosing an
endpoint from the service catalog. endpoint from the service catalog.
:param integer timeout: DEPRECATED: use session. (optional) :param integer timeout: This argument is deprecated as of the 1.7.0 release
in favor of session and may be removed in the 2.0.0
release. (optional)
:param string endpoint: A user-supplied endpoint URL for the identity :param string endpoint: A user-supplied endpoint URL for the identity
service. Lazy-authentication is possible for API service. Lazy-authentication is possible for API
service calls if endpoint is set at instantiation. service calls if endpoint is set at instantiation.
(optional) (optional)
:param string token: Token for authentication. (optional) :param string token: Token for authentication. (optional)
:param string cacert: DEPRECATED: use session. (optional) :param string cacert: This argument is deprecated as of the 1.7.0 release
:param string key: DEPRECATED: use session. (optional) in favor of session and may be removed in the 2.0.0
:param string cert: DEPRECATED: use session. (optional) release. (optional)
:param boolean insecure: DEPRECATED: use session. (optional) :param string key: This argument is deprecated as of the 1.7.0 release
:param string original_ip: DEPRECATED: use session. (optional) in favor of session and may be removed in the 2.0.0
:param boolean debug: DEPRECATED: use logging configuration. (optional) release. (optional)
:param string cert: This argument is deprecated as of the 1.7.0 release
in favor of session and may be removed in the 2.0.0
release. (optional)
:param boolean insecure: This argument is deprecated as of the 1.7.0
release in favor of session and may be removed in
the 2.0.0 release. (optional)
:param string original_ip: This argument is deprecated as of the 1.7.0
release in favor of session and may be removed
in the 2.0.0 release. (optional)
:param boolean debug: This argument is deprecated as of the 1.7.0 release
in favor of logging configuration and may be removed
in the 2.0.0 release. (optional)
:param dict auth_ref: To allow for consumers of the client to manage their :param dict auth_ref: To allow for consumers of the client to manage their
own caching strategy, you may initialize a client own caching strategy, you may initialize a client
with a previously captured auth_reference (token). If with a previously captured auth_reference (token). If
@@ -345,6 +365,12 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
self._auth_token = None self._auth_token = None
if not session: if not session:
warnings.warn(
'Constructing an HTTPClient instance without using a session '
'is deprecated as of the 1.7.0 release and may be removed in '
'the 2.0.0 release.', DeprecationWarning)
kwargs['session'] = _FakeRequestSession() kwargs['session'] = _FakeRequestSession()
session = client_session.Session._construct(kwargs) session = client_session.Session._construct(kwargs)
session.auth = self session.auth = self

View File

@@ -57,6 +57,8 @@ class ClientDiscoveryTests(utils.TestCase):
def test_discover_extensions_v2(self): def test_discover_extensions_v2(self):
self.requests_mock.get("%s/extensions" % V2_URL, text=EXTENSION_LIST) self.requests_mock.get("%s/extensions" % V2_URL, text=EXTENSION_LIST)
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
extensions = client.Client().discover_extensions(url=V2_URL) extensions = client.Client().discover_extensions(url=V2_URL)
self.assertIn(EXTENSION_ALIAS_FOO, extensions) self.assertIn(EXTENSION_ALIAS_FOO, extensions)
self.assertEqual(extensions[EXTENSION_ALIAS_FOO], EXTENSION_NAME_FOO) self.assertEqual(extensions[EXTENSION_ALIAS_FOO], EXTENSION_NAME_FOO)

View File

@@ -56,6 +56,8 @@ class ClientTest(utils.TestCase):
TEST_URL = 'http://127.0.0.1:5000/hi' TEST_URL = 'http://127.0.0.1:5000/hi'
def test_unauthorized_client_requests(self): def test_unauthorized_client_requests(self):
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = get_client() cl = get_client()
self.assertRaises(exceptions.AuthorizationFailure, cl.get, '/hi') self.assertRaises(exceptions.AuthorizationFailure, cl.get, '/hi')
self.assertRaises(exceptions.AuthorizationFailure, cl.post, '/hi') self.assertRaises(exceptions.AuthorizationFailure, cl.post, '/hi')
@@ -63,6 +65,8 @@ class ClientTest(utils.TestCase):
self.assertRaises(exceptions.AuthorizationFailure, cl.delete, '/hi') self.assertRaises(exceptions.AuthorizationFailure, cl.delete, '/hi')
def test_get(self): def test_get(self):
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = get_authed_client() cl = get_authed_client()
self.stub_url('GET', text=RESPONSE_BODY) self.stub_url('GET', text=RESPONSE_BODY)
@@ -79,6 +83,8 @@ class ClientTest(utils.TestCase):
self.assertEqual(body, {"hi": "there"}) self.assertEqual(body, {"hi": "there"})
def test_get_error_with_plaintext_resp(self): def test_get_error_with_plaintext_resp(self):
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = get_authed_client() cl = get_authed_client()
self.stub_url('GET', status_code=400, self.stub_url('GET', status_code=400,
text='Some evil plaintext string') text='Some evil plaintext string')
@@ -86,6 +92,8 @@ class ClientTest(utils.TestCase):
self.assertRaises(exceptions.BadRequest, cl.get, '/hi') self.assertRaises(exceptions.BadRequest, cl.get, '/hi')
def test_get_error_with_json_resp(self): def test_get_error_with_json_resp(self):
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = get_authed_client() cl = get_authed_client()
err_response = { err_response = {
"error": { "error": {
@@ -105,6 +113,8 @@ class ClientTest(utils.TestCase):
self.assertTrue(exc_raised, 'Exception not raised.') self.assertTrue(exc_raised, 'Exception not raised.')
def test_post(self): def test_post(self):
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = get_authed_client() cl = get_authed_client()
self.stub_url('POST') self.stub_url('POST')
@@ -120,8 +130,12 @@ class ClientTest(utils.TestCase):
def test_forwarded_for(self): def test_forwarded_for(self):
ORIGINAL_IP = "10.100.100.1" ORIGINAL_IP = "10.100.100.1"
cl = httpclient.HTTPClient(username="username", password="password", # Creating a HTTPClient not using session is deprecated.
project_id="tenant", auth_url="auth_test", with self.deprecations.expect_deprecations_here():
cl = httpclient.HTTPClient(username="username",
password="password",
project_id="tenant",
auth_url="auth_test",
original_ip=ORIGINAL_IP) original_ip=ORIGINAL_IP)
self.stub_url('GET') self.stub_url('GET')

View File

@@ -45,6 +45,8 @@ class ClientTest(utils.TestCase):
@mock.patch.object(requests, '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
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = get_authed_client() cl = get_authed_client()
with self.deprecations.expect_deprecations_here(): with self.deprecations.expect_deprecations_here():
@@ -65,6 +67,8 @@ class ClientTest(utils.TestCase):
@mock.patch.object(requests, '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
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = get_authed_client() cl = get_authed_client()
with self.deprecations.expect_deprecations_here(): with self.deprecations.expect_deprecations_here():
@@ -83,10 +87,12 @@ class ClientTest(utils.TestCase):
@mock.patch.object(requests, '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
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = httpclient.HTTPClient( cl = httpclient.HTTPClient(
username="username", password="password", project_id="tenant", username="username", password="password", project_id="tenant",
auth_url="auth_test", cacert="ca.pem", cert=('cert.pem', 'key.pem') auth_url="auth_test", cacert="ca.pem",
) cert=('cert.pem', 'key.pem'))
cl.management_url = "https://127.0.0.1:5000" cl.management_url = "https://127.0.0.1:5000"
cl.auth_token = "token" cl.auth_token = "token"
with self.deprecations.expect_deprecations_here(): with self.deprecations.expect_deprecations_here():

View File

@@ -87,6 +87,8 @@ class KeyringTest(utils.TestCase):
"""Ensure that if we don't have use_keyring set in the client that """Ensure that if we don't have use_keyring set in the client that
the keyring is never accessed. the keyring is never accessed.
""" """
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
project_id=TENANT_ID, auth_url=AUTH_URL) project_id=TENANT_ID, auth_url=AUTH_URL)
@@ -104,6 +106,8 @@ class KeyringTest(utils.TestCase):
self.assertFalse(self.memory_keyring.set_password_called) self.assertFalse(self.memory_keyring.set_password_called)
def test_build_keyring_key(self): def test_build_keyring_key(self):
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
project_id=TENANT_ID, auth_url=AUTH_URL) project_id=TENANT_ID, auth_url=AUTH_URL)
@@ -118,6 +122,8 @@ class KeyringTest(utils.TestCase):
(AUTH_URL, TENANT_ID, TENANT, TOKEN, USERNAME)) (AUTH_URL, TENANT_ID, TENANT, TOKEN, USERNAME))
def test_set_and_get_keyring_expired(self): def test_set_and_get_keyring_expired(self):
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
project_id=TENANT_ID, auth_url=AUTH_URL, project_id=TENANT_ID, auth_url=AUTH_URL,
use_keyring=True) use_keyring=True)
@@ -146,6 +152,8 @@ class KeyringTest(utils.TestCase):
PROJECT_SCOPED_TOKEN['access']['token']['expires']) PROJECT_SCOPED_TOKEN['access']['token']['expires'])
def test_get_keyring(self): def test_get_keyring(self):
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
project_id=TENANT_ID, auth_url=AUTH_URL, project_id=TENANT_ID, auth_url=AUTH_URL,
use_keyring=True) use_keyring=True)
@@ -162,6 +170,8 @@ class KeyringTest(utils.TestCase):
self.assertTrue(self.memory_keyring.fetched) self.assertTrue(self.memory_keyring.fetched)
def test_set_keyring(self): def test_set_keyring(self):
# Creating a HTTPClient not using session is deprecated.
with self.deprecations.expect_deprecations_here():
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
project_id=TENANT_ID, auth_url=AUTH_URL, project_id=TENANT_ID, auth_url=AUTH_URL,
use_keyring=True) use_keyring=True)