From ccbb9ea5e5014898925be1f6a8ab4232bdeba6f9 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Wed, 13 Sep 2023 14:23:19 +0200 Subject: [PATCH] Fixed request logging When passing http_log_debug to cinderclient.client.Client we didn't honor it and log the requests if a session is provided. Closes-Bug: 2035372 Change-Id: I505debd650ddce739665b1c9630f17a3b981279f --- cinderclient/client.py | 4 ++++ cinderclient/tests/unit/test_client.py | 22 +++++++++++++++++++ .../http_log_debug-ff023f069afde3fe.yaml | 7 ++++++ 3 files changed, 33 insertions(+) create mode 100644 releasenotes/notes/http_log_debug-ff023f069afde3fe.yaml diff --git a/cinderclient/client.py b/cinderclient/client.py index c99a2e7a6..85ccf7d5c 100644 --- a/cinderclient/client.py +++ b/cinderclient/client.py @@ -175,6 +175,7 @@ class SessionClient(adapter.LegacyJsonAdapter): def __init__(self, *args, **kwargs): 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): apiver = api_versions.APIVersion(str(apiver)) if apiver.ver_minor != 0: @@ -185,6 +186,8 @@ class SessionClient(adapter.LegacyJsonAdapter): def request(self, *args, **kwargs): kwargs.setdefault('authenticated', False) + if self.http_log_debug: + kwargs.setdefault('logger', self._logger) # Note(tpatil): The standard call raises errors from # keystoneauth, here we need to raise the cinderclient errors. @@ -721,6 +724,7 @@ def _construct_http_client(username=None, password=None, project_id=None, region_name=region_name, retries=retries, api_version=api_version, + http_log_debug=http_log_debug, **kwargs) else: # FIXME(jamielennox): username and password are now optional. Need diff --git a/cinderclient/tests/unit/test_client.py b/cinderclient/tests/unit/test_client.py index b7cd3c63a..ba0208ead 100644 --- a/cinderclient/tests/unit/test_client.py +++ b/cinderclient/tests/unit/test_client.py @@ -246,6 +246,28 @@ class ClientTest(utils.TestCase): # is not getting 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): def test_req_does_not_log_sensitive_info(self): diff --git a/releasenotes/notes/http_log_debug-ff023f069afde3fe.yaml b/releasenotes/notes/http_log_debug-ff023f069afde3fe.yaml new file mode 100644 index 000000000..6a72cdc49 --- /dev/null +++ b/releasenotes/notes/http_log_debug-ff023f069afde3fe.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + `Bug #2035372 + `_: Fixed + not honoring ``http_log_debug`` parameter in ``cinderclient.client.Client`` + when also providing a session.