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:
Brant Knudson
2015-07-26 08:46:27 -05:00
parent 962ab574fd
commit b94a61012e
4 changed files with 71 additions and 39 deletions

View File

@@ -36,9 +36,11 @@ class BaseTest(utils.TestCase):
self.assertEqual(base.getid(TmpObject), 4) self.assertEqual(base.getid(TmpObject), 4)
def test_resource_lazy_getattr(self): def test_resource_lazy_getattr(self):
self.client = client.Client(token=self.TEST_TOKEN, # Creating a Client not using session is deprecated.
auth_url='http://127.0.0.1:5000', with self.deprecations.expect_deprecations_here():
endpoint='http://127.0.0.1:5000') 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.useFixture(mockpatch.PatchObject(
self.client._adapter, 'get', side_effect=AttributeError, self.client._adapter, 'get', side_effect=AttributeError,
@@ -83,9 +85,13 @@ class ManagerTest(utils.TestCase):
def setUp(self): def setUp(self):
super(ManagerTest, self).setUp() super(ManagerTest, self).setUp()
self.client = client.Client(token=self.TEST_TOKEN,
auth_url='http://127.0.0.1:5000', # Creating a Client not using session is deprecated.
endpoint='http://127.0.0.1:5000') 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 = base.Manager(self.client)
self.mgr.resource_class = base.Resource self.mgr.resource_class = base.Resource

View File

@@ -93,10 +93,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
# where with assertRaises(exceptions.Unauthorized): doesn't work # where with assertRaises(exceptions.Unauthorized): doesn't work
# right # right
def client_create_wrapper(): def client_create_wrapper():
client.Client(username=self.TEST_USER, with self.deprecations.expect_deprecations_here():
password="bad_key", client.Client(username=self.TEST_USER,
project_id=self.TEST_TENANT_ID, password="bad_key",
auth_url=self.TEST_URL) project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL)
self.assertRaises(exceptions.Unauthorized, client_create_wrapper) self.assertRaises(exceptions.Unauthorized, client_create_wrapper)
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY) self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
@@ -108,10 +109,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.stub_auth(base_url=self.TEST_ADMIN_URL, self.stub_auth(base_url=self.TEST_ADMIN_URL,
json=self.TEST_RESPONSE_DICT) json=self.TEST_RESPONSE_DICT)
cs = client.Client(username=self.TEST_USER, with self.deprecations.expect_deprecations_here():
password=self.TEST_TOKEN, cs = client.Client(username=self.TEST_USER,
project_id=self.TEST_TENANT_ID, password=self.TEST_TOKEN,
auth_url=self.TEST_URL) project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL)
self.assertEqual(cs.management_url, self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3] self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
@@ -123,10 +125,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
def test_authenticate_success_password_scoped(self): def test_authenticate_success_password_scoped(self):
self.stub_auth(json=self.TEST_RESPONSE_DICT) self.stub_auth(json=self.TEST_RESPONSE_DICT)
cs = client.Client(username=self.TEST_USER, with self.deprecations.expect_deprecations_here():
password=self.TEST_TOKEN, cs = client.Client(username=self.TEST_USER,
project_id=self.TEST_TENANT_ID, password=self.TEST_TOKEN,
auth_url=self.TEST_URL) project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL)
self.assertEqual(cs.management_url, self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3] self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
['endpoints'][0]["adminURL"]) ['endpoints'][0]["adminURL"])
@@ -140,9 +143,10 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.stub_auth(json=self.TEST_RESPONSE_DICT) self.stub_auth(json=self.TEST_RESPONSE_DICT)
cs = client.Client(username=self.TEST_USER, with self.deprecations.expect_deprecations_here():
password=self.TEST_TOKEN, cs = client.Client(username=self.TEST_USER,
auth_url=self.TEST_URL) password=self.TEST_TOKEN,
auth_url=self.TEST_URL)
self.assertEqual(cs.auth_token, self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"]) self.TEST_RESPONSE_DICT["access"]["token"]["id"])
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog) 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, self.stub_url('GET', [fake_url], json=fake_resp,
base_url=self.TEST_ADMIN_IDENTITY_ENDPOINT) base_url=self.TEST_ADMIN_IDENTITY_ENDPOINT)
cl = client.Client(auth_url=self.TEST_URL, with self.deprecations.expect_deprecations_here():
token=fake_token) cl = client.Client(auth_url=self.TEST_URL,
token=fake_token)
json_body = jsonutils.loads(self.requests_mock.last_request.body) json_body = jsonutils.loads(self.requests_mock.last_request.body)
self.assertEqual(json_body['auth']['token']['id'], fake_token) 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.TEST_REQUEST_BODY['auth']['token'] = {'id': self.TEST_TOKEN}
self.stub_auth(json=self.TEST_RESPONSE_DICT) self.stub_auth(json=self.TEST_RESPONSE_DICT)
cs = client.Client(token=self.TEST_TOKEN, with self.deprecations.expect_deprecations_here():
project_id=self.TEST_TENANT_ID, cs = client.Client(token=self.TEST_TOKEN,
auth_url=self.TEST_URL) project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL)
self.assertEqual(cs.management_url, self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3] self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
['endpoints'][0]["adminURL"]) ['endpoints'][0]["adminURL"])
@@ -193,10 +199,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
"id": self.TEST_TRUST_ID} "id": self.TEST_TRUST_ID}
self.stub_auth(json=response) self.stub_auth(json=response)
cs = client.Client(token=self.TEST_TOKEN, with self.deprecations.expect_deprecations_here():
project_id=self.TEST_TENANT_ID, cs = client.Client(token=self.TEST_TOKEN,
trust_id=self.TEST_TRUST_ID, project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL) trust_id=self.TEST_TRUST_ID,
auth_url=self.TEST_URL)
self.assertTrue(cs.auth_ref.trust_scoped) self.assertTrue(cs.auth_ref.trust_scoped)
self.assertEqual(cs.auth_ref.trust_id, self.TEST_TRUST_ID) self.assertEqual(cs.auth_ref.trust_id, self.TEST_TRUST_ID)
self.assertEqual(cs.auth_ref.trustee_user_id, self.TEST_USER) 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) self.stub_auth(json=self.TEST_RESPONSE_DICT)
cs = client.Client(token=self.TEST_TOKEN, with self.deprecations.expect_deprecations_here():
auth_url=self.TEST_URL) cs = client.Client(token=self.TEST_TOKEN,
auth_url=self.TEST_URL)
self.assertEqual(cs.auth_token, self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"]) self.TEST_RESPONSE_DICT["access"]["token"]["id"])
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog) 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, self.stub_url('GET', [fake_url], json=fake_resp,
base_url=self.TEST_ADMIN_IDENTITY_ENDPOINT) base_url=self.TEST_ADMIN_IDENTITY_ENDPOINT)
cl = client.Client(username='exampleuser', with self.deprecations.expect_deprecations_here():
password='password', cl = client.Client(username='exampleuser',
project_name='exampleproject', password='password',
auth_url=self.TEST_URL) project_name='exampleproject',
auth_url=self.TEST_URL)
self.assertEqual(cl.auth_token, self.TEST_TOKEN) self.assertEqual(cl.auth_token, self.TEST_TOKEN)

View File

@@ -78,9 +78,12 @@ class TestCase(UnauthenticatedTestCase):
def setUp(self): def setUp(self):
super(TestCase, self).setUp() super(TestCase, self).setUp()
self.client = client.Client(token=self.TEST_TOKEN,
auth_url=self.TEST_URL, # Creating a Client not using session is deprecated.
endpoint=self.TEST_URL) 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): def stub_auth(self, **kwargs):
self.stub_url('POST', ['tokens'], **kwargs) self.stub_url('POST', ['tokens'], **kwargs)

View File

@@ -14,6 +14,7 @@
# under the License. # under the License.
import logging import logging
import warnings
from keystoneclient.auth.identity import v2 as v2_auth from keystoneclient.auth.identity import v2 as v2_auth
from keystoneclient import exceptions 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 If debug is enabled, it may show passwords in plain text as a part of
its output. 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 The client can be created and used like a user or in a strictly
bootstrap mode. Normal operation expects a username, password, auth_url, bootstrap mode. Normal operation expects a username, password, auth_url,
@@ -130,6 +136,14 @@ class Client(httpclient.HTTPClient):
def __init__(self, **kwargs): def __init__(self, **kwargs):
"""Initialize a new client for the Keystone v2.0 API.""" """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) super(Client, self).__init__(**kwargs)
self.certificates = certificates.CertificatesManager(self._adapter) self.certificates = certificates.CertificatesManager(self._adapter)