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:
@@ -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
|
||||
|
@@ -454,6 +454,7 @@ class GenericAuthPluginTests(utils.TestCase):
|
||||
for k, v in six.iteritems(self.auth.headers):
|
||||
self.assertRequestHeaderEqual(k, v)
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.assertIsNone(self.session.get_token())
|
||||
self.assertEqual(self.auth.headers,
|
||||
self.session.get_auth_headers())
|
||||
|
@@ -275,10 +275,12 @@ class V2IdentityPlugin(utils.TestCase):
|
||||
password=self.TEST_PASS)
|
||||
s = session.Session(auth=a)
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.assertEqual('token1', s.get_token())
|
||||
self.assertEqual({'X-Auth-Token': 'token1'}, s.get_auth_headers())
|
||||
|
||||
a.invalidate()
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.assertEqual('token2', s.get_token())
|
||||
self.assertEqual({'X-Auth-Token': 'token2'}, s.get_auth_headers())
|
||||
|
||||
@@ -289,6 +291,7 @@ class V2IdentityPlugin(utils.TestCase):
|
||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||
password=password)
|
||||
s = session.Session(auth=a)
|
||||
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())
|
||||
|
@@ -458,9 +458,11 @@ class V3IdentityPlugin(utils.TestCase):
|
||||
password=self.TEST_PASS)
|
||||
s = session.Session(auth=a)
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.assertEqual('token1', s.get_token())
|
||||
self.assertEqual({'X-Auth-Token': 'token1'}, s.get_auth_headers())
|
||||
a.invalidate()
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.assertEqual('token2', s.get_token())
|
||||
self.assertEqual({'X-Auth-Token': 'token2'}, s.get_auth_headers())
|
||||
|
||||
@@ -471,6 +473,7 @@ class V3IdentityPlugin(utils.TestCase):
|
||||
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
||||
password=password)
|
||||
s = session.Session(a)
|
||||
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)
|
||||
|
@@ -76,6 +76,7 @@ class V3FederatedPlugin(utils.TestCase):
|
||||
|
||||
def test_unscoped_behaviour(self):
|
||||
sess = session.Session(auth=self.get_plugin())
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.assertEqual(self.unscoped_token_id, sess.get_token())
|
||||
|
||||
self.assertTrue(self.unscoped_mock.called)
|
||||
@@ -84,6 +85,7 @@ 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)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.assertEqual(self.scoped_token_id, sess.get_token())
|
||||
|
||||
self.assertTrue(self.unscoped_mock.called)
|
||||
|
@@ -802,6 +802,7 @@ class AdapterTest(utils.TestCase):
|
||||
sess = client_session.Session()
|
||||
adpt = adapter.Adapter(sess, auth=auth)
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
self.assertEqual(self.TEST_TOKEN, adpt.get_token())
|
||||
self.assertTrue(auth.get_token_called)
|
||||
|
||||
|
@@ -248,6 +248,7 @@ class AuthenticateWithOAuthTests(TokenTests):
|
||||
access_key=access_key,
|
||||
access_secret=access_secret)
|
||||
s = session.Session(auth=a)
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
t = s.get_token()
|
||||
self.assertEqual(self.TEST_TOKEN, t)
|
||||
|
||||
|
Reference in New Issue
Block a user