Deprecate create Discover without session

The comments indicated that creating a Discover without a
session is deprecated, but there was no warning generated.

Also, updated the Discover() parameter docstrings with the
standard deprecation info (e.g., in what release it's
deprecated and when we might remove it).

bp deprecations

Change-Id: I1d42b74aa72c15b95ac3c365b40d8c622869ed7e
This commit is contained in:
Brant Knudson
2015-07-26 09:25:33 -05:00
parent c2b4372446
commit 1697fd7198
2 changed files with 64 additions and 28 deletions

View File

@@ -11,6 +11,7 @@
# under the License. # under the License.
import logging import logging
import warnings
from debtcollector import removals from debtcollector import removals
import six import six
@@ -96,6 +97,12 @@ class Discover(_discover.Discover):
In the event that auth_url and endpoint is provided then auth_url will be In the event that auth_url and endpoint is provided then auth_url will be
used in accordance with how the client operates. used in accordance with how the client operates.
.. warning::
Creating an instance of this class without using the session argument
is deprecated as of the 1.7.0 release and may be removed in the 2.0.0
release.
:param session: A session object that will be used for communication. :param session: A session object that will be used for communication.
Clients will also be constructed with this session. Clients will also be constructed with this session.
:type session: keystoneclient.session.Session :type session: keystoneclient.session.Session
@@ -105,35 +112,38 @@ class Discover(_discover.Discover):
service. (optional) service. (optional)
:param string original_ip: The original IP of the requesting user which :param string original_ip: The original IP of the requesting user which
will be sent to identity service in a will be sent to identity service in a
'Forwarded' header. (optional) DEPRECATED: use 'Forwarded' header. (optional) This is ignored
the session object. This is ignored if a session if a session is provided. Deprecated as of the
is provided. 1.7.0 release and may be removed in the 2.0.0
release.
:param boolean debug: Enables debug logging of all request and responses to :param boolean debug: Enables debug logging of all request and responses to
the identity service. default False (optional) the identity service. default False (optional)
DEPRECATED: use the session object. This is ignored This is ignored if a session is provided. Deprecated
if a session is provided. as of the 1.7.0 release and may be removed in the
2.0.0 release.
:param string cacert: Path to the Privacy Enhanced Mail (PEM) file which :param string cacert: Path to the Privacy Enhanced Mail (PEM) file which
contains the trusted authority X.509 certificates contains the trusted authority X.509 certificates
needed to established SSL connection with the needed to established SSL connection with the
identity service. (optional) DEPRECATED: use the identity service. (optional) This is ignored if a
session object. This is ignored if a session is session is provided. Deprecated as of the 1.7.0
provided. release and may be removed in the 2.0.0 release.
:param string key: Path to the Privacy Enhanced Mail (PEM) file which :param string key: Path to the Privacy Enhanced Mail (PEM) file which
contains the unencrypted client private key needed to contains the unencrypted client private key needed to
established two-way SSL connection with the identity established two-way SSL connection with the identity
service. (optional) DEPRECATED: use the session object. service. (optional) This is ignored if a session is
This is ignored if a session is provided. provided. Deprecated as of the 1.7.0 release and may be
removed in the 2.0.0 release.
:param string cert: Path to the Privacy Enhanced Mail (PEM) file which :param string cert: Path to the Privacy Enhanced Mail (PEM) file which
contains the corresponding X.509 client certificate contains the corresponding X.509 client certificate
needed to established two-way SSL connection with the needed to established two-way SSL connection with the
identity service. (optional) DEPRECATED: use the identity service. (optional) This is ignored if a
session object. This is ignored if a session is session is provided. Deprecated as of the 1.7.0 release
provided. and may be removed in the 2.0.0 release.
:param boolean insecure: Does not perform X.509 certificate validation when :param boolean insecure: Does not perform X.509 certificate validation when
establishing SSL connection with identity service. establishing SSL connection with identity service.
default: False (optional) DEPRECATED: use the default: False (optional) This is ignored if a
session object. This is ignored if a session is session is provided. Deprecated as of the 1.7.0
provided. release and may be removed in the 2.0.0 release.
:param bool authenticated: Should a token be used to perform the initial :param bool authenticated: Should a token be used to perform the initial
discovery operations. default: None (attach a discovery operations. default: None (attach a
token if an auth plugin is available). token if an auth plugin is available).
@@ -143,6 +153,10 @@ class Discover(_discover.Discover):
@utils.positional(2) @utils.positional(2)
def __init__(self, session=None, authenticated=None, **kwargs): def __init__(self, session=None, authenticated=None, **kwargs):
if not session: if not session:
warnings.warn(
'Constructing a Discover instance without using a session is '
'deprecated as of the 1.7.0 release and may be removed in the '
'2.0.0 release.', DeprecationWarning)
session = client_session.Session._construct(kwargs) session = client_session.Session._construct(kwargs)
kwargs['session'] = session kwargs['session'] = session

View File

@@ -484,8 +484,10 @@ class ClientDiscoveryTests(utils.TestCase):
text=V3_AUTH_RESPONSE, text=V3_AUTH_RESPONSE,
headers={'X-Subject-Token': V3_TOKEN}) headers={'X-Subject-Token': V3_TOKEN})
disc = discover.Discover(auth_url=BASE_URL, debug=False, # Creating Discover not using session is deprecated.
username='foo') with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL, debug=False,
username='foo')
client = disc.create_client(debug=True, password='bar') client = disc.create_client(debug=True, password='bar')
self.assertIsInstance(client, v3_client.Client) self.assertIsInstance(client, v3_client.Client)
@@ -498,7 +500,9 @@ class ClientDiscoveryTests(utils.TestCase):
self.requests_mock.get(BASE_URL, self.requests_mock.get(BASE_URL,
status_code=300, status_code=300,
text=V3_VERSION_ENTRY) text=V3_VERSION_ENTRY)
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
with self.deprecations.expect_deprecations_here(): with self.deprecations.expect_deprecations_here():
versions = disc.available_versions() versions = disc.available_versions()
@@ -515,7 +519,9 @@ class ClientDiscoveryTests(utils.TestCase):
versions.add_version(V4_VERSION) versions.add_version(V4_VERSION)
self.requests_mock.get(BASE_URL, status_code=300, json=versions) self.requests_mock.get(BASE_URL, status_code=300, json=versions)
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
self.assertRaises(exceptions.DiscoveryFailure, self.assertRaises(exceptions.DiscoveryFailure,
disc.create_client, version=4) disc.create_client, version=4)
@@ -523,7 +529,9 @@ class ClientDiscoveryTests(utils.TestCase):
versions = fixture.DiscoveryList(v2=True, v3=False) versions = fixture.DiscoveryList(v2=True, v3=False)
self.requests_mock.get(BASE_URL, status_code=300, json=versions) self.requests_mock.get(BASE_URL, status_code=300, json=versions)
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
self.assertRaises(exceptions.DiscoveryFailure, self.assertRaises(exceptions.DiscoveryFailure,
disc.create_client, version=(3, 0)) disc.create_client, version=(3, 0))
@@ -558,7 +566,9 @@ class DiscoverQueryTests(utils.TestCase):
def test_available_keystone_data(self): def test_available_keystone_data(self):
self.requests_mock.get(BASE_URL, status_code=300, text=V3_VERSION_LIST) self.requests_mock.get(BASE_URL, status_code=300, text=V3_VERSION_LIST)
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
versions = disc.version_data() versions = disc.version_data()
self.assertEqual((2, 0), versions[0]['version']) self.assertEqual((2, 0), versions[0]['version'])
@@ -589,7 +599,9 @@ class DiscoverQueryTests(utils.TestCase):
v1_url = "%sv1/" % BASE_URL v1_url = "%sv1/" % BASE_URL
v2_url = "%sv2/" % BASE_URL v2_url = "%sv2/" % BASE_URL
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
versions = disc.version_data() versions = disc.version_data()
self.assertEqual((1, 0), versions[0]['version']) self.assertEqual((1, 0), versions[0]['version'])
@@ -620,7 +632,9 @@ class DiscoverQueryTests(utils.TestCase):
v1_url = "%sv1/" % BASE_URL v1_url = "%sv1/" % BASE_URL
v2_url = "%sv2/" % BASE_URL v2_url = "%sv2/" % BASE_URL
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
versions = disc.version_data() versions = disc.version_data()
self.assertEqual((1, 0), versions[0]['version']) self.assertEqual((1, 0), versions[0]['version'])
@@ -666,7 +680,9 @@ class DiscoverQueryTests(utils.TestCase):
text = jsonutils.dumps({'versions': version_list}) text = jsonutils.dumps({'versions': version_list})
self.requests_mock.get(BASE_URL, text=text) self.requests_mock.get(BASE_URL, text=text)
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
# deprecated is allowed by default # deprecated is allowed by default
versions = disc.version_data(allow_deprecated=False) versions = disc.version_data(allow_deprecated=False)
@@ -688,7 +704,9 @@ class DiscoverQueryTests(utils.TestCase):
text = jsonutils.dumps({'versions': version_list}) text = jsonutils.dumps({'versions': version_list})
self.requests_mock.get(BASE_URL, text=text) self.requests_mock.get(BASE_URL, text=text)
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
versions = disc.version_data() versions = disc.version_data()
self.assertEqual(0, len(versions)) self.assertEqual(0, len(versions))
@@ -704,7 +722,9 @@ class DiscoverQueryTests(utils.TestCase):
version_list = fixture.DiscoveryList(BASE_URL, v2=False, version_list = fixture.DiscoveryList(BASE_URL, v2=False,
v3_status=status) v3_status=status)
self.requests_mock.get(BASE_URL, json=version_list) self.requests_mock.get(BASE_URL, json=version_list)
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
versions = disc.version_data() versions = disc.version_data()
self.assertEqual(0, len(versions)) self.assertEqual(0, len(versions))
@@ -734,7 +754,9 @@ class DiscoverQueryTests(utils.TestCase):
text = jsonutils.dumps({'versions': version_list}) text = jsonutils.dumps({'versions': version_list})
self.requests_mock.get(BASE_URL, text=text) self.requests_mock.get(BASE_URL, text=text)
disc = discover.Discover(auth_url=BASE_URL) # Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
# raw_version_data will return all choices, even invalid ones # raw_version_data will return all choices, even invalid ones
versions = disc.raw_version_data() versions = disc.raw_version_data()