From e1d221000f6aaa52312c4138eac239a93593ba32 Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Fri, 27 Apr 2018 18:16:12 +0800 Subject: Add logging for rest calls to ONAP services Change-Id: I9372f303790241a2ba580e212d5dea5a7d1844e0 Issue-ID: MULTICLOUD-178 Signed-off-by: Yun Huang --- share/common/utils/restcall.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/share/common/utils/restcall.py b/share/common/utils/restcall.py index f19ea838..05788bc9 100644 --- a/share/common/utils/restcall.py +++ b/share/common/utils/restcall.py @@ -63,6 +63,10 @@ def _call_req(base_url, user, passwd, auth_type, headers['Authorization'] = 'Basic ' + \ base64.b64encode(tmpauthsource).decode('utf-8') + logger.info("Making rest call with uri,method, header = %s, %s, %s" % (full_url, method.upper(), headers)) + if content: + logger.debug("with content = %s" % (content)) + ca_certs = None for retry_times in range(MAX_RETRY_TIME): http = httplib2.Http( @@ -89,7 +93,10 @@ def _call_req(base_url, user, passwd, auth_type, ret = [1, "Unable to connect to %s" % full_url, resp_status] continue raise ex + logger.info("Rest call finished with status = %s", resp_status) + logger.debug("with response content = %s" % resp_body) except urllib.error.URLError as err: + logger.error("status=%s, error message=%s" % (resp_status, str(err))) ret = [2, str(err), resp_status] except Exception: logger.error(traceback.format_exc()) @@ -99,7 +106,10 @@ def _call_req(base_url, user, passwd, auth_type, ret = [3, str(sys.exc_info()), resp_status] except: logger.error(traceback.format_exc()) + if not resp_status: + resp_status = status.HTTP_500_INTERNAL_SERVER_ERROR ret = [4, str(sys.exc_info()), resp_status] + return ret @@ -123,8 +133,6 @@ def req_to_aai(resource, method, content='', appid=settings.MULTICLOUD_APP_ID): 'accept': 'application/json' } - logger.debug("req_to_aai--%s::> %s, %s" % - (tmp_trasaction_id, method, _combine_url(settings.AAI_BASE_URL,resource))) return _call_req(settings.AAI_BASE_URL, settings.AAI_USERNAME, settings.AAI_PASSWORD, rest_no_auth, resource, method, content=json.dumps(content), extra_headers=headers) -- cgit 1.2.3-korg