ADDED: Script for the new job trbs_test_result_receiver
authorJunghyun Kim <jh0822.kim@samsung.com>
Fri, 10 Feb 2017 04:05:47 +0000 (13:05 +0900)
committerSoonKyu Park <sk7.park@samsung.com>
Thu, 23 Feb 2017 08:35:19 +0000 (17:35 +0900)
Change-Id: I3022c0f9209f87b6be172f56813808f67122acdd
Signed-off-by: Junghyun Kim <jh0822.kim@samsung.com>
job_trbs_test_result_receiver.py [new file with mode: 0644]
packaging/jenkins-scripts.spec

diff --git a/job_trbs_test_result_receiver.py b/job_trbs_test_result_receiver.py
new file mode 100644 (file)
index 0000000..8b0937c
--- /dev/null
@@ -0,0 +1,326 @@
+#!/usr/bin/python
+#-*-coding:utf-8-*-
+
+import os
+import sys
+import shutil
+import subprocess
+import json
+import pprint
+import time
+import datetime
+import base64
+import MySQLdb
+import MySQLdb.cursors
+import re
+
+
+#class MySQLCursorDict(mysql.connector.cursor.MySQLCursor):
+    #def _row_to_python(self, rowdata, desc=None):
+        #row = super(MySQLCursorDict, self)._row_to_python(rowdata, desc)
+        #if row:
+            #return dict(zip(self.column_names, row))
+        #return None
+
+
+def unicode_to_str(obj):
+    """convert unicode object to str"""
+
+    if isinstance(obj, list):
+        return [unicode_to_str(element) for element in obj]
+    elif isinstance(obj, dict):
+        return {unicode_to_str(key) : unicode_to_str(value) for key, value \
+                in obj.iteritems()}
+    elif isinstance(obj, unicode):
+        return obj.encode('utf-8')
+    else:
+        return obj
+
+
+if __name__ == "__main__":
+
+
+    ITEM = {
+        'sr'           : '',
+        'num'          : '',
+        'config_mysql' : 'config_mysql2.json' }
+
+
+    RESULT = { 'raw'   : {} }
+
+
+    print '=====[BuildMonitor DB connecting...]=====\n'
+
+    # load config data
+    db_ip = os.getenv("BUILDMONITOR_IP")
+    db_user = os.getenv("BUILDMONITOR_USER")
+    db_pass = os.getenv("BUILDMONITOR_PASS")
+    db_name = os.getenv("BUILDMONITOR_NAME")
+    print '%s %s %s' % (db_ip, db_user, db_name)
+    #if not os.path.isfile( ITEM['config_mysql'] ):
+            #ITEM['config_mysql'] = "jenkins-scripts/" + ITEM['config_mysql']
+            #if not os.path.isfile( ITEM['config_mysql'] ):
+                #sys.exit("ERROR: %s was not found!" % ITEM['config_mysql'])
+#
+#
+    #f = open( ITEM['config_mysql'], 'r')
+    #mconfig = json.loads(f.read())
+    #f.close()
+
+
+
+
+    trbs_data = os.getenv('TRBS_DATA').replace(' ', '+')
+
+    if trbs_data:
+        RESULT['raw']['trbs_data'] = unicode_to_str(json.loads(base64.b64decode(trbs_data)))
+    else:
+        sys.exit( "Error: trbs_data is empty!" )
+
+    print RESULT['raw']['trbs_data']
+
+
+    ITEM['sr']  = RESULT['raw']['trbs_data']['info']['sr']
+    ITEM['num'] = RESULT['raw']['trbs_data']['info']['snapshot_num']
+
+
+
+    #dbcon = mysql.connector.connect( user=mconfig['user'], password=mconfig['password'], host=mconfig['host'], database=mconfig['database'] )
+    #dbcon = mysql.connector.connect( user=db_user, password=db_pass, host=db_ip, database=db_name )
+    dbcon = MySQLdb.connect(host=db_ip, user=db_user, passwd=db_pass, db=db_name, cursorclass=MySQLdb.cursors.DictCursor)
+    #query = dbcon.cursor(cursor_class=MySQLCursorDict)
+    #query = dbcon.cursor(dictionary=True)
+    query = dbcon.cursor()
+
+
+
+
+    # SR의 ID값 확인
+    select_sr = "SELECT * FROM sr_status WHERE sr = %s"
+    query.execute( select_sr, [ITEM['sr']] )
+    RESULT['raw']['sr_status'] = query.fetchall()
+
+    print RESULT['raw']['sr_status']
+
+    if len( RESULT['raw']['sr_status'] ) != 1:
+        sys.exit("ERROR: %s was not found in database(sr_status)!" % ITEM['sr'])
+
+    RESULT['sr_id'] = RESULT['raw']['sr_status'][0]['id']
+    print "sr_id is", RESULT['sr_id']
+
+
+
+
+    # build_project_id 값 확인
+    #select_sr_detail = ( "SELECT id, sr_status_id, pre_build_project_id, post_build_project_id, obs_request_no, obs_request_comment, obs_request_date, obs_request_status "
+                         #"FROM sr_status_detail "
+                         #"WHERE sr_status_id = %s "
+                         #"ORDER BY id DESC" )
+    select_sr_detail = ("SELECT bp.id "
+                        " FROM sr_status_detail ssd, build_project bp, info_project ip"
+                        " WHERE ssd.sr_status_id = %s "
+                        " AND ssd.trbs_build_project_id = bp.id"
+                        " AND bp.info_project_id = ip.id"
+                        " AND ip.project_name LIKE '%%:Mobile:ref:%%'"
+                       )
+
+    print select_sr_detail
+
+    query.execute( select_sr_detail, [RESULT['sr_id']] )
+    RESULT['raw']['sr_detail'] = query.fetchall()
+    print RESULT['raw']['sr_detail']
+
+
+
+    if len( RESULT['raw']['sr_detail'] ) < 1:
+        sys.exit("ERROR: %s was not found in database(sr_status_detail)!" % ITEM['sr'])
+
+    RESULT['build_project_id'] = RESULT['raw']['sr_detail'][0]['id']
+    print "build_project_id is", RESULT['build_project_id']
+
+
+
+
+
+    # snapshot 정보 확인
+    select_snapshot = ( "SELECT build_snapshot.id, snapshot_name, snapshot_num, snapshot_url, start_time, end_time, build_snapshot.status, info_project_id "
+                        "FROM build_snapshot "
+                        "LEFT JOIN build_project ON build_project.id = build_snapshot.build_project_id "
+                        "WHERE build_project_id = %s ORDER BY build_snapshot.id DESC" )
+
+
+    query.execute( select_snapshot, [RESULT['build_project_id']] )
+    temp = query.fetchall()
+    print temp
+
+    if len(temp) < 1:
+        sys.exit("ERROR: snapshot_num is empty!")
+
+    RESULT['raw']['snapshot'] = temp
+
+    RESULT['snapshot_num'] = RESULT['raw']['snapshot'][0]['snapshot_num']
+    print "snapshot_num is", RESULT['snapshot_num']
+
+
+
+    if ITEM['num'] != RESULT['snapshot_num']:
+        sys.exit("Error: snapshot_num different!!")
+
+
+
+
+
+
+    for key, value in RESULT['raw']['trbs_data'].items():
+
+        if key == 'trbs_tct':
+
+            insert_tct = ( "INSERT INTO trbs_tct "
+                           "( id, sr_status_id, ref_id, sr_name, snapshot_num, profile, plan_name, total, pass, fail, "
+                             "block, na, pcnt, time_start, time_end, build_id, device_id, device_model, device_name, "
+                             "device_host, manufacturer, tct_profile, tct_version, url) "
+                           "VALUES ( %(id)s, %(sr_status_id)s, %(ref_id)s, %(sr_name)s, %(snapshot_num)s, %(profile)s, %(plan_name)s, %(total)s, %(pass)s, %(fail)s, "
+                                    "%(block)s, %(na)s, %(pcnt)s, %(time_start)s, %(time_end)s, %(build_id)s, %(device_id)s, %(device_model)s, %(device_name)s, "
+                                    "%(device_host)s, %(manufacturer)s, %(tct_profile)s, %(tct_version)s, %(url)s )" )
+            try:
+                value['sr_status_id'] = RESULT['sr_id']
+
+                query.execute( insert_tct, value )
+                dbcon.commit()
+            except MySQLdb.IntegrityError:
+                print "[Error] Duplicate entry (" + key + ")-", value
+
+        elif key == 'trbs_tct_suite':
+
+            insert_tct_suite = ( "INSERT INTO trbs_tct_suite "
+                                 "( id, trbs_tct_id, name, total, pass, pass_rate, fail, fail_rate, block, block_rate, na, na_rate ) "
+                                 "VALUES ( %(id)s, %(trbs_tct_id)s, %(name)s, %(total)s, %(pass)s, %(pass_rate)s, %(fail)s, %(fail_rate)s, %(block)s, %(block_rate)s, %(na)s, %(na_rate)s )" )
+
+            for temp in value:
+
+                try:
+                    query.execute( insert_tct_suite, temp )
+                    dbcon.commit()
+                except MySQLdb.IntegrityError:
+                    print "[Error] Duplicate entry (" + key + ")-", value
+
+
+        elif key == 'trbs_ref':
+
+            insert_ref = ( "INSERT INTO trbs_ref "
+                           "( id, plan_name, total, pass, fail, block, na, pcnt, time_start, time_end, build_id, device_id, "
+                             "device_model, device_name, device_host, manufacturer, tct_profile, tct_version, url ) "
+                           "VALUES( %(id)s, %(plan_name)s, %(total)s, %(pass)s, %(fail)s, %(block)s, %(na)s, %(pcnt)s, %(time_start)s, %(time_end)s, %(build_id)s, %(device_id)s, "
+                                   "%(device_model)s, %(device_name)s, %(device_host)s, %(manufacturer)s, %(tct_profile)s, %(tct_version)s, %(url)s )" )
+
+            try:
+                query.execute( insert_ref, value )
+                dbcon.commit()
+            except MySQLdb.IntegrityError:
+                print "[Error] Duplicate entry (" + key + ")-", value
+
+
+        elif key == 'trbs_ref_suite':
+
+
+            insert_ref_suite = ( "INSERT INTO trbs_ref_suite "
+                                 "( id, trbs_ref_id, name, total, pass, pass_rate, fail, fail_rate, block, block_rate, na, na_rate ) "
+                                 "VALUES ( %(id)s, %(trbs_ref_id)s, %(name)s, %(total)s, %(pass)s, %(pass_rate)s, %(fail)s, %(fail_rate)s, %(block)s, %(block_rate)s, %(na)s, %(na_rate)s )" )
+
+            for temp in value:
+                try:
+                    query.execute( insert_ref_suite, temp )
+                    dbcon.commit()
+                except MySQLdb.IntegrityError:
+                    print "[Error] Duplicate entry (" + key + ")-", value
+
+
+        elif key == 'trbs_smoke':
+
+            insert_smoke = ( "INSERT INTO trbs_smoke "
+                             "( id, sr_status_id, sr_name, snapshot_num, profile, pass, fail, total, pcnt, url, time_start, time_end ) "
+                             "VALUES ( %(id)s, %(sr_status_id)s, %(sr_name)s, %(snapshot_num)s, %(profile)s, %(pass)s, %(fail)s, %(total)s, %(pcnt)s, %(url)s, %(time_start)s, %(time_end)s ) " )
+
+            try:
+                value['sr_status_id'] = RESULT['sr_id']
+
+                query.execute( insert_smoke, value )
+                dbcon.commit()
+            except MySQLdb.IntegrityError:
+                print "[Error] Duplicate entry (" + key + ")-", value
+
+
+        elif key == 'trbs_smoke_suite':
+
+            insert_smoke_suite = ( "INSERT INTO trbs_smoke_suite "
+                                   "( id, trbs_smoke_id, name, pass, fail ) "
+                                   "VALUES( %(id)s, %(trbs_smoke_id)s, %(name)s, %(pass)s, %(fail)s )" )
+
+            for temp in value:
+                try:
+                    query.execute( insert_smoke_suite, temp )
+                    dbcon.commit()
+                except MySQLdb.IntegrityError:
+                    print "[Error] Duplicate entry (" + key + ")-", value
+
+
+        elif key == 'trbs_perf':
+
+            insert_perf = ( "INSERT INTO trbs_perf "
+                            "( id, sr_status_id, sr_name, snapshot_num, profile, device_core, device_dvfs, device_freq, device_kernel, "
+                              "device_platform, total, pass, fail, pcnt, time_start, time_end, url ) "
+                            "VALUES ( %(id)s, %(sr_status_id)s, %(sr_name)s, %(snapshot_num)s, %(profile)s, %(device_core)s, %(device_dvfs)s, %(device_freq)s, %(device_kernel)s, "
+                                     "%(device_platform)s, %(total)s, %(pass)s, %(fail)s, %(pcnt)s, %(time_start)s, %(time_end)s, %(url)s )" )
+
+            try:
+                value['sr_status_id'] = RESULT['sr_id']
+
+                query.execute( insert_perf, value )
+                dbcon.commit()
+            except MySQLdb.IntegrityError:
+                print "[Error] Duplicate entry (" + key + ")-", value
+
+
+        elif key == 'trbs_perf_suite':
+
+            insert_perf_suite = ( "INSERT INTO trbs_perf_suite "
+                                  "( id, trbs_perf_id, name, total, pass, fail ) "
+                                  "VALUES ( %(id)s, %(trbs_perf_id)s, %(name)s, %(total)s, %(pass)s, %(fail)s )" )
+
+            for temp in value:
+                try:
+                    query.execute( insert_perf_suite, temp )
+                    dbcon.commit()
+                except MySQLdb.IntegrityError:
+                    print "[Error] Duplicate entry (" + key + ")-", value
+
+
+        elif key == 'trbs_perf_suite_test':
+
+            insert_perf_suite_test = ( "INSERT INTO trbs_perf_suite_test "
+                                       "( `id`, `trbs_perf_suite_id`, `name`, `actualperf`, `expectedperf`, `range`, `result`, `criteria`, `unit` ) "
+                                       "VALUES ( %(id)s, %(trbs_perf_suite_id)s, %(name)s, %(actualperf)s, %(expectedperf)s, %(range)s, %(result)s, %(criteria)s, %(unit)s )" )
+
+            for temp in value:
+                try:
+                    query.execute( insert_perf_suite_test, temp )
+                    dbcon.commit()
+                except MySQLdb.IntegrityError:
+                    print "[Error] Duplicate entry (" + key + ")-", value
+
+
+        else:
+
+            if key == 'info':
+                pass
+            else:
+                print "[Error] wrong data (", key, ") -", value
+
+
+
+    query.close()
+    dbcon.close()
+
+
+    exit()
index 3245c26..69d845c 100644 (file)
@@ -139,6 +139,7 @@ fi
 %{destdir}/job_update_nuget.py
 %{destdir}/job_add_git_tag.py
 %{destdir}/job_repa.py
+%{destdir}/job_trbs_test_result_receiver.py
 %dir %{destdir}/templates
 %{destdir}/templates/index.html
 %{destdir}/job_update_local_git.py