Proper deprecation for Session.construct()
Session.construct() wasn't properly deprecated since the deprecation was only mentioned in the docstring. Proper deprecation requires use of warnings/debtcollector and documentation. bp deprecations Change-Id: Ieff238aff9d39cfbbb80381b2392c33d0359acb3
This commit is contained in:
@@ -57,7 +57,7 @@ def Client(version=None, unstable=False, session=None, **kwargs):
|
|||||||
cannot be found.
|
cannot be found.
|
||||||
"""
|
"""
|
||||||
if not session:
|
if not session:
|
||||||
session = client_session.Session.construct(kwargs)
|
session = client_session.Session._construct(kwargs)
|
||||||
|
|
||||||
d = discover.Discover(session=session, **kwargs)
|
d = discover.Discover(session=session, **kwargs)
|
||||||
return d.create_client(version=version, unstable=unstable)
|
return d.create_client(version=version, unstable=unstable)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ def version_match(required, candidate):
|
|||||||
def available_versions(url, session=None, **kwargs):
|
def available_versions(url, session=None, **kwargs):
|
||||||
"""Retrieve raw version data from a url."""
|
"""Retrieve raw version data from a url."""
|
||||||
if not session:
|
if not session:
|
||||||
session = client_session.Session.construct(kwargs)
|
session = client_session.Session._construct(kwargs)
|
||||||
|
|
||||||
return _discover.get_version_data(session, url)
|
return _discover.get_version_data(session, url)
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ 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:
|
||||||
session = client_session.Session.construct(kwargs)
|
session = client_session.Session._construct(kwargs)
|
||||||
kwargs['session'] = session
|
kwargs['session'] = session
|
||||||
|
|
||||||
url = None
|
url = None
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
|||||||
|
|
||||||
if not session:
|
if not session:
|
||||||
kwargs['session'] = _FakeRequestSession()
|
kwargs['session'] = _FakeRequestSession()
|
||||||
session = client_session.Session.construct(kwargs)
|
session = client_session.Session._construct(kwargs)
|
||||||
session.auth = self
|
session.auth = self
|
||||||
|
|
||||||
super(HTTPClient, self).__init__(session=session)
|
super(HTTPClient, self).__init__(session=session)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
import warnings
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
@@ -525,15 +526,27 @@ class Session(object):
|
|||||||
new request-style arguments.
|
new request-style arguments.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
*DEPRECATED*: This function is purely for bridging the gap between
|
|
||||||
older client arguments and the session arguments that they relate
|
*DEPRECATED as of 1.7.0*: This function is purely for bridging the
|
||||||
to. It is not intended to be used as a generic Session Factory.
|
gap between older client arguments and the session arguments that
|
||||||
|
they relate to. It is not intended to be used as a generic Session
|
||||||
|
Factory. This function may be removed in the 2.0.0 release.
|
||||||
|
|
||||||
This function purposefully modifies the input kwargs dictionary so that
|
This function purposefully modifies the input kwargs dictionary so that
|
||||||
the remaining kwargs dict can be reused and passed on to other
|
the remaining kwargs dict can be reused and passed on to other
|
||||||
functions without session arguments.
|
functions without session arguments.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
warnings.warn(
|
||||||
|
'Session.construct() is deprecated as of the 1.7.0 release in '
|
||||||
|
'favor of using session constructor and may be removed in the '
|
||||||
|
'2.0.0 release.', DeprecationWarning)
|
||||||
|
|
||||||
|
return cls._construct(kwargs)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _construct(cls, kwargs):
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
for attr in ('verify', 'cacert', 'cert', 'key', 'insecure',
|
for attr in ('verify', 'cacert', 'cert', 'key', 'insecure',
|
||||||
|
|||||||
@@ -337,7 +337,8 @@ class ConstructSessionFromArgsTests(utils.TestCase):
|
|||||||
|
|
||||||
def _s(self, k=None, **kwargs):
|
def _s(self, k=None, **kwargs):
|
||||||
k = k or kwargs
|
k = k or kwargs
|
||||||
return client_session.Session.construct(k)
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
return client_session.Session.construct(k)
|
||||||
|
|
||||||
def test_verify(self):
|
def test_verify(self):
|
||||||
self.assertFalse(self._s(insecure=True).verify)
|
self.assertFalse(self._s(insecure=True).verify)
|
||||||
|
|||||||
Reference in New Issue
Block a user