Skip to content

Commit 63e3fa7

Browse files
Zuulopenstack-gerrit
Zuul
authored andcommitted
Merge "Fixed request logging"
2 parents eb53ae8 + ccbb9ea commit 63e3fa7

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

cinderclient/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class SessionClient(adapter.LegacyJsonAdapter):
172172

173173
def __init__(self, *args, **kwargs):
174174
apiver = kwargs.pop('api_version', None) or api_versions.APIVersion()
175+
self.http_log_debug = kwargs.pop('http_log_debug', False)
175176
if not isinstance(apiver, api_versions.APIVersion):
176177
apiver = api_versions.APIVersion(str(apiver))
177178
if apiver.ver_minor != 0:
@@ -182,6 +183,8 @@ def __init__(self, *args, **kwargs):
182183

183184
def request(self, *args, **kwargs):
184185
kwargs.setdefault('authenticated', False)
186+
if self.http_log_debug:
187+
kwargs.setdefault('logger', self._logger)
185188

186189
# Note(tpatil): The standard call raises errors from
187190
# keystoneauth, here we need to raise the cinderclient errors.
@@ -718,6 +721,7 @@ def _construct_http_client(username=None, password=None, project_id=None,
718721
region_name=region_name,
719722
retries=retries,
720723
api_version=api_version,
724+
http_log_debug=http_log_debug,
721725
**kwargs)
722726
else:
723727
# FIXME(jamielennox): username and password are now optional. Need

cinderclient/tests/unit/test_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,28 @@ def test_keystone_request_raises_auth_failure_exception(
246246
# is not getting called.
247247
self.assertFalse(mock_from_resp.called)
248248

249+
@mock.patch('keystoneauth1.adapter.LegacyJsonAdapter.request',
250+
return_value=(mock.Mock(), mock.Mock()))
251+
@ddt.data(True, False, None)
252+
def test_http_log_debug_request(self, http_log_debug, mock_request):
253+
args_req = (mock.sentinel.url, mock.sentinel.OP)
254+
kwargs_req = {'raise_exc': False}
255+
kwargs_expect = {'authenticated': False}
256+
kwargs_expect.update(kwargs_req)
257+
258+
kwargs = {'api_version': '3.0'}
259+
if isinstance(http_log_debug, bool):
260+
kwargs['http_log_debug'] = http_log_debug
261+
if http_log_debug:
262+
kwargs_expect['logger'] = mock.ANY
263+
264+
cs = cinderclient.client.SessionClient(self, **kwargs)
265+
266+
res = cs.request(*args_req, **kwargs_req)
267+
268+
mock_request.assert_called_once_with(*args_req, **kwargs_expect)
269+
self.assertEqual(mock_request.return_value, res)
270+
249271

250272
class ClientTestSensitiveInfo(utils.TestCase):
251273
def test_req_does_not_log_sensitive_info(self):
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
`Bug #2035372
5+
<https://bugs.launchpad.net/python-cinderclient/+bug/2035372>`_: Fixed
6+
not honoring ``http_log_debug`` parameter in ``cinderclient.client.Client``
7+
when also providing a session.

0 commit comments

Comments
 (0)