Merge "Fixed request logging"
This commit is contained in:
@@ -172,6 +172,7 @@ class SessionClient(adapter.LegacyJsonAdapter):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
apiver = kwargs.pop('api_version', None) or api_versions.APIVersion()
|
apiver = kwargs.pop('api_version', None) or api_versions.APIVersion()
|
||||||
|
self.http_log_debug = kwargs.pop('http_log_debug', False)
|
||||||
if not isinstance(apiver, api_versions.APIVersion):
|
if not isinstance(apiver, api_versions.APIVersion):
|
||||||
apiver = api_versions.APIVersion(str(apiver))
|
apiver = api_versions.APIVersion(str(apiver))
|
||||||
if apiver.ver_minor != 0:
|
if apiver.ver_minor != 0:
|
||||||
@@ -182,6 +183,8 @@ class SessionClient(adapter.LegacyJsonAdapter):
|
|||||||
|
|
||||||
def request(self, *args, **kwargs):
|
def request(self, *args, **kwargs):
|
||||||
kwargs.setdefault('authenticated', False)
|
kwargs.setdefault('authenticated', False)
|
||||||
|
if self.http_log_debug:
|
||||||
|
kwargs.setdefault('logger', self._logger)
|
||||||
|
|
||||||
# Note(tpatil): The standard call raises errors from
|
# Note(tpatil): The standard call raises errors from
|
||||||
# keystoneauth, here we need to raise the cinderclient errors.
|
# keystoneauth, here we need to raise the cinderclient errors.
|
||||||
@@ -718,6 +721,7 @@ def _construct_http_client(username=None, password=None, project_id=None,
|
|||||||
region_name=region_name,
|
region_name=region_name,
|
||||||
retries=retries,
|
retries=retries,
|
||||||
api_version=api_version,
|
api_version=api_version,
|
||||||
|
http_log_debug=http_log_debug,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
else:
|
else:
|
||||||
# FIXME(jamielennox): username and password are now optional. Need
|
# FIXME(jamielennox): username and password are now optional. Need
|
||||||
|
@@ -246,6 +246,28 @@ class ClientTest(utils.TestCase):
|
|||||||
# is not getting called.
|
# is not getting called.
|
||||||
self.assertFalse(mock_from_resp.called)
|
self.assertFalse(mock_from_resp.called)
|
||||||
|
|
||||||
|
@mock.patch('keystoneauth1.adapter.LegacyJsonAdapter.request',
|
||||||
|
return_value=(mock.Mock(), mock.Mock()))
|
||||||
|
@ddt.data(True, False, None)
|
||||||
|
def test_http_log_debug_request(self, http_log_debug, mock_request):
|
||||||
|
args_req = (mock.sentinel.url, mock.sentinel.OP)
|
||||||
|
kwargs_req = {'raise_exc': False}
|
||||||
|
kwargs_expect = {'authenticated': False}
|
||||||
|
kwargs_expect.update(kwargs_req)
|
||||||
|
|
||||||
|
kwargs = {'api_version': '3.0'}
|
||||||
|
if isinstance(http_log_debug, bool):
|
||||||
|
kwargs['http_log_debug'] = http_log_debug
|
||||||
|
if http_log_debug:
|
||||||
|
kwargs_expect['logger'] = mock.ANY
|
||||||
|
|
||||||
|
cs = cinderclient.client.SessionClient(self, **kwargs)
|
||||||
|
|
||||||
|
res = cs.request(*args_req, **kwargs_req)
|
||||||
|
|
||||||
|
mock_request.assert_called_once_with(*args_req, **kwargs_expect)
|
||||||
|
self.assertEqual(mock_request.return_value, res)
|
||||||
|
|
||||||
|
|
||||||
class ClientTestSensitiveInfo(utils.TestCase):
|
class ClientTestSensitiveInfo(utils.TestCase):
|
||||||
def test_req_does_not_log_sensitive_info(self):
|
def test_req_does_not_log_sensitive_info(self):
|
||||||
|
7
releasenotes/notes/http_log_debug-ff023f069afde3fe.yaml
Normal file
7
releasenotes/notes/http_log_debug-ff023f069afde3fe.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
`Bug #2035372
|
||||||
|
<https://bugs.launchpad.net/python-cinderclient/+bug/2035372>`_: Fixed
|
||||||
|
not honoring ``http_log_debug`` parameter in ``cinderclient.client.Client``
|
||||||
|
when also providing a session.
|
Reference in New Issue
Block a user