Proper deprecation for Session.get_token()

Session.get_token() wasn't properly deprecated since the deprecation
was only mentioned in the docstring. Proper deprecation requires use
of warnings/debtcollector and documentation.

Also, changed a test to use the non-deprecated function instead where
the test wasn't checking that the deprecated function worked.

bp deprecations

Change-Id: I3d421b35554d58476281e037f90ab9b48e82730a
This commit is contained in:
Brant Knudson
2015-07-26 08:19:11 -05:00
parent afcf4a163e
commit 962ab574fd
7 changed files with 32 additions and 15 deletions

View File

@@ -19,6 +19,7 @@ import socket
import time
import warnings
from debtcollector import removals
from oslo_config import cfg
from oslo_serialization import jsonutils
from oslo_utils import importutils
@@ -611,6 +612,8 @@ class Session(object):
auth = self._auth_required(auth, msg)
return auth.get_headers(self, **kwargs)
@removals.remove(message='Use get_auth_headers instead.', version='1.7.0',
removal_version='2.0.0')
def get_token(self, auth=None):
"""Return a token as provided by the auth plugin.
@@ -623,9 +626,12 @@ class Session(object):
:raises keystoneclient.exceptions.MissingAuthPlugin: if a plugin is not
available.
*DEPRECATED*: This assumes that the only header that is used to
authenticate a message is 'X-Auth-Token'. This may not be
correct. Use get_auth_headers instead.
.. warning::
This method is deprecated as of the 1.7.0 release in favor of
:meth:`get_auth_headers` and may be removed in the 2.0.0 release.
This method assumes that the only header that is used to
authenticate a message is 'X-Auth-Token' which may not be correct.
:returns: A valid token.
:rtype: string

View File

@@ -454,7 +454,8 @@ class GenericAuthPluginTests(utils.TestCase):
for k, v in six.iteritems(self.auth.headers):
self.assertRequestHeaderEqual(k, v)
self.assertIsNone(self.session.get_token())
with self.deprecations.expect_deprecations_here():
self.assertIsNone(self.session.get_token())
self.assertEqual(self.auth.headers,
self.session.get_auth_headers())
self.assertNotIn('X-Auth-Token',

View File

@@ -275,11 +275,13 @@ class V2IdentityPlugin(utils.TestCase):
password=self.TEST_PASS)
s = session.Session(auth=a)
self.assertEqual('token1', s.get_token())
with self.deprecations.expect_deprecations_here():
self.assertEqual('token1', s.get_token())
self.assertEqual({'X-Auth-Token': 'token1'}, s.get_auth_headers())
a.invalidate()
self.assertEqual('token2', s.get_token())
with self.deprecations.expect_deprecations_here():
self.assertEqual('token2', s.get_token())
self.assertEqual({'X-Auth-Token': 'token2'}, s.get_auth_headers())
def test_doesnt_log_password(self):
@@ -289,7 +291,8 @@ class V2IdentityPlugin(utils.TestCase):
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
password=password)
s = session.Session(auth=a)
self.assertEqual(self.TEST_TOKEN, s.get_token())
with self.deprecations.expect_deprecations_here():
self.assertEqual(self.TEST_TOKEN, s.get_token())
self.assertEqual({'X-Auth-Token': self.TEST_TOKEN},
s.get_auth_headers())
self.assertNotIn(password, self.logger.output)

View File

@@ -458,10 +458,12 @@ class V3IdentityPlugin(utils.TestCase):
password=self.TEST_PASS)
s = session.Session(auth=a)
self.assertEqual('token1', s.get_token())
with self.deprecations.expect_deprecations_here():
self.assertEqual('token1', s.get_token())
self.assertEqual({'X-Auth-Token': 'token1'}, s.get_auth_headers())
a.invalidate()
self.assertEqual('token2', s.get_token())
with self.deprecations.expect_deprecations_here():
self.assertEqual('token2', s.get_token())
self.assertEqual({'X-Auth-Token': 'token2'}, s.get_auth_headers())
def test_doesnt_log_password(self):
@@ -471,7 +473,8 @@ class V3IdentityPlugin(utils.TestCase):
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
password=password)
s = session.Session(a)
self.assertEqual(self.TEST_TOKEN, s.get_token())
with self.deprecations.expect_deprecations_here():
self.assertEqual(self.TEST_TOKEN, s.get_token())
self.assertEqual({'X-Auth-Token': self.TEST_TOKEN},
s.get_auth_headers())
@@ -487,7 +490,7 @@ class V3IdentityPlugin(utils.TestCase):
include_catalog=False)
s = session.Session(auth=a)
s.get_token()
s.get_auth_headers()
auth_url = self.TEST_URL + '/auth/tokens'
self.assertEqual(auth_url, a.token_url)

View File

@@ -76,7 +76,8 @@ class V3FederatedPlugin(utils.TestCase):
def test_unscoped_behaviour(self):
sess = session.Session(auth=self.get_plugin())
self.assertEqual(self.unscoped_token_id, sess.get_token())
with self.deprecations.expect_deprecations_here():
self.assertEqual(self.unscoped_token_id, sess.get_token())
self.assertTrue(self.unscoped_mock.called)
self.assertFalse(self.scoped_mock.called)
@@ -84,7 +85,8 @@ class V3FederatedPlugin(utils.TestCase):
def test_scoped_behaviour(self):
auth = self.get_plugin(project_id=self.scoped_token.project_id)
sess = session.Session(auth=auth)
self.assertEqual(self.scoped_token_id, sess.get_token())
with self.deprecations.expect_deprecations_here():
self.assertEqual(self.scoped_token_id, sess.get_token())
self.assertTrue(self.unscoped_mock.called)
self.assertTrue(self.scoped_mock.called)

View File

@@ -802,7 +802,8 @@ class AdapterTest(utils.TestCase):
sess = client_session.Session()
adpt = adapter.Adapter(sess, auth=auth)
self.assertEqual(self.TEST_TOKEN, adpt.get_token())
with self.deprecations.expect_deprecations_here():
self.assertEqual(self.TEST_TOKEN, adpt.get_token())
self.assertTrue(auth.get_token_called)
def test_adapter_connect_retries(self):

View File

@@ -248,7 +248,8 @@ class AuthenticateWithOAuthTests(TokenTests):
access_key=access_key,
access_secret=access_secret)
s = session.Session(auth=a)
t = s.get_token()
with self.deprecations.expect_deprecations_here():
t = s.get_token()
self.assertEqual(self.TEST_TOKEN, t)
OAUTH_REQUEST_BODY = {