[BuildMonitor] TPE-185 fix the SR status error 65/144665/1
authorSungHun Hwang <sh0924.hwang@samsung.com>
Thu, 17 Aug 2017 10:10:53 +0000 (19:10 +0900)
committerSungHun Hwang <sh0924.hwang@samsung.com>
Thu, 17 Aug 2017 10:10:53 +0000 (19:10 +0900)
PROBLEM:
  The status in Fhub3.0 stays 'Testing' step

REASON:
  finding bulid_project_id part is mssing

SOLUTION:
  change the code to get the build_project_id

Change-Id: Ic09131fc814725847d95fe76639ab40f0a4f6845
Signed-off-by: SungHun Hwang <sh0924.hwang@samsung.com>
job_trbs_test_result_receiver.py

index f170ab1..50b58ba 100644 (file)
@@ -11,14 +11,17 @@ import re
 import datetime
 from codebase import *
 
-def check_test_failure(data, is_ref_exist, is_perf_exist):
+def is_test_succeeded(data, is_ref_exist, is_perf_exist):
 
-    # if ref result is existed, then compare with ref result.
+    # if ref results exist, compare with them.
     if is_ref_exist:
         for suite in data['TCT']['SUITE'].keys():
-            case_tests = ['pass_case', 'fail_case', 'block_case', 'na_case']
+            c = 'pass_case'
+            if data['TCT']['SUITE'][suite][c] < data['REF']['SUITE'][suite][c]:
+                return 0
+            case_tests = ['fail_case', 'block_case', 'na_case']
             for c in case_tests:
-                if data['TCT']['SUITE'][suite][c] != data['REF']['SUITE'][suite][c]:
+                if data['TCT']['SUITE'][suite][c] > data['REF']['SUITE'][suite][c]:
                     return 0
     else:
         if data['TCT']['COUNT']['total_case'] != data['TCT']['COUNT']['pass_case']:
@@ -34,17 +37,25 @@ def check_test_failure(data, is_ref_exist, is_perf_exist):
 
     return 1
 
-def insert_test_stage(data, MYSQL, sr_id, is_ref_exist, is_perf_exist ):
+def insert_test_stage(data, MYSQL, sr_id, snapshot, is_ref_exist, is_perf_exist ):
     status = 'F';
-    if check_test_failure(data, is_ref_exist, is_perf_exist):
+    if is_test_succeeded(data, is_ref_exist, is_perf_exist):
         status = 'S';
 
+    build_project_id = 0
+    sql_data = (snapshot,)
+    sql = "SELECT build_project_id FROM build_snapshot WHERE snapshot_name=%s LIMIT 1"
+    MYSQL['cursor'].execute(sql, sql_data)
+    row = MYSQL['cursor'].fetchall()
+    if len(row) > 0:
+        build_project_id = row[0]['build_project_id']
+
     cur_time = datetime.datetime.now()
 
-    sql_data = (sr_id, cur_time, cur_time, status, status)
+    sql_data = (sr_id, cur_time, cur_time, status, build_project_id, status)
     sql = "INSERT INTO sr_stage (sr_status_id, info_stage_id, "\
         " stage_start_time, stage_end_time, stage_status, build_project_id)"\
-        " VALUES (%s, 101, %s, %s, %s, 0) ON DUPLICATE KEY UPDATE stage_status=%s"
+        " VALUES (%s, 101, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE stage_status=%s"
     pprint.pprint(sql)
     pprint.pprint(sql_data)
     MYSQL['cursor'].execute(sql, sql_data)
@@ -801,6 +812,7 @@ if __name__ == "__main__":
                         print "[ERROR] MYSQL : %s (%s)" % (str(e), sql)
 
 
-    insert_test_stage(CONFIG['RAW'], MYSQL, DINFO['sr_status_id'] , isExistRef , isExistPerf)
+    snapshot = CONFIG['RAW']['TCT']['environment']['build_id']
+    insert_test_stage(CONFIG['RAW'], MYSQL, DINFO['sr_status_id'], snapshot, isExistRef , isExistPerf)
 
     exit(0)