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.
import logging
import warnings
from debtcollector import removals
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
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.
Clients will also be constructed with this session.
:type session: keystoneclient.session.Session
@@ -105,35 +112,38 @@ class Discover(_discover.Discover):
service. (optional)
:param string original_ip: The original IP of the requesting user which
will be sent to identity service in a
'Forwarded' header. (optional) DEPRECATED: use
the session object. This is ignored if a session
is provided.
'Forwarded' header. (optional) This is ignored
if a session is provided. Deprecated as of the
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
the identity service. default False (optional)
DEPRECATED: use the session object. This is ignored
if a session is provided.
This is ignored if a session is provided. Deprecated
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
contains the trusted authority X.509 certificates
needed to established SSL connection with the
identity service. (optional) DEPRECATED: use the
session object. This is ignored if a session is
provided.
identity service. (optional) This is ignored if a
session is provided. Deprecated as of the 1.7.0
release and may be removed in the 2.0.0 release.
:param string key: Path to the Privacy Enhanced Mail (PEM) file which
contains the unencrypted client private key needed to
established two-way SSL connection with the identity
service. (optional) DEPRECATED: use the session object.
This is ignored if a session is provided.
service. (optional) This is ignored if a session is
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
contains the corresponding X.509 client certificate
needed to established two-way SSL connection with the
identity service. (optional) DEPRECATED: use the
session object. This is ignored if a session is
provided.
identity service. (optional) This is ignored if a
session is provided. Deprecated as of the 1.7.0 release
and may be removed in the 2.0.0 release.
:param boolean insecure: Does not perform X.509 certificate validation when
establishing SSL connection with identity service.
default: False (optional) DEPRECATED: use the
session object. This is ignored if a session is
provided.
default: False (optional) This is ignored if a
session is provided. Deprecated as of the 1.7.0
release and may be removed in the 2.0.0 release.
:param bool authenticated: Should a token be used to perform the initial
discovery operations. default: None (attach a
token if an auth plugin is available).
@@ -143,6 +153,10 @@ class Discover(_discover.Discover):
@utils.positional(2)
def __init__(self, session=None, authenticated=None, **kwargs):
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)
kwargs['session'] = session

View File

@@ -484,6 +484,8 @@ class ClientDiscoveryTests(utils.TestCase):
text=V3_AUTH_RESPONSE,
headers={'X-Subject-Token': V3_TOKEN})
# Creating Discover not using session is deprecated.
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')
@@ -498,6 +500,8 @@ class ClientDiscoveryTests(utils.TestCase):
self.requests_mock.get(BASE_URL,
status_code=300,
text=V3_VERSION_ENTRY)
# 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():
@@ -515,6 +519,8 @@ class ClientDiscoveryTests(utils.TestCase):
versions.add_version(V4_VERSION)
self.requests_mock.get(BASE_URL, status_code=300, json=versions)
# Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
self.assertRaises(exceptions.DiscoveryFailure,
disc.create_client, version=4)
@@ -523,6 +529,8 @@ class ClientDiscoveryTests(utils.TestCase):
versions = fixture.DiscoveryList(v2=True, v3=False)
self.requests_mock.get(BASE_URL, status_code=300, json=versions)
# Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
self.assertRaises(exceptions.DiscoveryFailure,
disc.create_client, version=(3, 0))
@@ -558,6 +566,8 @@ class DiscoverQueryTests(utils.TestCase):
def test_available_keystone_data(self):
self.requests_mock.get(BASE_URL, status_code=300, text=V3_VERSION_LIST)
# Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
versions = disc.version_data()
@@ -589,6 +599,8 @@ class DiscoverQueryTests(utils.TestCase):
v1_url = "%sv1/" % BASE_URL
v2_url = "%sv2/" % 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()
@@ -620,6 +632,8 @@ class DiscoverQueryTests(utils.TestCase):
v1_url = "%sv1/" % BASE_URL
v2_url = "%sv2/" % 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()
@@ -666,6 +680,8 @@ class DiscoverQueryTests(utils.TestCase):
text = jsonutils.dumps({'versions': version_list})
self.requests_mock.get(BASE_URL, text=text)
# 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
@@ -688,6 +704,8 @@ class DiscoverQueryTests(utils.TestCase):
text = jsonutils.dumps({'versions': version_list})
self.requests_mock.get(BASE_URL, text=text)
# Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
versions = disc.version_data()
@@ -704,6 +722,8 @@ class DiscoverQueryTests(utils.TestCase):
version_list = fixture.DiscoveryList(BASE_URL, v2=False,
v3_status=status)
self.requests_mock.get(BASE_URL, json=version_list)
# Creating Discover not using session is deprecated.
with self.deprecations.expect_deprecations_here():
disc = discover.Discover(auth_url=BASE_URL)
versions = disc.version_data()
@@ -734,6 +754,8 @@ class DiscoverQueryTests(utils.TestCase):
text = jsonutils.dumps({'versions': version_list})
self.requests_mock.get(BASE_URL, text=text)
# 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