json_rpc.client: log the URL and exceptions

Change-Id: I0c02d68fd82dc5c9d5fec32ca98f02e98228eca2
This commit is contained in:
Dmitry Tantsur 2022-07-13 12:37:27 +02:00
parent d7a2345a62
commit 2337a06533
2 changed files with 10 additions and 5 deletions

View File

@ -185,15 +185,20 @@ class _CallContext(object):
body['id'] = (getattr(context, 'request_id', None)
or uuidutils.generate_uuid())
LOG.debug("RPC %s with %s", method, strutils.mask_dict_password(body))
scheme = 'http'
if CONF.json_rpc.use_ssl:
scheme = 'https'
url = '%s://%s:%d' % (scheme,
netutils.escape_ipv6(self.host),
CONF.json_rpc.port)
result = _get_session().post(url, json=body)
LOG.debug('RPC %s returned %s', method,
LOG.debug("RPC %s to %s with %s", method, url,
strutils.mask_dict_password(body))
try:
result = _get_session().post(url, json=body)
except Exception as exc:
LOG.debug('RPC %s to %s failed with %s', method, url, exc)
raise
LOG.debug('RPC %s to %s returned %s', method, url,
strutils.mask_password(result.text or '<None>'))
if not cast:

View File

@ -620,10 +620,10 @@ class TestClient(base.IronicLibTestCase):
'method': 'do_something',
'params': {'node': request, 'context': self.ctx_json}})
self.assertEqual(2, mock_log.call_count)
node = mock_log.call_args_list[0][0][2]['params']['node']
node = mock_log.call_args_list[0][0][3]['params']['node']
self.assertEqual(node, {'redfish_username': 'admin',
'redfish_password': '***'})
resp_text = mock_log.call_args_list[1][0][2]
resp_text = mock_log.call_args_list[1][0][3]
self.assertEqual(body.replace('passw0rd', '***'), resp_text)