From 0824b82b0c349e50a478e5efe9ae938a106ebe2d Mon Sep 17 00:00:00 2001 From: Sanghoon Lee Date: Fri, 30 Jun 2017 13:32:04 +0900 Subject: [PATCH] [TRBS][Fixed trbs test result receiver] Handling duplicate data when TRBS is retriggered. Change-Id: I74d0216b601a74ace3aeef6e4ef92ec81a9b2e9b --- codebase.py | 12 + job_trbs_test_result_receiver.py | 696 +++++++++++++++++---------------------- 2 files changed, 306 insertions(+), 402 deletions(-) diff --git a/codebase.py b/codebase.py index 4559262..66ecc70 100755 --- a/codebase.py +++ b/codebase.py @@ -86,7 +86,19 @@ def default(obj): raise TypeError('Not sure how to serialize %s' % (obj,)) +def makeUpdateSQL( table, item, id ): + set_sql = [] + + for k, v in item.items(): + if type(v) == str: + item[k] = v.replace("'", '"') + + set_sql.append( "`%s` = '%s'" % ( k,str(item[k]) ) ) + + result = ','.join(set_sql) + + return ("UPDATE %s SET %s WHERE id = %s" % (table, result, id)) diff --git a/job_trbs_test_result_receiver.py b/job_trbs_test_result_receiver.py index d9dcae5..9092856 100755 --- a/job_trbs_test_result_receiver.py +++ b/job_trbs_test_result_receiver.py @@ -115,8 +115,6 @@ if __name__ == "__main__": "WHERE s.sr= %(sr)s AND d.sr_status_id = s.id ORDER BY d.id DESC" ) -# print "SQL[sr][select_srinfo] : ", SQL['SR']['select_srinfo'] -# print "DINFO : ", DINFO MYSQL['cursor'].execute( SQL['SR']['select_srinfo'], DINFO ) TEMP = MYSQL['cursor'].fetchall() @@ -136,19 +134,6 @@ if __name__ == "__main__": - - - - - - #print( DINFO['sr'] ) - #pprint.pprint( CONFIG['RAW']['REF']['environment'] ) - #exit() - - #print( CONFIG['RAW']['REF']['environment'] - - - SQL['REF'] = {} # select ref SQL['REF']['select'] = ( @@ -160,82 +145,72 @@ if __name__ == "__main__": MYSQL['cursor'].execute( SQL['REF']['select'], CONFIG['RAW']['REF']['environment'] ) TEMP = MYSQL['cursor'].fetchall() + 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 = "" + # 결과가 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]) + 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 : Can not search Reference TCT - ", CONFIG['RAW']['REF']['environment']['build_id'] + print "[WARN] MYSQL : There is no Reference TCT result. Now, Inserting...", CONFIG['RAW']['REF']['environment']['build_id'] - #pprint.pprint( CONFIG['RAW']['REF'] ) + sql = makeInsertSQL( table, VALUES ) + print "[INFO] MYSQL : INSERT to", table, ", build_id =", VALUES['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'] - } + try: + MYSQL['cursor'].execute( sql ) + MYSQL['connection'].commit() - #pprint.pprint( VALUES ) - table = "trbs_ref" + except MySQLdb.Error, e: try: - sql = makeInsertSQL( table, VALUES ) - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() - - 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['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) - - + 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() + # 결과가 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(): - #pprint.pprint( CONFIG['RAW']['REF']['SUITE'][suite] ) - #pprint.pprint( DINFO ) - #exit() - VALUES = { 'trbs_ref_id' : DINFO['ref_id'], 'name' : suite, @@ -250,8 +225,6 @@ if __name__ == "__main__": 'na_rate' : CONFIG['RAW']['REF']['SUITE'][suite]['na_rate'] } - - SQL['REF']['select_suite'] = ( "SELECT * " "FROM trbs_ref_suite " @@ -261,41 +234,34 @@ if __name__ == "__main__": MYSQL['cursor'].execute( SQL['REF']['select_suite'], VALUES ) TEMP = MYSQL['cursor'].fetchall() - if len( TEMP ) > 0: - print ("[WARN] MYSQL : Duplicate REF Suite, id = %(id)s, name = %(name)s" % TEMP[0]) - - else: - - - table = "trbs_ref_suite" - - try: - sql = makeInsertSQL( table, VALUES ) - - #print sql - #exit() - - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() - - print "[INFO] MYSQL : INSERT to", table, ", trbs_ref_id =", DINFO['ref_id'], ", name =", suite - - 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) + 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]) + 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() + 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) SQL['TCT'] = {} + # select tct SQL['TCT']['select'] = ( "SELECT * " @@ -306,93 +272,74 @@ if __name__ == "__main__": MYSQL['cursor'].execute( SQL['TCT']['select'], DINFO ) TEMP = MYSQL['cursor'].fetchall() - if len( TEMP ) > 0: - DINFO['trbs_tct_id'] = TEMP[0]['id'] - print ("[WARN] MYSQL : Duplicate TCT, id = %(id)s, sr_name = %(sr_name)s" % TEMP[0]) - - else: - - #pprint.pprint( CONFIG['RAW']['TCT'] ) - #pprint.pprint( DINFO ) - - VALUES = { - 'sr_status_id' : DINFO['sr_status_id'], - 'ref_id' : DINFO['ref_id'], - 'sr_name' : DINFO['sr'], - 'snapshot_num' : DINFO['snapshot_num'], - 'profile' : CONFIG['RAW']['TCT']['environment']['tct_profile'], - 'total' : CONFIG['RAW']['TCT']['COUNT']['total_case'], - 'pass' : CONFIG['RAW']['TCT']['COUNT']['pass_case'], - 'fail' : CONFIG['RAW']['TCT']['COUNT']['fail_case'], - 'block' : CONFIG['RAW']['TCT']['COUNT']['block_case'], - 'na' : CONFIG['RAW']['TCT']['COUNT']['na_case'], - 'pcnt' : round( (float(CONFIG['RAW']['TCT']['COUNT']['pass_case'])/float(CONFIG['RAW']['TCT']['COUNT']['total_case']))*100, 2 ), - 'plan_name' : CONFIG['RAW']['TCT']['plan_name'], - 'time_start' : CONFIG['RAW']['TCT']['start_at'], - 'time_end' : CONFIG['RAW']['TCT']['end_at'], - 'build_id' : CONFIG['RAW']['TCT']['environment']['build_id'], - 'device_id' : CONFIG['RAW']['TCT']['environment']['device_id'], - 'device_model' : CONFIG['RAW']['TCT']['environment']['device_model'], - 'device_name' : CONFIG['RAW']['TCT']['environment']['device_name'], - 'device_host' : CONFIG['RAW']['TCT']['environment']['device_host'], - 'manufacturer' : CONFIG['RAW']['TCT']['environment']['manufacturer'], - 'tct_profile' : CONFIG['RAW']['TCT']['environment']['tct_profile'], - 'tct_version' : CONFIG['RAW']['TCT']['environment']['tct_version'], - 'url' : CONFIG['RAW']['TCT']['url'] - } + VALUES = { + 'sr_status_id' : DINFO['sr_status_id'], + 'ref_id' : DINFO['ref_id'], + 'sr_name' : DINFO['sr'], + 'snapshot_num' : DINFO['snapshot_num'], + 'profile' : CONFIG['RAW']['TCT']['environment']['tct_profile'], + 'total' : CONFIG['RAW']['TCT']['COUNT']['total_case'], + 'pass' : CONFIG['RAW']['TCT']['COUNT']['pass_case'], + 'fail' : CONFIG['RAW']['TCT']['COUNT']['fail_case'], + 'block' : CONFIG['RAW']['TCT']['COUNT']['block_case'], + 'na' : CONFIG['RAW']['TCT']['COUNT']['na_case'], + 'pcnt' : round( (float(CONFIG['RAW']['TCT']['COUNT']['pass_case'])/float(CONFIG['RAW']['TCT']['COUNT']['total_case']))*100, 2 ), + 'plan_name' : CONFIG['RAW']['TCT']['plan_name'], + 'time_start' : CONFIG['RAW']['TCT']['start_at'], + 'time_end' : CONFIG['RAW']['TCT']['end_at'], + 'build_id' : CONFIG['RAW']['TCT']['environment']['build_id'], + 'device_id' : CONFIG['RAW']['TCT']['environment']['device_id'], + 'device_model' : CONFIG['RAW']['TCT']['environment']['device_model'], + 'device_name' : CONFIG['RAW']['TCT']['environment']['device_name'], + 'device_host' : CONFIG['RAW']['TCT']['environment']['device_host'], + 'manufacturer' : CONFIG['RAW']['TCT']['environment']['manufacturer'], + 'tct_profile' : CONFIG['RAW']['TCT']['environment']['tct_profile'], + 'tct_version' : CONFIG['RAW']['TCT']['environment']['tct_version'], + 'url' : CONFIG['RAW']['TCT']['url'] + } - #pprint.pprint( VALUES ) - - table = "trbs_tct" - - try: - sql = makeInsertSQL( table, VALUES ) - - #print sql - #exit() - - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() - - 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) - + table = "trbs_tct" + sql = "" - MYSQL['cursor'].execute( SQL['TCT']['select'], DINFO ) - TEMP = MYSQL['cursor'].fetchall() + if len( TEMP ) > 0: + DINFO['trbs_tct_id'] = TEMP[0]['id'] + sql = makeUpdateSQL( table, VALUES , DINFO['trbs_tct_id']) + print ("[Info] MYSQL : Updated TCT, id = %(id)s, sr_name = %(sr_name)s" % TEMP[0]) - # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 - if len( TEMP ) > 0: - DINFO['trbs_tct_id'] = TEMP[0]['id'] - print ("[INFO] MYSQL : TCT id = %(id)s, build_id = %(build_id)s" % TEMP[0]) - else: - print "[ERROR] MYSQL : Can not process TCT" - exit(1) + else: + sql = makeInsertSQL( table, VALUES ) + print "[INFO] MYSQL : INSERT to", table, ", build_id =", VALUES['build_id'] + 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['TCT']['select'], DINFO ) + TEMP = MYSQL['cursor'].fetchall() + # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 + if len( TEMP ) > 0: + DINFO['trbs_tct_id'] = TEMP[0]['id'] + print ("[INFO] MYSQL : TCT id = %(id)s, build_id = %(build_id)s" % TEMP[0]) + else: + print "[ERROR] MYSQL : Can not process TCT" + exit(1) - #pprint.pprint( CONFIG['RAW']['TCT'] ) - #exit() for suite in CONFIG['RAW']['TCT']['SUITE'].keys(): - #pprint.pprint( CONFIG['RAW']['TCT']['SUITE'][suite] ) - #pprint.pprint( DINFO ) - #exit() - VALUES = { 'trbs_tct_id' : DINFO['trbs_tct_id'], 'name' : suite, @@ -407,8 +354,6 @@ if __name__ == "__main__": 'na_rate' : CONFIG['RAW']['TCT']['SUITE'][suite]['na_rate'] } - - SQL['TCT']['select_suite'] = ( "SELECT * " "FROM trbs_tct_suite " @@ -418,47 +363,29 @@ if __name__ == "__main__": MYSQL['cursor'].execute( SQL['TCT']['select_suite'], VALUES ) TEMP = MYSQL['cursor'].fetchall() + table = "trbs_tct_suite" + sql = "" + if len( TEMP ) > 0: - print ("[WARN] MYSQL : Duplicate TCT Suite, id = %(id)s, name = %(name)s" % TEMP[0]) + sql = makeUpdateSQL( table, VALUES, TEMP[0]['id'] ) + print ("[INFO] MYSQL : Updated TCT Suite, id = %(id)s, name = %(name)s" % TEMP[0]) else: + sql = makeInsertSQL( table, VALUES ) + print "[INFO] MYSQL : INSERT to", table, ", trbs_tct_id =", DINFO['trbs_tct_id'], ", name =", suite + try: + #print sql + #exit() + MYSQL['cursor'].execute( sql ) + MYSQL['connection'].commit() - table = "trbs_tct_suite" + except MySQLdb.Error, e: try: - sql = makeInsertSQL( table, VALUES ) - - #print sql - #exit() - - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() - - print "[INFO] MYSQL : INSERT to", table, ", trbs_tct_id =", DINFO['trbs_tct_id'], ", name =", suite - - 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) - - - - - - - - - - - - - - - - - + print "[ERROR] MYSQL : [%d]: %s (%s)" % (e.args[0], e.args[1], sql) + except IndexError: + print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) @@ -472,78 +399,66 @@ if __name__ == "__main__": "WHERE sr_name = %(sr)s AND snapshot_num = %(snapshot_num)s ORDER BY id DESC" ) + + VALUES = { + 'sr_status_id' : DINFO['sr_status_id'], + 'sr_name' : DINFO['sr'], + 'snapshot_num' : DINFO['snapshot_num'], + 'profile' : CONFIG['RAW']['TCT']['environment']['tct_profile'], + 'total' : CONFIG['RAW']['SMOKES']['COUNT']['total_case'], + 'pass' : CONFIG['RAW']['SMOKES']['COUNT']['pass_case'], + 'fail' : CONFIG['RAW']['SMOKES']['COUNT']['fail_case'], + 'pcnt' : round( (float(CONFIG['RAW']['SMOKES']['COUNT']['pass_case'])/float(CONFIG['RAW']['SMOKES']['COUNT']['total_case']))*100, 2 ), + 'time_start' : CONFIG['RAW']['TCT']['start_at'], + 'time_end' : CONFIG['RAW']['TCT']['start_at'], + 'url' : CONFIG['RAW']['TCT']['url'] + } + MYSQL['cursor'].execute( SQL['SMOKES']['select'], DINFO ) TEMP = MYSQL['cursor'].fetchall() + table = "trbs_smoke" + sql = "" + if len( TEMP ) > 0: DINFO['trbs_smoke_id'] = TEMP[0]['id'] - print ("[WARN] MYSQL : Duplicate SMOKE, id = %(id)s, sr_name = %(sr_name)s" % TEMP[0]) + sql = makeUpdateSQL( table, VALUES, DINFO['trbs_smoke_id'] ) + print ("[INFO] MYSQL : Updated SMOKE, id = %(id)s, sr_name = %(sr_name)s" % TEMP[0]) else: + sql = makeInsertSQL( table, VALUES ) + print "[INFO] MYSQL : INSERT to", table - #pprint.pprint( CONFIG['RAW']['SMOKES'] ) - #exit() - VALUES = { - 'sr_status_id' : DINFO['sr_status_id'], - 'sr_name' : DINFO['sr'], - 'snapshot_num' : DINFO['snapshot_num'], - 'profile' : CONFIG['RAW']['TCT']['environment']['tct_profile'], - 'total' : CONFIG['RAW']['SMOKES']['COUNT']['total_case'], - 'pass' : CONFIG['RAW']['SMOKES']['COUNT']['pass_case'], - 'fail' : CONFIG['RAW']['SMOKES']['COUNT']['fail_case'], - 'pcnt' : round( (float(CONFIG['RAW']['SMOKES']['COUNT']['pass_case'])/float(CONFIG['RAW']['SMOKES']['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() - - table = "trbs_smoke" + try: + MYSQL['cursor'].execute( sql ) + MYSQL['connection'].commit() + except MySQLdb.Error, e: try: - sql = makeInsertSQL( table, VALUES ) - - #print sql - #exit() + 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() - print "[INFO] MYSQL : INSERT to", table - - 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['SMOKES']['select'], DINFO ) - TEMP = MYSQL['cursor'].fetchall() - - # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 - if len( TEMP ) > 0: - DINFO['trbs_smoke_id'] = TEMP[0]['id'] - print ("[INFO] MYSQL : SMOKE id = %(id)s" % TEMP[0]) - else: - print "[ERROR] MYSQL : Can not process SMOKE" - exit(1) + MYSQL['cursor'].execute( SQL['SMOKES']['select'], DINFO ) + TEMP = MYSQL['cursor'].fetchall() + # 결과가 1개 이거나 아니면 latest 결과가 정답일 것이라 전제 + if len( TEMP ) > 0: + DINFO['trbs_smoke_id'] = TEMP[0]['id'] + print ("[INFO] MYSQL : SMOKE id = %(id)s" % TEMP[0]) + else: + print "[ERROR] MYSQL : Can not process SMOKE" + exit(1) #pprint.pprint( CONFIG['RAW']['SMOKES'] ) #exit() - for suite in CONFIG['RAW']['SMOKES']['SUITE'].keys(): - #pprint.pprint( CONFIG['RAW']['SMOKES']['SUITE'][suite] ) - #pprint.pprint( DINFO ) - #exit() + + for suite in CONFIG['RAW']['SMOKES']['SUITE'].keys(): VALUES = { 'trbs_smoke_id' : DINFO['trbs_smoke_id'], @@ -552,53 +467,51 @@ if __name__ == "__main__": 'fail' : CONFIG['RAW']['SMOKES']['SUITE'][suite]['COUNT']['fail_case'], } - #pprint.pprint( VALUES ) - #exit() - SQL['SMOKES']['select_suite'] = ( "SELECT * " "FROM trbs_smoke_suite " "WHERE trbs_smoke_id = %(trbs_smoke_id)s AND name = %(name)s" ) + MYSQL['cursor'].execute( SQL['SMOKES']['select_suite'], VALUES ) TEMP = MYSQL['cursor'].fetchall() + + table = "trbs_smoke_suite" + sql = "" + if len( TEMP ) > 0: DINFO['trbs_smoke_suite_id'] = TEMP[0]['id'] - print ("[WARN] MYSQL : Duplicate SMOKE Suite, id = %(id)s, name = %(name)s" % TEMP[0]) + sql = makeUpdateSQL( table, VALUES , DINFO['trbs_smoke_suite_id'] ) + print ("[INFO] MYSQL : Updated SMOKE Suite, id = %(id)s, name = %(name)s" % TEMP[0]) else: + sql = makeInsertSQL( table, VALUES ) + print "[INFO] MYSQL : INSERT to", table, ", trbs_smoke_id =", DINFO['trbs_smoke_id'], ", name =", suite + try: + #print sql + #exit() - table = "trbs_smoke_suite" + MYSQL['cursor'].execute( sql ) + MYSQL['connection'].commit() + except MySQLdb.Error, e: try: - sql = makeInsertSQL( table, VALUES ) - - #print sql - #exit() - - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() - - print "[INFO] MYSQL : INSERT to", table, ", trbs_smoke_id =", DINFO['trbs_smoke_id'], ", name =", suite - - 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) - + 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['SMOKES']['select_suite'], VALUES ) - TEMP = MYSQL['cursor'].fetchall() + # check + MYSQL['cursor'].execute( SQL['SMOKES']['select_suite'], VALUES ) + TEMP = MYSQL['cursor'].fetchall() - if len( TEMP ) == 0: - print "[ERROR] MYSQL : Can not process SMOKE Suite" - else: - DINFO['trbs_smoke_suite_id'] = TEMP[0]['id'] + if len( TEMP ) == 0: + print "[ERROR] MYSQL : Can not process SMOKE Suite" + else: + DINFO['trbs_smoke_suite_id'] = TEMP[0]['id'] for testcase in CONFIG['RAW']['SMOKES']['SUITE'][suite]['TESTCASE'].keys(): @@ -622,42 +535,29 @@ if __name__ == "__main__": MYSQL['cursor'].execute( SQL['SMOKES']['select_suite_test'], VALUES ) TEMP = MYSQL['cursor'].fetchall() - if len( TEMP ) > 0: - print ("[WARN] MYSQL : Duplicate SMOKE Suite Test, id = %(id)s, name = %(name)s" % TEMP[0]) - else: - - table = "trbs_smoke_suite_test" - - try: - sql = makeInsertSQL( table, VALUES ) - - #print sql - #exit() - - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() - - print "[INFO] MYSQL : INSERT to", table, ", trbs_smoke_suite_id =", DINFO['trbs_smoke_suite_id'], ", name =", testcase - - 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) - - - - - - - - - + table = "trbs_smoke_suite_test" + sql = "" + if len( TEMP ) > 0: + sql = makeUpdateSQL( table, VALUES , TEMP[0]['id'] ) + print ("[INFO] MYSQL : Updated SMOKE Suite Test, id = %(id)s, name = %(name)s" % TEMP[0]) + else: + sql = makeInsertSQL( table, VALUES ) + print "[INFO] MYSQL : INSERT to", table, ", trbs_smoke_suite_id =", DINFO['trbs_smoke_suite_id'], ", name =", testcase + try: + #print sql + #exit() + 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) @@ -672,68 +572,61 @@ if __name__ == "__main__": MYSQL['cursor'].execute( SQL['PERFS']['select'], DINFO ) TEMP = MYSQL['cursor'].fetchall() + + 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'] - print ("[WARN] MYSQL : Duplicate PERF, id = %(id)s, sr_name = %(sr_name)s" % TEMP[0]) + 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 - #pprint.pprint( CONFIG['RAW']['PERFS'] ) - #exit() + try: + MYSQL['cursor'].execute( sql ) + MYSQL['connection'].commit() - 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'] - } - - #pprint.pprint( VALUES ) - #exit() - - table = "trbs_perf" + except MySQLdb.Error, e: try: - sql = makeInsertSQL( table, VALUES ) + print "[ERROR] MYSQL : [%d]: %s (%s)" % (e.args[0], e.args[1], sql) + except IndexError: + print "[ERROR] MYSQL : %s (%s)" % (str(e), sql) - #print sql - #exit() - - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() - - print "[INFO] MYSQL : INSERT to", table - - 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() - 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) + # 결과가 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) @@ -766,41 +659,43 @@ if __name__ == "__main__": MYSQL['cursor'].execute( SQL['PERFS']['select_suite'], VALUES ) TEMP = MYSQL['cursor'].fetchall() + table = "trbs_perf_suite" + sql = "" + if len( TEMP ) > 0: DINFO['trbs_perf_suite_id'] = TEMP[0]['id'] - print ("[WARN] MYSQL : Duplicate PERF Suite, id = %(id)s, name = %(name)s" % TEMP[0]) + 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_id =", DINFO['trbs_perf_id'], ", name =", suite - table = "trbs_perf_suite" - - try: - sql = makeInsertSQL( table, VALUES ) - #print sql - #exit() + try: + #print sql + #exit() - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() + MYSQL['cursor'].execute( sql ) + MYSQL['connection'].commit() - print "[INFO] MYSQL : INSERT to", table, ", trbs_perf_id =", DINFO['trbs_perf_id'], ", name =", suite - 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) + MYSQL['cursor'].execute( SQL['PERFS']['select_suite'], VALUES ) + TEMP = MYSQL['cursor'].fetchall() - 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'] - 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(): @@ -829,29 +724,26 @@ if __name__ == "__main__": MYSQL['cursor'].execute( SQL['PERFS']['select_suite_test'], VALUES ) TEMP = MYSQL['cursor'].fetchall() + table = "trbs_perf_suite_test" + sql = "" + if len( TEMP ) > 0: - print ("[WARN] MYSQL : Duplicate PERF Suite Test, id = %(id)s, name = %(name)s" % 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 - table = "trbs_perf_suite_test" - - try: - sql = makeInsertSQL( table, VALUES ) - - #print sql - #exit() - - MYSQL['cursor'].execute( sql ) - MYSQL['connection'].commit() - - print "[INFO] MYSQL : INSERT to", table, ", trbs_perf_suite_id =", DINFO['trbs_perf_suite_id'], ", name =", testcase - 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) + 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) exit(0) -- 2.7.4