diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-09-02 10:51:31 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-09-02 10:51:31 +0000 |
commit | b0d7405a5b4345ac2711193e4ceeca9fb299bc38 (patch) | |
tree | 5b8660c1280a5f0476393c18ed0c4bfc4577507d | |
parent | f58661e5041374a8d3cfa8a5eb3c16089b806edb (diff) | |
parent | 42bd016e1f0e011ba745dba243e62401298e324c (diff) | |
download | python-keystoneclient-b0d7405a5b4345ac2711193e4ceeca9fb299bc38.tar.gz |
Merge "Deprecate create HTTPClient without session"
-rw-r--r-- | keystoneclient/httpclient.py | 40 | ||||
-rw-r--r-- | keystoneclient/tests/unit/generic/test_client.py | 4 | ||||
-rw-r--r-- | keystoneclient/tests/unit/test_http.py | 30 | ||||
-rw-r--r-- | keystoneclient/tests/unit/test_https.py | 18 | ||||
-rw-r--r-- | keystoneclient/tests/unit/test_keyring.py | 36 |
5 files changed, 93 insertions, 35 deletions
diff --git a/keystoneclient/httpclient.py b/keystoneclient/httpclient.py index 3fcbca3..b15db24 100644 --- a/keystoneclient/httpclient.py +++ b/keystoneclient/httpclient.py @@ -148,6 +148,12 @@ class _KeystoneAdapter(adapter.LegacyJsonAdapter): class HTTPClient(baseclient.Client, base.BaseAuthPlugin): """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 username: Username for authentication. (optional) :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 region_name: Name of a region to select when choosing an 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 service. Lazy-authentication is possible for API service calls if endpoint is set at instantiation. (optional) :param string token: Token for authentication. (optional) - :param string cacert: DEPRECATED: use session. (optional) - :param string key: DEPRECATED: use session. (optional) - :param string cert: DEPRECATED: use session. (optional) - :param boolean insecure: DEPRECATED: use session. (optional) - :param string original_ip: DEPRECATED: use session. (optional) - :param boolean debug: DEPRECATED: use logging configuration. (optional) + :param string cacert: 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 key: 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 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 own caching strategy, you may initialize a client with a previously captured auth_reference (token). If @@ -345,6 +365,12 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin): self._auth_token = None 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() session = client_session.Session._construct(kwargs) session.auth = self diff --git a/keystoneclient/tests/unit/generic/test_client.py b/keystoneclient/tests/unit/generic/test_client.py index 6eb6836..a3690fb 100644 --- a/keystoneclient/tests/unit/generic/test_client.py +++ b/keystoneclient/tests/unit/generic/test_client.py @@ -57,7 +57,9 @@ class ClientDiscoveryTests(utils.TestCase): def test_discover_extensions_v2(self): self.requests_mock.get("%s/extensions" % V2_URL, text=EXTENSION_LIST) - extensions = client.Client().discover_extensions(url=V2_URL) + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + extensions = client.Client().discover_extensions(url=V2_URL) self.assertIn(EXTENSION_ALIAS_FOO, extensions) self.assertEqual(extensions[EXTENSION_ALIAS_FOO], EXTENSION_NAME_FOO) self.assertIn(EXTENSION_ALIAS_BAR, extensions) diff --git a/keystoneclient/tests/unit/test_http.py b/keystoneclient/tests/unit/test_http.py index 2b29ee7..4c37851 100644 --- a/keystoneclient/tests/unit/test_http.py +++ b/keystoneclient/tests/unit/test_http.py @@ -56,14 +56,18 @@ class ClientTest(utils.TestCase): TEST_URL = 'http://127.0.0.1:5000/hi' def test_unauthorized_client_requests(self): - cl = get_client() + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = get_client() self.assertRaises(exceptions.AuthorizationFailure, cl.get, '/hi') self.assertRaises(exceptions.AuthorizationFailure, cl.post, '/hi') self.assertRaises(exceptions.AuthorizationFailure, cl.put, '/hi') self.assertRaises(exceptions.AuthorizationFailure, cl.delete, '/hi') def test_get(self): - cl = get_authed_client() + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = get_authed_client() self.stub_url('GET', text=RESPONSE_BODY) @@ -79,14 +83,18 @@ class ClientTest(utils.TestCase): self.assertEqual(body, {"hi": "there"}) def test_get_error_with_plaintext_resp(self): - cl = get_authed_client() + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = get_authed_client() self.stub_url('GET', status_code=400, text='Some evil plaintext string') self.assertRaises(exceptions.BadRequest, cl.get, '/hi') def test_get_error_with_json_resp(self): - cl = get_authed_client() + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = get_authed_client() err_response = { "error": { "code": 400, @@ -105,7 +113,9 @@ class ClientTest(utils.TestCase): self.assertTrue(exc_raised, 'Exception not raised.') def test_post(self): - cl = get_authed_client() + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = get_authed_client() self.stub_url('POST') with self.deprecations.expect_deprecations_here(): @@ -120,9 +130,13 @@ class ClientTest(utils.TestCase): def test_forwarded_for(self): ORIGINAL_IP = "10.100.100.1" - cl = httpclient.HTTPClient(username="username", password="password", - project_id="tenant", auth_url="auth_test", - original_ip=ORIGINAL_IP) + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = httpclient.HTTPClient(username="username", + password="password", + project_id="tenant", + auth_url="auth_test", + original_ip=ORIGINAL_IP) self.stub_url('GET') diff --git a/keystoneclient/tests/unit/test_https.py b/keystoneclient/tests/unit/test_https.py index e04357a..14c3cdc 100644 --- a/keystoneclient/tests/unit/test_https.py +++ b/keystoneclient/tests/unit/test_https.py @@ -45,7 +45,9 @@ class ClientTest(utils.TestCase): @mock.patch.object(requests, 'request') def test_get(self, MOCK_REQUEST): MOCK_REQUEST.return_value = FAKE_RESPONSE - cl = get_authed_client() + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = get_authed_client() with self.deprecations.expect_deprecations_here(): resp, body = cl.get("/hi") @@ -65,7 +67,9 @@ class ClientTest(utils.TestCase): @mock.patch.object(requests, 'request') def test_post(self, MOCK_REQUEST): MOCK_REQUEST.return_value = FAKE_RESPONSE - cl = get_authed_client() + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = get_authed_client() with self.deprecations.expect_deprecations_here(): cl.post("/hi", body=[1, 2, 3]) @@ -83,10 +87,12 @@ class ClientTest(utils.TestCase): @mock.patch.object(requests, 'request') def test_post_auth(self, MOCK_REQUEST): MOCK_REQUEST.return_value = FAKE_RESPONSE - cl = httpclient.HTTPClient( - username="username", password="password", project_id="tenant", - auth_url="auth_test", cacert="ca.pem", cert=('cert.pem', 'key.pem') - ) + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = httpclient.HTTPClient( + username="username", password="password", project_id="tenant", + auth_url="auth_test", cacert="ca.pem", + cert=('cert.pem', 'key.pem')) cl.management_url = "https://127.0.0.1:5000" cl.auth_token = "token" with self.deprecations.expect_deprecations_here(): diff --git a/keystoneclient/tests/unit/test_keyring.py b/keystoneclient/tests/unit/test_keyring.py index defd233..2868a8f 100644 --- a/keystoneclient/tests/unit/test_keyring.py +++ b/keystoneclient/tests/unit/test_keyring.py @@ -87,8 +87,10 @@ class KeyringTest(utils.TestCase): """Ensure that if we don't have use_keyring set in the client that the keyring is never accessed. """ - cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, - project_id=TENANT_ID, auth_url=AUTH_URL) + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, + project_id=TENANT_ID, auth_url=AUTH_URL) # stub and check that a new token is received method = 'get_raw_token_from_identity_service' @@ -104,8 +106,10 @@ class KeyringTest(utils.TestCase): self.assertFalse(self.memory_keyring.set_password_called) def test_build_keyring_key(self): - cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, - project_id=TENANT_ID, auth_url=AUTH_URL) + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, + project_id=TENANT_ID, auth_url=AUTH_URL) keyring_key = cl._build_keyring_key(auth_url=AUTH_URL, username=USERNAME, @@ -118,9 +122,11 @@ class KeyringTest(utils.TestCase): (AUTH_URL, TENANT_ID, TENANT, TOKEN, USERNAME)) def test_set_and_get_keyring_expired(self): - cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, - project_id=TENANT_ID, auth_url=AUTH_URL, - use_keyring=True) + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, + project_id=TENANT_ID, auth_url=AUTH_URL, + use_keyring=True) # set an expired token into the keyring auth_ref = access.AccessInfo.factory(body=PROJECT_SCOPED_TOKEN) @@ -146,9 +152,11 @@ class KeyringTest(utils.TestCase): PROJECT_SCOPED_TOKEN['access']['token']['expires']) def test_get_keyring(self): - cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, - project_id=TENANT_ID, auth_url=AUTH_URL, - use_keyring=True) + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, + project_id=TENANT_ID, auth_url=AUTH_URL, + use_keyring=True) # set an token into the keyring auth_ref = access.AccessInfo.factory(body=PROJECT_SCOPED_TOKEN) @@ -162,9 +170,11 @@ class KeyringTest(utils.TestCase): self.assertTrue(self.memory_keyring.fetched) def test_set_keyring(self): - cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, - project_id=TENANT_ID, auth_url=AUTH_URL, - use_keyring=True) + # Creating a HTTPClient not using session is deprecated. + with self.deprecations.expect_deprecations_here(): + cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD, + project_id=TENANT_ID, auth_url=AUTH_URL, + use_keyring=True) # stub and check that a new token is received method = 'get_raw_token_from_identity_service' |