From 7cb409aac22709574d33881d0649996ac919cc2f Mon Sep 17 00:00:00 2001 From: Sanghoon Lee Date: Mon, 10 Jul 2017 11:37:04 +0900 Subject: [PATCH] [TRBS][Handling when reference result is not existed] PROBLEM: - DA TRBS doesn't have REF and PERF result. SOLUTION: - When REF and PERF result is not existed, then skip the inserting into db. Change-Id: I14db54ffc8f758de87deb2c2713d28d65b23b88b --- job_trbs_test_result_receiver.py | 476 ++++++++++++++++++++------------------- 1 file changed, 247 insertions(+), 229 deletions(-) diff --git a/job_trbs_test_result_receiver.py b/job_trbs_test_result_receiver.py index 33a642b..f170ab1 100755 --- a/job_trbs_test_result_receiver.py +++ b/job_trbs_test_result_receiver.py @@ -11,27 +11,32 @@ import re import datetime from codebase import * -def check_test_failure(data): - # tct test. - for suite in data['TCT']['SUITE'].keys(): - case_tests = ['pass_case', 'fail_case', 'block_case', 'na_case'] - for c in case_tests: - if data['TCT']['SUITE'][suite][c] != data['REF']['SUITE'][suite][c]: - return 0 +def check_test_failure(data, is_ref_exist, is_perf_exist): + + # if ref result is existed, then compare with ref result. + if is_ref_exist: + for suite in data['TCT']['SUITE'].keys(): + case_tests = ['pass_case', 'fail_case', 'block_case', 'na_case'] + for c in case_tests: + 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']: + return 0 # smoke test. if data['SMOKES']['COUNT']['fail_case'] > 0: return 0 # perf test - if data['PERFS']['COUNT']['fail_case'] > 0: + if (is_perf_exist) and (data['PERFS']['COUNT']['fail_case'] > 0): return 0 return 1 -def insert_test_stage(data, MYSQL, sr_id): +def insert_test_stage(data, MYSQL, sr_id, is_ref_exist, is_perf_exist ): status = 'F'; - if check_test_failure(data): + if check_test_failure(data, is_ref_exist, is_perf_exist): status = 'S'; cur_time = datetime.datetime.now() @@ -167,131 +172,134 @@ if __name__ == "__main__": exit(1) - insert_test_stage(CONFIG['RAW'], MYSQL, DINFO['sr_status_id']) - SQL['REF'] = {} - # select ref - SQL['REF']['select'] = ( - "SELECT * " - "FROM trbs_ref " - "WHERE build_id= %(build_id)s AND tct_profile = %(tct_profile)s ORDER BY id DESC" - ) + # If reference is exists, then insert into DB. + isExistRef = True - MYSQL['cursor'].execute( SQL['REF']['select'], CONFIG['RAW']['REF']['environment'] ) - TEMP = MYSQL['cursor'].fetchall() + if 'environment' not in CONFIG['RAW']['REF'] : + isExistRef = False - VALUES = { - 'total' : CONFIG['RAW']['REF']['COUNT']['total_case'], - 'pass' : CONFIG['RAW']['REF']['COUNT']['pass_case'], - 'fail' : CONFIG['RAW']['REF']['COUNT']['fail_case'], - 'block' : CONFIG['RAW']['REF']['COUNT']['block_case'], - 'na' : CONFIG['RAW']['REF']['COUNT']['na_case'], - 'pcnt' : round( (float(CONFIG['RAW']['REF']['COUNT']['pass_case'])/float(CONFIG['RAW']['REF']['COUNT']['total_case']))*100, 2 ), - 'plan_name' : CONFIG['RAW']['REF']['plan_name'], - 'time_start' : CONFIG['RAW']['REF']['start_at'], - 'time_end' : CONFIG['RAW']['REF']['end_at'], - 'build_id' : CONFIG['RAW']['REF']['environment']['build_id'], - 'device_id' : CONFIG['RAW']['REF']['environment']['device_id'], - 'device_model' : CONFIG['RAW']['REF']['environment']['device_model'], - 'device_name' : CONFIG['RAW']['REF']['environment']['device_name'], - 'device_host' : CONFIG['RAW']['REF']['environment']['device_host'], - 'manufacturer' : CONFIG['RAW']['REF']['environment']['manufacturer'], - 'tct_profile' : CONFIG['RAW']['REF']['environment']['tct_profile'], - 'tct_version' : CONFIG['RAW']['REF']['environment']['tct_version'], - 'url' : CONFIG['RAW']['REF']['url'] - } - - table = "trbs_ref" - sql = "" + if ( isExistRef ) : + SQL['REF'] = {} + # select ref + SQL['REF']['select'] = ( + "SELECT * " + "FROM trbs_ref " + "WHERE build_id= %(build_id)s AND tct_profile = %(tct_profile)s ORDER BY id DESC" + ) - # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 - if len( TEMP ) > 0: - DINFO['ref_id'] = TEMP[0]['id'] - sql = makeUpdateSQL( table, VALUES, DINFO['ref_id'] ) - print ("[INFO] MYSQL : Can search Reference id = %(id)s, build_id = %(build_id)s" % TEMP[0]) - print "[INFO] MYSQL : Updated Ref to", table, ", build_id =", VALUES['build_id'] + MYSQL['cursor'].execute( SQL['REF']['select'], CONFIG['RAW']['REF']['environment'] ) + TEMP = MYSQL['cursor'].fetchall() - else: - print "[WARN] MYSQL : There is no Reference TCT result. Now, Inserting...", CONFIG['RAW']['REF']['environment']['build_id'] + VALUES = { + 'total' : CONFIG['RAW']['REF']['COUNT']['total_case'], + 'pass' : CONFIG['RAW']['REF']['COUNT']['pass_case'], + 'fail' : CONFIG['RAW']['REF']['COUNT']['fail_case'], + 'block' : CONFIG['RAW']['REF']['COUNT']['block_case'], + 'na' : CONFIG['RAW']['REF']['COUNT']['na_case'], + 'pcnt' : round( (float(CONFIG['RAW']['REF']['COUNT']['pass_case'])/float(CONFIG['RAW']['REF']['COUNT']['total_case']))*100, 2 ), + 'plan_name' : CONFIG['RAW']['REF']['plan_name'], + 'time_start' : CONFIG['RAW']['REF']['start_at'], + 'time_end' : CONFIG['RAW']['REF']['end_at'], + 'build_id' : CONFIG['RAW']['REF']['environment']['build_id'], + 'device_id' : CONFIG['RAW']['REF']['environment']['device_id'], + 'device_model' : CONFIG['RAW']['REF']['environment']['device_model'], + 'device_name' : CONFIG['RAW']['REF']['environment']['device_name'], + 'device_host' : CONFIG['RAW']['REF']['environment']['device_host'], + 'manufacturer' : CONFIG['RAW']['REF']['environment']['manufacturer'], + 'tct_profile' : CONFIG['RAW']['REF']['environment']['tct_profile'], + 'tct_version' : CONFIG['RAW']['REF']['environment']['tct_version'], + 'url' : CONFIG['RAW']['REF']['url'] + } - sql = makeInsertSQL( table, VALUES ) - print "[INFO] MYSQL : INSERT to", table, ", build_id =", VALUES['build_id'] + table = "trbs_ref" + sql = "" - try: - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() + # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 + if len( TEMP ) > 0: + DINFO['ref_id'] = TEMP[0]['id'] + sql = makeUpdateSQL( table, VALUES, DINFO['ref_id'] ) + print ("[INFO] MYSQL : Can search Reference id = %(id)s, build_id = %(build_id)s" % TEMP[0]) + print "[INFO] MYSQL : Updated Ref to", table, ", build_id =", VALUES['build_id'] + else: + print "[WARN] MYSQL : There is no Reference TCT result. Now, Inserting...", CONFIG['RAW']['REF']['environment']['build_id'] + sql = makeInsertSQL( table, VALUES ) + print "[INFO] MYSQL : INSERT to", table, ", build_id =", VALUES['build_id'] - except MySQLdb.Error, e: try: - print "[ERROR] MYSQL : [%d]: %s (%s)" % (e.args[0], e.args[1], sql) - except IndexError: - print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) + MYSQL['cursor'].execute( sql ) + MYSQL['connection'].commit() + except MySQLdb.Error, e: + try: + print "[ERROR] MYSQL : [%d]: %s (%s)" % (e.args[0], e.args[1], sql) + except IndexError: + print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) - MYSQL['cursor'].execute( SQL['REF']['select'], CONFIG['RAW']['REF']['environment'] ) - TEMP = MYSQL['cursor'].fetchall() + MYSQL['cursor'].execute( SQL['REF']['select'], CONFIG['RAW']['REF']['environment'] ) + TEMP = MYSQL['cursor'].fetchall() - # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 - if len( TEMP ) > 0: - DINFO['ref_id'] = TEMP[0]['id'] - print ("[INFO] MYSQL : Reference id = %(id)s, build_id = %(build_id)s" % TEMP[0]) - else: - print "[ERROR] MYSQL : Can not process reference TCT" - exit(1) + # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 + if len( TEMP ) > 0: + DINFO['ref_id'] = TEMP[0]['id'] + print ("[INFO] MYSQL : Reference id = %(id)s, build_id = %(build_id)s" % TEMP[0]) + else: + print "[ERROR] MYSQL : Can not process reference TCT" + exit(1) - for suite in CONFIG['RAW']['REF']['SUITE'].keys(): + for suite in CONFIG['RAW']['REF']['SUITE'].keys(): - VALUES = { - 'trbs_ref_id' : DINFO['ref_id'], - 'name' : suite, - 'total' : CONFIG['RAW']['REF']['SUITE'][suite]['total_case'], - 'pass' : CONFIG['RAW']['REF']['SUITE'][suite]['pass_case'], - 'pass_rate' : CONFIG['RAW']['REF']['SUITE'][suite]['pass_rate'], - 'fail' : CONFIG['RAW']['REF']['SUITE'][suite]['fail_case'], - 'fail_rate' : CONFIG['RAW']['REF']['SUITE'][suite]['fail_rate'], - 'block' : CONFIG['RAW']['REF']['SUITE'][suite]['block_case'], - 'block_rate' : CONFIG['RAW']['REF']['SUITE'][suite]['block_rate'], - 'na' : CONFIG['RAW']['REF']['SUITE'][suite]['na_case'], - 'na_rate' : CONFIG['RAW']['REF']['SUITE'][suite]['na_rate'] - } + VALUES = { + 'trbs_ref_id' : DINFO['ref_id'], + 'name' : suite, + 'total' : CONFIG['RAW']['REF']['SUITE'][suite]['total_case'], + 'pass' : CONFIG['RAW']['REF']['SUITE'][suite]['pass_case'], + 'pass_rate' : CONFIG['RAW']['REF']['SUITE'][suite]['pass_rate'], + 'fail' : CONFIG['RAW']['REF']['SUITE'][suite]['fail_case'], + 'fail_rate' : CONFIG['RAW']['REF']['SUITE'][suite]['fail_rate'], + 'block' : CONFIG['RAW']['REF']['SUITE'][suite]['block_case'], + 'block_rate' : CONFIG['RAW']['REF']['SUITE'][suite]['block_rate'], + 'na' : CONFIG['RAW']['REF']['SUITE'][suite]['na_case'], + 'na_rate' : CONFIG['RAW']['REF']['SUITE'][suite]['na_rate'] + } - SQL['REF']['select_suite'] = ( - "SELECT * " - "FROM trbs_ref_suite " - "WHERE trbs_ref_id = %(trbs_ref_id)s AND name = %(name)s" - ) + SQL['REF']['select_suite'] = ( + "SELECT * " + "FROM trbs_ref_suite " + "WHERE trbs_ref_id = %(trbs_ref_id)s AND name = %(name)s" + ) - MYSQL['cursor'].execute( SQL['REF']['select_suite'], VALUES ) - TEMP = MYSQL['cursor'].fetchall() + MYSQL['cursor'].execute( SQL['REF']['select_suite'], VALUES ) + TEMP = MYSQL['cursor'].fetchall() - table = "trbs_ref_suite" - sql = "" + table = "trbs_ref_suite" + sql = "" - if len( TEMP ) > 0: - sql = makeUpdateSQL( table, VALUES , TEMP[0]['id']) - print ("[INFO] MYSQL : Updated REF Suite, id = %(id)s, name = %(name)s" % TEMP[0]) + if len( TEMP ) > 0: + sql = makeUpdateSQL( table, VALUES , TEMP[0]['id']) + print ("[INFO] MYSQL : Updated REF Suite, id = %(id)s, name = %(name)s" % TEMP[0]) - else: - sql = makeInsertSQL( table, VALUES ) - print "[INFO] MYSQL : INSERT to", table, ", trbs_ref_id =", DINFO['ref_id'], ", name =", suite + else: + sql = makeInsertSQL( table, VALUES ) + print "[INFO] MYSQL : INSERT to", table, ", trbs_ref_id =", DINFO['ref_id'], ", name =", suite - try: - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() + try: + MYSQL['cursor'].execute( sql ) + MYSQL['connection'].commit() - except MySQLdb.Error, e: - try: - print "[ERROR] MYSQL : [%d]: %s (%s)" % (e.args[0], e.args[1], sql) - except IndexError: - print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) + except MySQLdb.Error, e: + try: + print "[ERROR] MYSQL : [%d]: %s (%s)" % (e.args[0], e.args[1], sql) + except IndexError: + print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) @@ -311,10 +319,15 @@ if __name__ == "__main__": if int(CONFIG['RAW']['TCT']['COUNT']['total_case']) > 0: pcnt = round( (float(CONFIG['RAW']['TCT']['COUNT']['pass_case'])/float(CONFIG['RAW']['TCT']['COUNT']['total_case']))*100, 2 ) + # if reference is not exists, then value of ref_id is -1 + ref_id = "-1" + + if isExistRef : + ref_id = DINFO['ref_id'] VALUES = { 'sr_status_id' : DINFO['sr_status_id'], - 'ref_id' : DINFO['ref_id'], + 'ref_id' : ref_id, 'sr_name' : DINFO['sr'], 'snapshot_num' : DINFO['snapshot_num'], 'profile' : CONFIG['RAW']['TCT']['environment']['tct_profile'], @@ -429,7 +442,6 @@ if __name__ == "__main__": - SQL['SMOKES'] = {} # select smokes SQL['SMOKES']['select'] = ( @@ -601,120 +613,57 @@ if __name__ == "__main__": SQL['PERFS'] = {} - # select perfs - SQL['PERFS']['select'] = ( - "SELECT * " - "FROM trbs_perf " - "WHERE sr_name = %(sr)s AND snapshot_num = %(snapshot_num)s ORDER BY id DESC" - ) - MYSQL['cursor'].execute( SQL['PERFS']['select'], DINFO ) - TEMP = MYSQL['cursor'].fetchall() + # If perf is existed, then insert into DB. + isExistPerf = True + if 'DEVICE' not in CONFIG['RAW']['PERFS'] : + isExistPerf = False - VALUES = { - 'sr_status_id' : DINFO['sr_status_id'], - 'sr_name' : DINFO['sr'], - 'snapshot_num' : DINFO['snapshot_num'], - 'profile' : CONFIG['RAW']['TCT']['environment']['tct_profile'], - 'device_core' : CONFIG['RAW']['PERFS']['DEVICE']['Core_Nums'], - 'device_dvfs' : CONFIG['RAW']['PERFS']['DEVICE']['Def._DVFS_governor'], - 'device_freq' : CONFIG['RAW']['PERFS']['DEVICE']['Frequency_range'], - 'device_kernel' : CONFIG['RAW']['PERFS']['DEVICE']['Kernel_ver.'], - 'device_platform' : CONFIG['RAW']['PERFS']['DEVICE']['Platform_ver.'], - 'total' : CONFIG['RAW']['PERFS']['COUNT']['total_case'], - 'pass' : CONFIG['RAW']['PERFS']['COUNT']['pass_case'], - 'fail' : CONFIG['RAW']['PERFS']['COUNT']['fail_case'], - 'pcnt' : round( (float(CONFIG['RAW']['PERFS']['COUNT']['pass_case'])/float(CONFIG['RAW']['PERFS']['COUNT']['total_case']))*100, 2 ), - 'time_start' : CONFIG['RAW']['TCT']['start_at'], - 'time_end' : CONFIG['RAW']['TCT']['start_at'], - 'url' : CONFIG['RAW']['TCT']['url'] - } - - table = "trbs_perf" - sql = "" - - if len( TEMP ) > 0: - DINFO['trbs_perf_id'] = TEMP[0]['id'] - sql = makeUpdateSQL( table, VALUES,DINFO['trbs_perf_id'] ) - print ("[INFO] MYSQL : Updated PERF, id = %(id)s, sr_name = %(sr_name)s" % TEMP[0]) - - else: - sql = makeInsertSQL( table, VALUES ) - print "[INFO] MYSQL : INSERT to", table - - try: - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() - - - except MySQLdb.Error, e: - try: - print "[ERROR] MYSQL : [%d]: %s (%s)" % (e.args[0], e.args[1], sql) - except IndexError: - print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) - - - - MYSQL['cursor'].execute( SQL['PERFS']['select'], DINFO ) - TEMP = MYSQL['cursor'].fetchall() - - # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 - if len( TEMP ) > 0: - DINFO['trbs_perf_id'] = TEMP[0]['id'] - print ("[INFO] MYSQL : PERF id = %(id)s" % TEMP[0]) - else: - print "[ERROR] MYSQL : Can not process PERF" - exit(1) - - - - #pprint.pprint( CONFIG['RAW']['PERFS'] ) - #exit() + if isExistPerf : + # select perfs + SQL['PERFS']['select'] = ( + "SELECT * " + "FROM trbs_perf " + "WHERE sr_name = %(sr)s AND snapshot_num = %(snapshot_num)s ORDER BY id DESC" + ) - for suite in CONFIG['RAW']['PERFS']['SUITE'].keys(): + MYSQL['cursor'].execute( SQL['PERFS']['select'], DINFO ) + TEMP = MYSQL['cursor'].fetchall() - #pprint.pprint( CONFIG['RAW']['PERFS']['SUITE'][suite] ) - #pprint.pprint( DINFO ) - #exit() VALUES = { - 'trbs_perf_id' : DINFO['trbs_perf_id'], - 'name' : suite, - 'pass' : CONFIG['RAW']['PERFS']['SUITE'][suite]['COUNT']['pass_case'], - 'fail' : CONFIG['RAW']['PERFS']['SUITE'][suite]['COUNT']['fail_case'], - 'total' : CONFIG['RAW']['PERFS']['SUITE'][suite]['COUNT']['total_case'] + 'sr_status_id' : DINFO['sr_status_id'], + 'sr_name' : DINFO['sr'], + 'snapshot_num' : DINFO['snapshot_num'], + 'profile' : CONFIG['RAW']['TCT']['environment']['tct_profile'], + 'device_core' : CONFIG['RAW']['PERFS']['DEVICE']['Core_Nums'], + 'device_dvfs' : CONFIG['RAW']['PERFS']['DEVICE']['Def._DVFS_governor'], + 'device_freq' : CONFIG['RAW']['PERFS']['DEVICE']['Frequency_range'], + 'device_kernel' : CONFIG['RAW']['PERFS']['DEVICE']['Kernel_ver.'], + 'device_platform' : CONFIG['RAW']['PERFS']['DEVICE']['Platform_ver.'], + 'total' : CONFIG['RAW']['PERFS']['COUNT']['total_case'], + 'pass' : CONFIG['RAW']['PERFS']['COUNT']['pass_case'], + 'fail' : CONFIG['RAW']['PERFS']['COUNT']['fail_case'], + 'pcnt' : round( (float(CONFIG['RAW']['PERFS']['COUNT']['pass_case'])/float(CONFIG['RAW']['PERFS']['COUNT']['total_case']))*100, 2 ), + 'time_start' : CONFIG['RAW']['TCT']['start_at'], + 'time_end' : CONFIG['RAW']['TCT']['start_at'], + 'url' : CONFIG['RAW']['TCT']['url'] } - #pprint.pprint( VALUES ) - #exit() - - SQL['PERFS']['select_suite'] = ( - "SELECT * " - "FROM trbs_perf_suite " - "WHERE trbs_perf_id = %(trbs_perf_id)s AND name = %(name)s" - ) - - MYSQL['cursor'].execute( SQL['PERFS']['select_suite'], VALUES ) - TEMP = MYSQL['cursor'].fetchall() - - table = "trbs_perf_suite" + table = "trbs_perf" sql = "" if len( TEMP ) > 0: - DINFO['trbs_perf_suite_id'] = TEMP[0]['id'] - sql = makeUpdateSQL( table, VALUES, DINFO['trbs_perf_suite_id'] ) - print ("[INFO] MYSQL : Updated PERF Suite, id = %(id)s, name = %(name)s" % TEMP[0]) + DINFO['trbs_perf_id'] = TEMP[0]['id'] + sql = makeUpdateSQL( table, VALUES,DINFO['trbs_perf_id'] ) + print ("[INFO] MYSQL : Updated PERF, id = %(id)s, sr_name = %(sr_name)s" % TEMP[0]) else: sql = makeInsertSQL( table, VALUES ) - print "[INFO] MYSQL : INSERT to", table, ", trbs_perf_id =", DINFO['trbs_perf_id'], ", name =", suite - + print "[INFO] MYSQL : INSERT to", table try: - #print sql - #exit() - MYSQL['cursor'].execute( sql ) MYSQL['connection'].commit() @@ -726,56 +675,63 @@ if __name__ == "__main__": print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) - MYSQL['cursor'].execute( SQL['PERFS']['select_suite'], VALUES ) - TEMP = MYSQL['cursor'].fetchall() + MYSQL['cursor'].execute( SQL['PERFS']['select'], DINFO ) + TEMP = MYSQL['cursor'].fetchall() - if len( TEMP ) == 0: - print "[ERROR] MYSQL : Can not process PERF Suite" + # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 + if len( TEMP ) > 0: + DINFO['trbs_perf_id'] = TEMP[0]['id'] + print ("[INFO] MYSQL : PERF id = %(id)s" % TEMP[0]) else: - DINFO['trbs_perf_suite_id'] = TEMP[0]['id'] + print "[ERROR] MYSQL : Can not process PERF" + exit(1) + + #pprint.pprint( CONFIG['RAW']['PERFS'] ) + #exit() - for testcase in CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'].keys(): + for suite in CONFIG['RAW']['PERFS']['SUITE'].keys(): + + #pprint.pprint( CONFIG['RAW']['PERFS']['SUITE'][suite] ) + #pprint.pprint( DINFO ) + #exit() VALUES = { - 'trbs_perf_suite_id' : DINFO['trbs_perf_suite_id'], - 'name' : testcase, - 'actualperf' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['ActualPerf'], - 'criteria' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['Criteria'], - 'expectedperf' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['ExpectedPerf'], - 'range' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['Range'], - 'result' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['Result'], - 'unit' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['Unit'] + 'trbs_perf_id' : DINFO['trbs_perf_id'], + 'name' : suite, + 'pass' : CONFIG['RAW']['PERFS']['SUITE'][suite]['COUNT']['pass_case'], + 'fail' : CONFIG['RAW']['PERFS']['SUITE'][suite]['COUNT']['fail_case'], + 'total' : CONFIG['RAW']['PERFS']['SUITE'][suite]['COUNT']['total_case'] } #pprint.pprint( VALUES ) #exit() - - SQL['PERFS']['select_suite_test'] = ( + SQL['PERFS']['select_suite'] = ( "SELECT * " - "FROM trbs_perf_suite_test " - "WHERE trbs_perf_suite_id = %(trbs_perf_suite_id)s AND name = %(name)s" + "FROM trbs_perf_suite " + "WHERE trbs_perf_id = %(trbs_perf_id)s AND name = %(name)s" ) - MYSQL['cursor'].execute( SQL['PERFS']['select_suite_test'], VALUES ) + MYSQL['cursor'].execute( SQL['PERFS']['select_suite'], VALUES ) TEMP = MYSQL['cursor'].fetchall() - table = "trbs_perf_suite_test" + table = "trbs_perf_suite" sql = "" if len( TEMP ) > 0: - sql = makeUpdateSQL( table, VALUES, TEMP[0]['id'] ) - print ("[INFO] MYSQL : Updated PERF Suite Test, id = %(id)s, name = %(name)s" % TEMP[0]) + DINFO['trbs_perf_suite_id'] = TEMP[0]['id'] + sql = makeUpdateSQL( table, VALUES, DINFO['trbs_perf_suite_id'] ) + print ("[INFO] MYSQL : Updated PERF Suite, id = %(id)s, name = %(name)s" % TEMP[0]) + else: sql = makeInsertSQL( table, VALUES ) - print "[INFO] MYSQL : INSERT to", table, ", trbs_perf_suite_id =", DINFO['trbs_perf_suite_id'], ", name =", testcase + print "[INFO] MYSQL : INSERT to", table, ", trbs_perf_id =", DINFO['trbs_perf_id'], ", name =", suite try: - MYSQL['cursor'].execute( sql ) MYSQL['connection'].commit() @@ -785,4 +741,66 @@ if __name__ == "__main__": except IndexError: print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) + + MYSQL['cursor'].execute( SQL['PERFS']['select_suite'], VALUES ) + TEMP = MYSQL['cursor'].fetchall() + + + if len( TEMP ) == 0: + print "[ERROR] MYSQL : Can not process PERF Suite" + else: + DINFO['trbs_perf_suite_id'] = TEMP[0]['id'] + + + + for testcase in CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'].keys(): + + VALUES = { + 'trbs_perf_suite_id' : DINFO['trbs_perf_suite_id'], + 'name' : testcase, + 'actualperf' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['ActualPerf'], + 'criteria' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['Criteria'], + 'expectedperf' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['ExpectedPerf'], + 'range' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['Range'], + 'result' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['Result'], + 'unit' : CONFIG['RAW']['PERFS']['SUITE'][suite]['TESTCASE'][testcase]['Unit'] + } + + #pprint.pprint( VALUES ) + #exit() + + + SQL['PERFS']['select_suite_test'] = ( + "SELECT * " + "FROM trbs_perf_suite_test " + "WHERE trbs_perf_suite_id = %(trbs_perf_suite_id)s AND name = %(name)s" + ) + + MYSQL['cursor'].execute( SQL['PERFS']['select_suite_test'], VALUES ) + TEMP = MYSQL['cursor'].fetchall() + + table = "trbs_perf_suite_test" + sql = "" + + if len( TEMP ) > 0: + sql = makeUpdateSQL( table, VALUES, TEMP[0]['id'] ) + print ("[INFO] MYSQL : Updated PERF Suite Test, id = %(id)s, name = %(name)s" % TEMP[0]) + else: + sql = makeInsertSQL( table, VALUES ) + print "[INFO] MYSQL : INSERT to", table, ", trbs_perf_suite_id =", DINFO['trbs_perf_suite_id'], ", name =", testcase + + + try: + MYSQL['cursor'].execute( sql ) + MYSQL['connection'].commit() + + except MySQLdb.Error, e: + try: + print "[ERROR] MYSQL : [%d]: %s (%s)" % (e.args[0], e.args[1], sql) + except IndexError: + print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) + + + insert_test_stage(CONFIG['RAW'], MYSQL, DINFO['sr_status_id'] , isExistRef , isExistPerf) + exit(0) -- 2.7.4