Remove support for passing auth_token to ClientV1

This was long deprecated, users should create a Session instead.

Depends-On: I3ce2916872b6ba4c36d4d6f294456454eee78314
Change-Id: I9df8296ddc1b41cde22ff8b0f26d73c4408741ce
This commit is contained in:
Dmitry Tantsur 2017-11-17 12:23:41 +01:00
parent c584552304
commit 98ee6670f1
5 changed files with 15 additions and 40 deletions

View File

@ -18,7 +18,6 @@ import logging
from keystoneauth1 import exceptions as ks_exc
from keystoneauth1 import session as ks_session
from keystoneauth1 import token_endpoint
from oslo_utils import netutils
import requests
import six
@ -89,7 +88,7 @@ class VersionNotSupported(Exception):
class BaseClient(object):
"""Base class for clients, provides common HTTP code."""
def __init__(self, api_version, inspector_url=None, auth_token=None,
def __init__(self, api_version, inspector_url=None,
session=None, service_type='baremetal-introspection',
interface=None, region_name=None):
"""Create a client.
@ -100,26 +99,17 @@ class BaseClient(object):
http://host:port[/ver]. When session is provided, defaults to
service URL from the catalog. As a last resort
defaults to ``http://<current host>:5050/v<MAJOR>``.
:param auth_token: authentication token (deprecated, use session)
:param session: existing keystone session
:param session: existing keystone session. A session without
authentication is created if this is set to None.
:param service_type: service type to use when looking up the URL
:param interface: interface type (public, internal, etc) to use when
looking up the URL
:param region_name: region name to use when looking up the URL
"""
self._base_url = inspector_url or _DEFAULT_URL
self._auth_token = auth_token
if session is None:
if auth_token:
LOG.warning('Passing auth_token to client objects '
'is deprecated, please pass session instead')
auth = token_endpoint.Token(endpoint=self._base_url,
token=auth_token)
else:
auth = None
self._session = ks_session.Session(auth)
self._session = ks_session.Session(None)
else:
self._session = session
if not inspector_url:

View File

@ -209,9 +209,6 @@ class TestV1PythonAPI(functional.Base):
client.ClientV1(inspector_url='http://127.0.0.1:5050/v1')
.server_api_versions())
self.assertTrue(client.ClientV1(auth_token='some token')
.server_api_versions())
def test_rules_api(self):
res = self.client.rules.get_all()
self.assertEqual([], res)

View File

@ -114,14 +114,10 @@ class TestRequest(unittest.TestCase):
@mock.patch.object(http.BaseClient, 'server_api_versions',
lambda self: ((1, 0), (1, 42)))
def get_client(self, version=1, inspector_url=None, use_session=True,
use_token=True):
def get_client(self, version=1, inspector_url=None, use_session=True):
if use_session:
return http.BaseClient(version, session=self.session,
inspector_url=inspector_url)
elif use_token:
return http.BaseClient(version, auth_token='token',
inspector_url=inspector_url)
else:
return http.BaseClient(version, inspector_url=inspector_url)
@ -157,21 +153,10 @@ class TestRequest(unittest.TestCase):
service_type='baremetal-introspection',
interface=None, region_name=None)
@mock.patch.object(session.Session, 'request', autospec=True,
**{'return_value.status_code': 200})
def test_ok_with_auth_token(self, mock_req):
res = self.get_client(use_session=False).request('get', '/foo/bar')
self.assertIs(mock_req.return_value, res)
mock_req.assert_called_once_with(mock.ANY,
self.base_url + '/foo/bar', 'get',
raise_exc=False, headers=self.headers)
@mock.patch.object(session.Session, 'request', autospec=True,
**{'return_value.status_code': 200})
def test_ok_no_auth(self, mock_req):
res = self.get_client(use_session=False,
use_token=False).request('get', '/foo/bar')
res = self.get_client(use_session=False).request('get', '/foo/bar')
self.assertIs(mock_req.return_value, res)
mock_req.assert_called_once_with(mock.ANY,

View File

@ -36,11 +36,9 @@ FAKE_HEADERS = {
status_code=200))
class TestInit(unittest.TestCase):
my_ip = 'http://' + netutils.get_my_ipv4() + ':5050'
token = "token"
def get_client(self, **kwargs):
return ironic_inspector_client.ClientV1(auth_token=self.token,
**kwargs)
return ironic_inspector_client.ClientV1(**kwargs)
def test_ok(self, mock_get):
self.get_client()
@ -72,13 +70,11 @@ class BaseTest(unittest.TestCase):
super(BaseTest, self).setUp()
self.uuid = uuidutils.generate_uuid()
self.my_ip = 'http://' + netutils.get_my_ipv4() + ':5050'
self.token = "token"
@mock.patch.object(http.BaseClient, 'server_api_versions',
lambda self: ((1, 0), (1, 99)))
def get_client(self, **kwargs):
return ironic_inspector_client.ClientV1(auth_token=self.token,
**kwargs)
return ironic_inspector_client.ClientV1(**kwargs)
@mock.patch.object(http.BaseClient, 'request')

View File

@ -0,0 +1,7 @@
---
upgrade:
- |
Support for passing ``auth_token`` to ``ClientV1`` was removed. Please
create a **keystoneauth** session and pass it via the ``session`` argument
instead. If no ``session`` is passed, a new session without authentication
is created.