Add logging for rest calls to ONAP services 69/45069/3
authorYun Huang <yun.huang@windriver.com>
Fri, 27 Apr 2018 10:16:12 +0000 (18:16 +0800)
committerYun Huang <yun.huang@windriver.com>
Fri, 27 Apr 2018 10:16:12 +0000 (18:16 +0800)
Change-Id: I9372f303790241a2ba580e212d5dea5a7d1844e0
Issue-ID: MULTICLOUD-178
Signed-off-by: Yun Huang <yun.huang@windriver.com>
share/common/utils/restcall.py

index f19ea83..05788bc 100644 (file)
@@ -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)