[BuildMonitor] sync up with job_buildmonitor.py of TRBS 91/103691/1
authorSungHun Hwang <sh0924.hwang@samsung.com>
Fri, 9 Dec 2016 06:58:20 +0000 (15:58 +0900)
committerSungHun Hwang <sh0924.hwang@samsung.com>
Fri, 9 Dec 2016 07:02:04 +0000 (16:02 +0900)
1. change the build fail check method from build_target status to build_project status
2. disable old check method (if stable then remove this)
3. clear the previous tables when entering the duplicated build_snapshot_id
4. when build failed in [Snap] stage, skip the next step in [BUILD-MONITOR] jobs
5. when build image failed write to 'F' status of build_image table
6. some bugfixes & remove useless log

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

index 0f5aa40..649095d 100644 (file)
@@ -189,7 +189,7 @@ def package_build_for_sr_detail_sr_stage(git_tag, bm_start_datetime,
 
         ###================== [16_1110][TEMP] build_project
         if pre_build_project_id == 9876:
-            print '[%s][HSH] cannot find build_project_id!! Adding NOW!!\n' % (__file__)
+            print '[%s] cannot find build_project_id!! Adding NOW!!\n' % (__file__)
             query = "INSERT INTO build_project (info_project_id, status) VALUES(%s, %s)"
             query_data = (info_project_id, 'C')
             buildmonitor_db.do_query(query, query_data)
@@ -301,6 +301,9 @@ def start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetim
     query_data = (curr_info_project_id,)
     curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
 
+    # [16_1206] if change the build fail check method, disable
+    '''
+    # << 1st >>
     # get multi_build_status from build_target
     query = "SELECT status FROM build_target WHERE build_project_id = %s " \
             "AND last_flag = %s"
@@ -314,7 +317,21 @@ def start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetim
         #print '[%s] each_build_status(%s)\n' % (__file__, each_build_status)
         if each_build_status[0] == 'F':
             info_stage_status = 'F'
-            print '[%s] failed!! info_stage_status(%s)\n' % (__file__, info_stage_status)
+            #print '[%s] failed!! info_stage_status(%s)\n' % (__file__, info_stage_status)
+    '''
+
+    # << 2nd >>
+    # get curr_build_project_status
+    query = "SELECT status FROM build_project WHERE info_project_id = %s"
+    query_data = (curr_info_project_id,)
+    curr_build_project_status = buildmonitor_db.get_value_from_query_data(query, query_data)
+    print '[%s] curr_build_project_status(%s)\n' % (__file__, curr_build_project_status)
+
+    # [16_1208] change the build fail check method from build_target status to build_project status
+    if curr_build_project_status == 'F':
+        info_stage_status = 'F'
+    else:
+        info_stage_status = 'S'
 
     ### [2] stage end : [pre] package build
     info_stage_id = 2
@@ -325,15 +342,20 @@ def start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetim
                   info_stage_id, curr_build_project_id)
     buildmonitor_db.do_query(query, query_data)
 
-    ### [3] stage start : [pre] snapshot creation
-    info_stage_id = 3
-    query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
-            "stage_status, build_project_id) VALUES(%s, %s, %s, %s, %s)"
-    query_data = (curr_sr_status_id, info_stage_id,
-                  bm_start_datetime, 'R', curr_build_project_id)
-    buildmonitor_db.do_query(query, query_data)
+    if info_stage_status == 'S':
+        ### [3] stage start : [pre] snapshot creation
+        info_stage_id = 3
+        query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
+                "stage_status, build_project_id) VALUES(%s, %s, %s, %s, %s)"
+        query_data = (curr_sr_status_id, info_stage_id,
+                      bm_start_datetime, 'R', curr_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+    else:
+        print '[%s] Build failed!! skip [3] stage start\n' \
+              % (__file__)
 
-def start_pre_create_snapshot_for_build_snapshot(project, bm_start_datetime):
+#def start_pre_create_snapshot_for_build_snapshot(project, bm_start_datetime):
+def start_pre_create_snapshot_for_build_snapshot(project, bm_git_tag, bm_start_datetime):
     print '[%s] enter start_pre_create_snapshot_for_build_snapshot\n' % (__file__)
 
     # get pre_info_project_id -> get pre_build_project_id
@@ -357,13 +379,49 @@ def start_pre_create_snapshot_for_build_snapshot(project, bm_start_datetime):
         query_data = (pre_build_project_id, bm_start_datetime, 'R')
         buildmonitor_db.do_query(query, query_data)
     else:
-        print '[%s] duplicated build_snapshot_id!! skip insert\n' % (__file__)
+        print '[%s] duplicated build_snapshot_id!! skip insert & clear tables\n' \
+              % (__file__)
+
+        ### clear build_snapshot_package & build_image tables
+        query = "DELETE FROM build_snapshot_package WHERE build_snapshot_id = %s"
+        query_data = (pre_build_snapshot_id,)
+        buildmonitor_db.do_query(query, query_data)
+        query = "DELETE FROM build_image WHERE build_snapshot_id = %s"
+        query_data = (pre_build_snapshot_id,)
+        buildmonitor_db.do_query(query, query_data)
+
+        # get curr_sr_status_id
+        query = "SELECT id FROM sr_status WHERE sr = %s"
+        query_data = (bm_git_tag,)
+        curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+        ### [3] stage remove : [pre] snapshot creation
+        info_stage_id = 3
+        query = "DELETE FROM sr_stage WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (curr_sr_status_id, info_stage_id, pre_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+        ### [4] stage remove : [pre] image creation
+        info_stage_id = 4
+        query = "DELETE FROM sr_stage WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (curr_sr_status_id, info_stage_id, pre_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+        ### [3] stage restart : [pre] snapshot creation
+        info_stage_id = 3
+        query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
+                "stage_status, build_project_id) VALUES(%s, %s, %s, %s, %s)"
+        query_data = (curr_sr_status_id, info_stage_id,
+                      bm_start_datetime, 'R', pre_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
 
 def create_snapshot_packages_for_build_snapshot_package(project, bm_repo, bm_arch,
                                                         bm_pkg_url,
                                                         bm_pkg_name_lst,
                                                         bm_pkg_mdate_lst,
-                                                        bm_pkg_size_lst):
+                                                        bm_pkg_size_lst,
+                                                        bm_trg_count,
+                                                        bm_pkg_count,
+                                                        BM_PKG_LIMIT):
     print '[%s] enter create_snapshot_packages_for_build_snapshot_package\n' % (__file__)
 
     # get pre_info_project_id -> get pre_build_project_id
@@ -465,6 +523,8 @@ def update_fail_create_image_for_sr_stage(fields, bm_start_datetime):
     #      % (__file__, bm_prj_name, bm_split_data, bm_git_tag, bm_url)
 
     bm_end_datetime = datetime.datetime.now()
+    bm_repo = fields["repo"]
+    bm_device_name = fields["name"]
 
     #if 'prerelease' in bm_url:
     #if not ((bm_url.find("prerelease")) == -1):
@@ -491,6 +551,19 @@ def update_fail_create_image_for_sr_stage(fields, bm_start_datetime):
         query_data = (bm_start_datetime, bm_end_datetime, 'F',
                       curr_sr_status_id, info_stage_id, curr_build_project_id)
         buildmonitor_db.do_query(query, query_data)
+
+        ### build_image : update fail status for [pre] image creation
+        # get pre_build_snapshot_id
+        query = "SELECT id FROM build_project WHERE info_project_id = %s"
+        query_data = (curr_info_project_id,)
+        pre_build_snapshot_id = buildmonitor_db.get_value_from_query_data(query, query_data)
+
+        # update fail status
+        query = "UPDATE build_image SET end_time = %s, status = %s " \
+                "WHERE build_snapshot_id = %s AND repository = %s AND device_name = %s"
+        query_data = (bm_end_datetime, 'F',
+                      pre_build_snapshot_id, bm_repo, bm_device_name)
+        buildmonitor_db.do_query(query, query_data)
     else:
         # get post_info_project_id -> get post_build_project_id
         query = "SELECT id FROM info_project WHERE project_name = %s"
@@ -994,9 +1067,17 @@ def main():
         project = content.get("project")
         bm_git_tag = content.get("bm_git_tag")
         bm_start_datetime = content.get("bm_start_datetime")
+        bBuildFail = content.get("bBuildFail")
         # func call
-        start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetime) # move to job_dispacher
-        start_pre_create_snapshot_for_build_snapshot(project, bm_start_datetime)
+        start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetime)
+
+        # if bBuildFail is True then skip Creating images
+        if bBuildFail != True:
+            start_pre_create_snapshot_for_build_snapshot(project, bm_git_tag, bm_start_datetime)
+        else:
+            print '[%s] Build failed!! skip insert build_snapshot_id\n' \
+                  % (__file__)
+
     elif bm_stage == 'Pre_Snap_End':
         print '[%s][Pre_Snap_End]\n' % (__file__)
         # get vars
@@ -1028,12 +1109,18 @@ def main():
         bm_pkg_name_lst = content.get("bm_pkg_name_lst")
         bm_pkg_mdate_lst = content.get("bm_pkg_mdate_lst")
         bm_pkg_size_lst = content.get("bm_pkg_size_lst")
+        bm_trg_count = content.get("bm_trg_count ")
+        bm_pkg_count = content.get("bm_pkg_count")
+        BM_PKG_LIMIT = content.get("BM_PKG_LIMIT ")
         # func call
         create_snapshot_packages_for_build_snapshot_package(project, bm_repo, bm_arch,
                                                             bm_pkg_url,
                                                             bm_pkg_name_lst,
                                                             bm_pkg_mdate_lst,
-                                                            bm_pkg_size_lst)
+                                                            bm_pkg_size_lst,
+                                                            bm_trg_count,
+                                                            bm_pkg_count,
+                                                            BM_PKG_LIMIT)
 
     elif bm_stage == 'Pre_Snap_Fail':
         print '[%s][Pre_Snap_Fail]\n' % (__file__)
@@ -1043,7 +1130,7 @@ def main():
         # func call
         update_fail_status_for_sr_stage(project, bm_git_tag)
     #=======================================================
-    # [PRE][POST] Image
+    # [PRE]/[POST] Image
     elif bm_stage == 'Image':
         print '[%s][Image]\n' % (__file__)
         # get vars
@@ -1053,7 +1140,7 @@ def main():
         bm_end_datetime = content.get("bm_end_datetime")
         build_id = content.get("build_id")
         bm_img_size = content.get("bm_img_size")
-        #print '[HSH][%s] fields(%s), bm_start_datetime(%s), build_id(%s)\n' \
+        #print '[%s] fields(%s), bm_start_datetime(%s), build_id(%s)\n' \
         #      % (__file__, fields, bm_start_datetime, build_id)
 
         # func call
@@ -1063,7 +1150,7 @@ def main():
         elif image_status == 'failed':
             update_fail_create_image_for_sr_stage(fields, bm_start_datetime)
     #=======================================================
-    # [PRE][POST] Post_Image
+    # [PRE]/[POST] Post_Image
     elif bm_stage == 'Post_Image':
         print '[%s][Post_Image]\n' % (__file__)
         # get vars
@@ -1071,6 +1158,7 @@ def main():
         project = content.get("project")
         # func call
         end_create_image_for_sr_stage(bm_start_datetime, project)
+    #=======================================================
     # SR Accept or Reject
     elif bm_stage == 'SR_Accept':
         print '[%s][SR_Accept]\n' % (__file__)
@@ -1146,7 +1234,7 @@ def main():
         # func call
         update_fail_create_snapshot_for_sr_stage(bm_project)
     #=======================================================
-    # [POST] Image / Post_Image
+    # [POST] Image / Post_Image => N/A
     #=======================================================
     #else:
     #    print 'no bm_stage\n'