add log info when publish json to elasticsearch failed 43/15943/3
authorSerenaFeng <feng.xiaowei@zte.com.cn>
Wed, 22 Jun 2016 12:46:56 +0000 (20:46 +0800)
committerSerenaFeng <feng.xiaowei@zte.com.cn>
Thu, 30 Jun 2016 03:15:24 +0000 (11:15 +0800)
add logger.info when publish failed

JIRA: FUNCTEST-325

Change-Id: I353001c4305af31dd725e0977ced53d52ba79470
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
utils/test/scripts/mongo_to_elasticsearch.py
utils/test/scripts/shared_utils.py

index a569ac6..2ffbc17 100644 (file)
@@ -395,7 +395,12 @@ def publish_mongo_data(output_destination):
             for mongo_json_line in fobj:
                 test_result = json.loads(mongo_json_line)
                 if modify_mongo_entry(test_result):
-                    shared_utils.publish_json(test_result, es_creds, output_destination)
+                    status, data = shared_utils.publish_json(test_result, es_creds, output_destination)
+                    if status > 300:
+                        project = test_result['project_name']
+                        case_name = test_result['case_name']
+                        logger.info('project {} case {} publish failed, due to [{}]'
+                                    .format(project, case_name, json.loads(data)['error']['reason']))
     finally:
         if os.path.exists(tmp_filename):
             os.remove(tmp_filename)
index 91ce38e..8bbbdbe 100644 (file)
@@ -12,9 +12,11 @@ def publish_json(json_ojb, creds, output_destination):
     json_dump = json.dumps(json_ojb)
     if output_destination == 'stdout':
         print json_dump
+        return 200, None
     else:
         headers = urllib3.make_headers(basic_auth=creds)
-        http.request('POST', output_destination, headers=headers, body=json_dump)
+        result = http.request('POST', output_destination, headers=headers, body=json_dump)
+        return result.status, result.data
 
 
 def _get_nr_of_hits(elastic_json):