Proper deprecation for HTTPClient.request methods
HTTPClient.request and related methods weren't properly deprecated since they were only mentioned in the docstrings. Proper deprecation requires use of warnings/debtcollector and documentation. Also, fixed places where the deprecated request method was called. bp deprecations Change-Id: I0a16933252937ca046793bb6eb2e5cc5da03c9ae
This commit is contained in:
@@ -84,7 +84,7 @@ class Client(httpclient.HTTPClient):
|
||||
def _check_keystone_versions(self, url):
|
||||
"""Calls Keystone URL and detects the available API versions."""
|
||||
try:
|
||||
resp, body = self.request(url, "GET",
|
||||
resp, body = self._request(url, "GET",
|
||||
headers={'Accept':
|
||||
'application/json'})
|
||||
# Multiple Choices status code is returned by the root
|
||||
@@ -148,7 +148,7 @@ class Client(httpclient.HTTPClient):
|
||||
try:
|
||||
if not url.endswith("/"):
|
||||
url += '/'
|
||||
resp, body = self.request("%sextensions" % url, "GET",
|
||||
resp, body = self._request("%sextensions" % url, "GET",
|
||||
headers={'Accept':
|
||||
'application/json'})
|
||||
if resp.status_code in (200, 204): # some cases we get No Content
|
||||
|
@@ -696,6 +696,7 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||
def serialize(self, entity):
|
||||
return jsonutils.dumps(entity)
|
||||
|
||||
@removals.remove(version='1.7.0', removal_version='2.0.0')
|
||||
def request(self, *args, **kwargs):
|
||||
"""Send an http request with the specified characteristics.
|
||||
|
||||
@@ -703,10 +704,15 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||
setting headers, JSON encoding/decoding, and error handling.
|
||||
|
||||
.. warning::
|
||||
|
||||
*DEPRECATED*: This function is no longer used. It was designed to
|
||||
be used only by the managers and the managers now receive an
|
||||
adapter so this function is no longer on the standard request path.
|
||||
This may be removed in the 2.0.0 release.
|
||||
"""
|
||||
return self._request(*args, **kwargs)
|
||||
|
||||
def _request(self, *args, **kwargs):
|
||||
kwargs.setdefault('authenticated', False)
|
||||
return self._adapter.request(*args, **kwargs)
|
||||
|
||||
@@ -715,15 +721,14 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||
concatenating self.management_url and url and passing in method and
|
||||
any associated kwargs.
|
||||
"""
|
||||
# NOTE(jamielennox): This is deprecated and is no longer a part of the
|
||||
# standard client request path. It now goes via the adapter instead.
|
||||
if not management:
|
||||
endpoint_filter = kwargs.setdefault('endpoint_filter', {})
|
||||
endpoint_filter.setdefault('interface', 'public')
|
||||
|
||||
kwargs.setdefault('authenticated', None)
|
||||
return self.request(url, method, **kwargs)
|
||||
return self._request(url, method, **kwargs)
|
||||
|
||||
@removals.remove(version='1.7.0', removal_version='2.0.0')
|
||||
def get(self, url, **kwargs):
|
||||
"""Perform an authenticated GET request.
|
||||
|
||||
@@ -731,12 +736,16 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||
authentication token if one is available.
|
||||
|
||||
.. warning::
|
||||
*DEPRECATED*: This function is no longer used. It was designed to
|
||||
be used by the managers and the managers now receive an adapter so
|
||||
this function is no longer on the standard request path.
|
||||
|
||||
*DEPRECATED*: This function is no longer used and is deprecated as
|
||||
of the 1.7.0 release and may be removed in the 2.0.0 release. It
|
||||
was designed to be used by the managers and the managers now
|
||||
receive an adapter so this function is no longer on the standard
|
||||
request path.
|
||||
"""
|
||||
return self._cs_request(url, 'GET', **kwargs)
|
||||
|
||||
@removals.remove(version='1.7.0', removal_version='2.0.0')
|
||||
def head(self, url, **kwargs):
|
||||
"""Perform an authenticated HEAD request.
|
||||
|
||||
@@ -744,12 +753,16 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||
authentication token if one is available.
|
||||
|
||||
.. warning::
|
||||
*DEPRECATED*: This function is no longer used. It was designed to
|
||||
be used by the managers and the managers now receive an adapter so
|
||||
this function is no longer on the standard request path.
|
||||
|
||||
*DEPRECATED*: This function is no longer used and is deprecated as
|
||||
of the 1.7.0 release and may be removed in the 2.0.0 release. It
|
||||
was designed to be used by the managers and the managers now
|
||||
receive an adapter so this function is no longer on the standard
|
||||
request path.
|
||||
"""
|
||||
return self._cs_request(url, 'HEAD', **kwargs)
|
||||
|
||||
@removals.remove(version='1.7.0', removal_version='2.0.0')
|
||||
def post(self, url, **kwargs):
|
||||
"""Perform an authenticate POST request.
|
||||
|
||||
@@ -757,12 +770,16 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||
authentication token if one is available.
|
||||
|
||||
.. warning::
|
||||
*DEPRECATED*: This function is no longer used. It was designed to
|
||||
be used by the managers and the managers now receive an adapter so
|
||||
this function is no longer on the standard request path.
|
||||
|
||||
*DEPRECATED*: This function is no longer used and is deprecated as
|
||||
of the 1.7.0 release and may be removed in the 2.0.0 release. It
|
||||
was designed to be used by the managers and the managers now
|
||||
receive an adapter so this function is no longer on the standard
|
||||
request path.
|
||||
"""
|
||||
return self._cs_request(url, 'POST', **kwargs)
|
||||
|
||||
@removals.remove(version='1.7.0', removal_version='2.0.0')
|
||||
def put(self, url, **kwargs):
|
||||
"""Perform an authenticate PUT request.
|
||||
|
||||
@@ -770,12 +787,16 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||
authentication token if one is available.
|
||||
|
||||
.. warning::
|
||||
*DEPRECATED*: This function is no longer used. It was designed to
|
||||
be used by the managers and the managers now receive an adapter so
|
||||
this function is no longer on the standard request path.
|
||||
|
||||
*DEPRECATED*: This function is no longer used and is deprecated as
|
||||
of the 1.7.0 release and may be removed in the 2.0.0 release. It
|
||||
was designed to be used by the managers and the managers now
|
||||
receive an adapter so this function is no longer on the standard
|
||||
request path.
|
||||
"""
|
||||
return self._cs_request(url, 'PUT', **kwargs)
|
||||
|
||||
@removals.remove(version='1.7.0', removal_version='2.0.0')
|
||||
def patch(self, url, **kwargs):
|
||||
"""Perform an authenticate PATCH request.
|
||||
|
||||
@@ -783,12 +804,16 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||
an authentication token if one is available.
|
||||
|
||||
.. warning::
|
||||
*DEPRECATED*: This function is no longer used. It was designed to
|
||||
be used by the managers and the managers now receive an adapter so
|
||||
this function is no longer on the standard request path.
|
||||
|
||||
*DEPRECATED*: This function is no longer used and is deprecated as
|
||||
of the 1.7.0 release and may be removed in the 2.0.0 release. It
|
||||
was designed to be used by the managers and the managers now
|
||||
receive an adapter so this function is no longer on the standard
|
||||
request path.
|
||||
"""
|
||||
return self._cs_request(url, 'PATCH', **kwargs)
|
||||
|
||||
@removals.remove(version='1.7.0', removal_version='2.0.0')
|
||||
def delete(self, url, **kwargs):
|
||||
"""Perform an authenticate DELETE request.
|
||||
|
||||
@@ -796,9 +821,12 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||
an authentication token if one is available.
|
||||
|
||||
.. warning::
|
||||
*DEPRECATED*: This function is no longer used. It was designed to
|
||||
be used by the managers and the managers now receive an adapter so
|
||||
this function is no longer on the standard request path.
|
||||
|
||||
*DEPRECATED*: This function is no longer used and is deprecated as
|
||||
of the 1.7.0 release and may be removed in the 2.0.0 release. It
|
||||
was designed to be used by the managers and the managers now
|
||||
receive an adapter so this function is no longer on the standard
|
||||
request path.
|
||||
"""
|
||||
return self._cs_request(url, 'DELETE', **kwargs)
|
||||
|
||||
|
@@ -67,6 +67,7 @@ class ClientTest(utils.TestCase):
|
||||
|
||||
self.stub_url('GET', text=RESPONSE_BODY)
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get("/hi")
|
||||
self.assertEqual(self.requests_mock.last_request.method, 'GET')
|
||||
self.assertEqual(self.requests_mock.last_request.url, self.TEST_URL)
|
||||
@@ -96,6 +97,7 @@ class ClientTest(utils.TestCase):
|
||||
self.stub_url('GET', status_code=400, json=err_response)
|
||||
exc_raised = False
|
||||
try:
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cl.get('/hi')
|
||||
except exceptions.BadRequest as exc:
|
||||
exc_raised = True
|
||||
@@ -106,6 +108,7 @@ class ClientTest(utils.TestCase):
|
||||
cl = get_authed_client()
|
||||
|
||||
self.stub_url('POST')
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cl.post("/hi", body=[1, 2, 3])
|
||||
|
||||
self.assertEqual(self.requests_mock.last_request.method, 'POST')
|
||||
@@ -123,6 +126,7 @@ class ClientTest(utils.TestCase):
|
||||
|
||||
self.stub_url('GET')
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cl.request(self.TEST_URL, 'GET')
|
||||
forwarded = "for=%s;by=%s" % (ORIGINAL_IP, httpclient.USER_AGENT)
|
||||
self.assertRequestHeaderEqual('Forwarded', forwarded)
|
||||
|
@@ -47,6 +47,7 @@ class ClientTest(utils.TestCase):
|
||||
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
||||
cl = get_authed_client()
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get("/hi")
|
||||
|
||||
# this may become too tightly couple later
|
||||
@@ -66,6 +67,7 @@ class ClientTest(utils.TestCase):
|
||||
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
||||
cl = get_authed_client()
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cl.post("/hi", body=[1, 2, 3])
|
||||
|
||||
# this may become too tightly couple later
|
||||
@@ -87,6 +89,7 @@ class ClientTest(utils.TestCase):
|
||||
cert="cert.pem")
|
||||
cl.management_url = "https://127.0.0.1:5000"
|
||||
cl.auth_token = "token"
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
cl.post("/hi", body=[1, 2, 3])
|
||||
|
||||
# this may become too tightly couple later
|
||||
|
@@ -162,6 +162,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
json_body = jsonutils.loads(self.requests_mock.last_request.body)
|
||||
self.assertEqual(json_body['auth']['token']['id'], fake_token)
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get(fake_url)
|
||||
self.assertEqual(fake_resp, body)
|
||||
|
||||
@@ -233,6 +234,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
self.assertEqual(cl.auth_token, self.TEST_TOKEN)
|
||||
|
||||
# the token returned from the authentication will be used
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get(fake_url)
|
||||
self.assertEqual(fake_resp, body)
|
||||
|
||||
@@ -242,6 +244,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
# then override that token and the new token shall be used
|
||||
cl.auth_token = fake_token
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get(fake_url)
|
||||
self.assertEqual(fake_resp, body)
|
||||
|
||||
@@ -251,6 +254,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
# if we clear that overridden token then we fall back to the original
|
||||
del cl.auth_token
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get(fake_url)
|
||||
self.assertEqual(fake_resp, body)
|
||||
|
||||
|
@@ -229,6 +229,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
body = jsonutils.loads(self.requests_mock.last_request.body)
|
||||
self.assertEqual(body['auth']['identity']['token']['id'], fake_token)
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get(fake_url)
|
||||
self.assertEqual(fake_resp, body)
|
||||
|
||||
@@ -327,6 +328,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
self.assertEqual(cl.auth_token, self.TEST_TOKEN)
|
||||
|
||||
# the token returned from the authentication will be used
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get(fake_url)
|
||||
self.assertEqual(fake_resp, body)
|
||||
|
||||
@@ -336,6 +338,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
# then override that token and the new token shall be used
|
||||
cl.auth_token = fake_token
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get(fake_url)
|
||||
self.assertEqual(fake_resp, body)
|
||||
|
||||
@@ -345,6 +348,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
||||
# if we clear that overridden token then we fall back to the original
|
||||
del cl.auth_token
|
||||
|
||||
with self.deprecations.expect_deprecations_here():
|
||||
resp, body = cl.get(fake_url)
|
||||
self.assertEqual(fake_resp, body)
|
||||
|
||||
|
Reference in New Issue
Block a user