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,6 +36,8 @@ 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):
# Creating a Client not using session is deprecated.
with self.deprecations.expect_deprecations_here():
self.client = client.Client(token=self.TEST_TOKEN, self.client = client.Client(token=self.TEST_TOKEN,
auth_url='http://127.0.0.1:5000', auth_url='http://127.0.0.1:5000',
endpoint='http://127.0.0.1:5000') endpoint='http://127.0.0.1:5000')
@@ -83,9 +85,13 @@ class ManagerTest(utils.TestCase):
def setUp(self): def setUp(self):
super(ManagerTest, self).setUp() super(ManagerTest, self).setUp()
# Creating a Client not using session is deprecated.
with self.deprecations.expect_deprecations_here():
self.client = client.Client(token=self.TEST_TOKEN, self.client = client.Client(token=self.TEST_TOKEN,
auth_url='http://127.0.0.1:5000', auth_url='http://127.0.0.1:5000',
endpoint='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,6 +93,7 @@ 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():
with self.deprecations.expect_deprecations_here():
client.Client(username=self.TEST_USER, client.Client(username=self.TEST_USER,
password="bad_key", password="bad_key",
project_id=self.TEST_TENANT_ID, project_id=self.TEST_TENANT_ID,
@@ -108,6 +109,7 @@ 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)
with self.deprecations.expect_deprecations_here():
cs = client.Client(username=self.TEST_USER, cs = client.Client(username=self.TEST_USER,
password=self.TEST_TOKEN, password=self.TEST_TOKEN,
project_id=self.TEST_TENANT_ID, project_id=self.TEST_TENANT_ID,
@@ -123,6 +125,7 @@ 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)
with self.deprecations.expect_deprecations_here():
cs = client.Client(username=self.TEST_USER, cs = client.Client(username=self.TEST_USER,
password=self.TEST_TOKEN, password=self.TEST_TOKEN,
project_id=self.TEST_TENANT_ID, project_id=self.TEST_TENANT_ID,
@@ -140,6 +143,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.stub_auth(json=self.TEST_RESPONSE_DICT) self.stub_auth(json=self.TEST_RESPONSE_DICT)
with self.deprecations.expect_deprecations_here():
cs = client.Client(username=self.TEST_USER, cs = client.Client(username=self.TEST_USER,
password=self.TEST_TOKEN, password=self.TEST_TOKEN,
auth_url=self.TEST_URL) auth_url=self.TEST_URL)
@@ -157,6 +161,7 @@ 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)
with self.deprecations.expect_deprecations_here():
cl = client.Client(auth_url=self.TEST_URL, cl = client.Client(auth_url=self.TEST_URL,
token=fake_token) token=fake_token)
json_body = jsonutils.loads(self.requests_mock.last_request.body) json_body = jsonutils.loads(self.requests_mock.last_request.body)
@@ -174,6 +179,7 @@ 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)
with self.deprecations.expect_deprecations_here():
cs = client.Client(token=self.TEST_TOKEN, cs = client.Client(token=self.TEST_TOKEN,
project_id=self.TEST_TENANT_ID, project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL) auth_url=self.TEST_URL)
@@ -193,6 +199,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
"id": self.TEST_TRUST_ID} "id": self.TEST_TRUST_ID}
self.stub_auth(json=response) self.stub_auth(json=response)
with self.deprecations.expect_deprecations_here():
cs = client.Client(token=self.TEST_TOKEN, cs = client.Client(token=self.TEST_TOKEN,
project_id=self.TEST_TENANT_ID, project_id=self.TEST_TENANT_ID,
trust_id=self.TEST_TRUST_ID, trust_id=self.TEST_TRUST_ID,
@@ -210,6 +217,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.stub_auth(json=self.TEST_RESPONSE_DICT) self.stub_auth(json=self.TEST_RESPONSE_DICT)
with self.deprecations.expect_deprecations_here():
cs = client.Client(token=self.TEST_TOKEN, cs = client.Client(token=self.TEST_TOKEN,
auth_url=self.TEST_URL) auth_url=self.TEST_URL)
self.assertEqual(cs.auth_token, self.assertEqual(cs.auth_token,
@@ -226,6 +234,7 @@ 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)
with self.deprecations.expect_deprecations_here():
cl = client.Client(username='exampleuser', cl = client.Client(username='exampleuser',
password='password', password='password',
project_name='exampleproject', project_name='exampleproject',

View File

@@ -78,6 +78,9 @@ class TestCase(UnauthenticatedTestCase):
def setUp(self): def setUp(self):
super(TestCase, self).setUp() super(TestCase, self).setUp()
# Creating a Client not using session is deprecated.
with self.deprecations.expect_deprecations_here():
self.client = client.Client(token=self.TEST_TOKEN, self.client = client.Client(token=self.TEST_TOKEN,
auth_url=self.TEST_URL, auth_url=self.TEST_URL,
endpoint=self.TEST_URL) endpoint=self.TEST_URL)

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)