Deprecate create v2_0 Client without session
There was a comment to deprecate creating a v2_0 Client without a session. bp deprecations Change-Id: I71ff64754c8f90d184615eeec558718c11a1794a
This commit is contained in:
@@ -36,9 +36,11 @@ class BaseTest(utils.TestCase):
|
||||
self.assertEqual(base.getid(TmpObject), 4)
|
||||
|
||||
def test_resource_lazy_getattr(self):
|
||||
self.client = client.Client(token=self.TEST_TOKEN,
|
||||
auth_url='http://127.0.0.1:5000',
|
||||
endpoint='http://127.0.0.1:5000')
|
||||
# Creating a Client not using session is deprecated.
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.client = client.Client(token=self.TEST_TOKEN,
|
||||
auth_url='http://127.0.0.1:5000',
|
||||
endpoint='http://127.0.0.1:5000')
|
||||
|
||||
self.useFixture(mockpatch.PatchObject(
|
||||
self.client._adapter, 'get', side_effect=AttributeError,
|
||||
@@ -83,9 +85,13 @@ class ManagerTest(utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ManagerTest, self).setUp()
|
||||
self.client = client.Client(token=self.TEST_TOKEN,
|
||||
auth_url='http://127.0.0.1:5000',
|
||||
endpoint='http://127.0.0.1:5000')
|
||||
|
||||
# Creating a Client not using session is deprecated.
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.client = client.Client(token=self.TEST_TOKEN,
|
||||
auth_url='http://127.0.0.1:5000',
|
||||
endpoint='http://127.0.0.1:5000')
|
||||
|
||||
self.mgr = base.Manager(self.client)
|
||||
self.mgr.resource_class = base.Resource
|
||||
|
||||
|
@@ -93,10 +93,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
# where with assertRaises(exceptions.Unauthorized): doesn't work
|
||||
# right
|
||||
def client_create_wrapper():
|
||||
client.Client(username=self.TEST_USER,
|
||||
password="bad_key",
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
client.Client(username=self.TEST_USER,
|
||||
password="bad_key",
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
|
||||
self.assertRaises(exceptions.Unauthorized, client_create_wrapper)
|
||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||
@@ -108,10 +109,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
self.stub_auth(base_url=self.TEST_ADMIN_URL,
|
||||
json=self.TEST_RESPONSE_DICT)
|
||||
|
||||
cs = client.Client(username=self.TEST_USER,
|
||||
password=self.TEST_TOKEN,
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cs = client.Client(username=self.TEST_USER,
|
||||
password=self.TEST_TOKEN,
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
|
||||
self.assertEqual(cs.management_url,
|
||||
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
|
||||
@@ -123,10 +125,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
def test_authenticate_success_password_scoped(self):
|
||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||
|
||||
cs = client.Client(username=self.TEST_USER,
|
||||
password=self.TEST_TOKEN,
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cs = client.Client(username=self.TEST_USER,
|
||||
password=self.TEST_TOKEN,
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
self.assertEqual(cs.management_url,
|
||||
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
|
||||
['endpoints'][0]["adminURL"])
|
||||
@@ -140,9 +143,10 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
|
||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||
|
||||
cs = client.Client(username=self.TEST_USER,
|
||||
password=self.TEST_TOKEN,
|
||||
auth_url=self.TEST_URL)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cs = client.Client(username=self.TEST_USER,
|
||||
password=self.TEST_TOKEN,
|
||||
auth_url=self.TEST_URL)
|
||||
self.assertEqual(cs.auth_token,
|
||||
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
||||
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
|
||||
@@ -157,8 +161,9 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
self.stub_url('GET', [fake_url], json=fake_resp,
|
||||
base_url=self.TEST_ADMIN_IDENTITY_ENDPOINT)
|
||||
|
||||
cl = client.Client(auth_url=self.TEST_URL,
|
||||
token=fake_token)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cl = client.Client(auth_url=self.TEST_URL,
|
||||
token=fake_token)
|
||||
json_body = jsonutils.loads(self.requests_mock.last_request.body)
|
||||
self.assertEqual(json_body['auth']['token']['id'], fake_token)
|
||||
|
||||
@@ -174,9 +179,10 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
self.TEST_REQUEST_BODY['auth']['token'] = {'id': self.TEST_TOKEN}
|
||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||
|
||||
cs = client.Client(token=self.TEST_TOKEN,
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cs = client.Client(token=self.TEST_TOKEN,
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
self.assertEqual(cs.management_url,
|
||||
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
|
||||
['endpoints'][0]["adminURL"])
|
||||
@@ -193,10 +199,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
"id": self.TEST_TRUST_ID}
|
||||
self.stub_auth(json=response)
|
||||
|
||||
cs = client.Client(token=self.TEST_TOKEN,
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
trust_id=self.TEST_TRUST_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cs = client.Client(token=self.TEST_TOKEN,
|
||||
project_id=self.TEST_TENANT_ID,
|
||||
trust_id=self.TEST_TRUST_ID,
|
||||
auth_url=self.TEST_URL)
|
||||
self.assertTrue(cs.auth_ref.trust_scoped)
|
||||
self.assertEqual(cs.auth_ref.trust_id, self.TEST_TRUST_ID)
|
||||
self.assertEqual(cs.auth_ref.trustee_user_id, self.TEST_USER)
|
||||
@@ -210,8 +217,9 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
|
||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||
|
||||
cs = client.Client(token=self.TEST_TOKEN,
|
||||
auth_url=self.TEST_URL)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cs = client.Client(token=self.TEST_TOKEN,
|
||||
auth_url=self.TEST_URL)
|
||||
self.assertEqual(cs.auth_token,
|
||||
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
||||
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
|
||||
@@ -226,10 +234,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
self.stub_url('GET', [fake_url], json=fake_resp,
|
||||
base_url=self.TEST_ADMIN_IDENTITY_ENDPOINT)
|
||||
|
||||
cl = client.Client(username='exampleuser',
|
||||
password='password',
|
||||
project_name='exampleproject',
|
||||
auth_url=self.TEST_URL)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cl = client.Client(username='exampleuser',
|
||||
password='password',
|
||||
project_name='exampleproject',
|
||||
auth_url=self.TEST_URL)
|
||||
|
||||
self.assertEqual(cl.auth_token, self.TEST_TOKEN)
|
||||
|
||||
|
@@ -78,9 +78,12 @@ class TestCase(UnauthenticatedTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCase, self).setUp()
|
||||
self.client = client.Client(token=self.TEST_TOKEN,
|
||||
auth_url=self.TEST_URL,
|
||||
endpoint=self.TEST_URL)
|
||||
|
||||
# Creating a Client not using session is deprecated.
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.client = client.Client(token=self.TEST_TOKEN,
|
||||
auth_url=self.TEST_URL,
|
||||
endpoint=self.TEST_URL)
|
||||
|
||||
def stub_auth(self, **kwargs):
|
||||
self.stub_url('POST', ['tokens'], **kwargs)
|
||||
|
@@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
from keystoneclient.auth.identity import v2 as v2_auth
|
||||
from keystoneclient import exceptions
|
||||
@@ -79,6 +80,11 @@ class Client(httpclient.HTTPClient):
|
||||
If debug is enabled, it may show passwords in plain text as a part of
|
||||
its output.
|
||||
|
||||
.. warning::
|
||||
|
||||
Constructing an instance of this class without a session is
|
||||
deprecated as of the 1.7.0 release and will be removed in the
|
||||
2.0.0 release.
|
||||
|
||||
The client can be created and used like a user or in a strictly
|
||||
bootstrap mode. Normal operation expects a username, password, auth_url,
|
||||
@@ -130,6 +136,14 @@ class Client(httpclient.HTTPClient):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Initialize a new client for the Keystone v2.0 API."""
|
||||
|
||||
if not kwargs.get('session'):
|
||||
warnings.warn(
|
||||
'Constructing an instance of the '
|
||||
'keystoneclient.v2_0.client.Client class without a session is '
|
||||
'deprecated as of the 1.7.0 release and may be removed in '
|
||||
'the 2.0.0 release.', DeprecationWarning)
|
||||
|
||||
super(Client, self).__init__(**kwargs)
|
||||
|
||||
self.certificates = certificates.CertificatesManager(self._adapter)
|
||||
|
Reference in New Issue
Block a user