[BuildMonitor] Add to set the stage_status as 'S' at the 'Base' snapshot stage 82/119482/5
authorSungHun Hwang <sh0924.hwang@samsung.com>
Fri, 17 Mar 2017 05:39:34 +0000 (14:39 +0900)
committerSungHun Hwang <sh0924.hwang@samsung.com>
Tue, 21 Mar 2017 02:15:44 +0000 (11:15 +0900)
1. [job_buildmonitor.py]
  Set the stage_status(PRE_SNAP & PRE_IMAGE / POST_SNAP & POST_IMAGE)
  as 'S(uccedded)' at the snapshot stage of 'Base' project

  << Modified functions >>
  1-1. Pre release part
    update_fail_status_for_sr_stage(...)
    end_pre_create_snapshot_for_sr_stage(...)

  1-2. Post release part (need 'multi_sr_status_id')
    update_fail_create_snapshot_for_sr_stage(...)
    end_create_snapshot_create_images_for_sr_stage(...)

2. [job_create_snapshot.py]
  2-1. Add to Skip [BUILD-MONITOR_Post_Image] if Base project
  2-2. Remove the legacy code ('buildmonibor_skip')

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

index 7bc6ab4..7ba7ecc 100644 (file)
@@ -324,18 +324,35 @@ def update_fail_status_for_sr_stage(project, bm_git_tag):
     curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
 
     # Skip updating the fail status if Base project
-    if 'Base' in project:
+    if 'base' in project.lower():
         sr_stage_status = 'S'
-        print '[%s] This is [Base] project!! skip updating the fail status\n' % (__file__)
+
+        ### [PRE_SNAP] stage end : update 'S' status
+        info_stage_id = PRE_SNAP
+        query = "UPDATE sr_stage SET stage_end_time = NOW(), stage_status = %s " \
+                "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (sr_stage_status, curr_sr_status_id, info_stage_id, curr_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+        ### [PRE_IMAGE] stage end : insert 'S' status
+        info_stage_id = PRE_IMAGE
+        query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
+                "stage_end_time, stage_status, build_project_id) " \
+                "VALUES(%s, %s, NOW(), NOW(), %s, %s)"
+        query_data = (curr_sr_status_id, info_stage_id,
+                      sr_stage_status, curr_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
+
+        print '[%s] This is [Base] project!! All stages are done\n' % (__file__)
     else:
         sr_stage_status = 'F'
 
-    ### [PRE_SNAP] stage end : update fail status [pre] snapshot creation
-    info_stage_id = PRE_SNAP
-    query = "UPDATE sr_stage SET stage_status = %s WHERE sr_status_id = %s " \
-            "AND info_stage_id = %s AND build_project_id = %s"
-    query_data = (sr_stage_status, curr_sr_status_id, info_stage_id, curr_build_project_id)
-    buildmonitor_db.do_query(query, query_data)
+        ### [PRE_SNAP] stage end : update 'F' status
+        info_stage_id = PRE_SNAP
+        query = "UPDATE sr_stage SET stage_end_time = NOW(), stage_status = %s " \
+                "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+        query_data = (sr_stage_status, curr_sr_status_id, info_stage_id, curr_build_project_id)
+        buildmonitor_db.do_query(query, query_data)
 
 def start_pre_create_snapshot_for_sr_stage(project, bm_git_tag, bm_start_datetime, bBuildFail):
     print '[%s] enter start_pre_create_snapshot_for_sr_stage\n' % (__file__)
@@ -498,19 +515,28 @@ def end_pre_create_snapshot_for_sr_stage(project, bm_git_tag,
     curr_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
 
     ### [PRE_SNAP] stage end : [pre] snapshot creation
+    sr_stage_status = 'S'
     info_stage_id = PRE_SNAP
     query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
             "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
-    query_data = (bm_end_datetime, 'S', curr_sr_status_id,
+    query_data = (bm_end_datetime, sr_stage_status, curr_sr_status_id,
                   info_stage_id, curr_build_project_id)
     buildmonitor_db.do_query(query, query_data)
 
-    ### [PRE_IMAGE] stage start : [pre] image creation
+    if 'base' in project.lower():
+        ### [PRE_IMAGE] stage end : [pre] image creation
+        sr_stage_status = 'S'
+        print '[%s] This is [Base] project!! sr_stage_status(%s)\n' \
+              % (__file__, sr_stage_status)
+    else:
+        ### [PRE_IMAGE] stage start : [pre] image creation
+        sr_stage_status = 'R'
+
     info_stage_id = PRE_IMAGE
     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_end_datetime,
-                  'R', curr_build_project_id)
+                  sr_stage_status, curr_build_project_id)
     buildmonitor_db.do_query(query, query_data)
 
 def end_pre_create_snapshot_for_build_snapshot(project, bm_snapshot_name,
@@ -953,20 +979,49 @@ def update_fail_create_snapshot_for_sr_stage(bm_snapshot_name):
     post_build_project_id = buildmonitor_db.get_value_from_query_data(query, query_data)
     print '[%s] post_build_project_id(%s)\n' % (__file__, post_build_project_id)
 
-    # get curr_sr_status_id
+    # get multi_sr_status_id
     query = "SELECT sr_status_id FROM sr_status_detail WHERE post_build_project_id = %s"
     query_data = (post_build_project_id,)
-    curr_sr_status_id = buildmonitor_db.get_value_from_query_data(query, query_data)
-    #print '[%s] curr_sr_status_id(%s)\n' \
-    #      % (__file__, curr_sr_status_id)
-
-    ### [7] stage : update fail status when failed
-    bm_start_datetime = bm_end_datetime = datetime.datetime.now()
-    query = "UPDATE sr_stage SET stage_start_time = %s, stage_end_time = %s, stage_status = %s " \
-            "WHERE sr_status_id = %s AND build_project_id = %s"
-    query_data = (bm_start_datetime, bm_end_datetime, 'F',
-                  curr_sr_status_id, post_build_project_id)
-    buildmonitor_db.do_query(query, query_data)
+    multi_sr_status_id = buildmonitor_db.get_multi_values_from_query_data(query, query_data)
+    #print '[%s] multi_sr_status_id(%s)\n' \
+    #      % (__file__, multi_sr_status_id)
+
+    # Skip updating the fail status if Base project
+    if 'base' in bm_snapshot_name.lower():
+        sr_stage_status = 'S'
+
+        for each_sr_status_id in multi_sr_status_id:
+            print '[%s] each_sr_status_id(%s)\n' % (__file__, each_sr_status_id)
+
+            ### [POST_SNAP] stage end : update 'S' status
+            info_stage_id = POST_SNAP
+            query = "UPDATE sr_stage SET stage_end_time = NOW(), stage_status = %s " \
+                    "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+            query_data = (sr_stage_status, each_sr_status_id[0], info_stage_id, post_build_project_id)
+            buildmonitor_db.do_query(query, query_data)
+
+            ### [POST_IMAGE] stage end : insert 'S' status
+            info_stage_id = POST_IMAGE
+            query = "INSERT INTO sr_stage (sr_status_id, info_stage_id, stage_start_time, " \
+                    "stage_end_time, stage_status, build_project_id) " \
+                    "VALUES(%s, %s, NOW(), NOW(), %s, %s)"
+            query_data = (each_sr_status_id[0], info_stage_id, sr_stage_status, post_build_project_id)
+            buildmonitor_db.do_query(query, query_data)
+
+            print '[%s] This is [Base] project!! All stages are done\n' % (__file__)
+
+    else:
+        sr_stage_status = 'F'
+
+        for each_sr_status_id in multi_sr_status_id:
+            print '[%s] each_sr_status_id(%s)\n' % (__file__, each_sr_status_id)
+
+            ### [POST_SNAP] stage end : update 'F' status
+            info_stage_id = POST_SNAP
+            query = "UPDATE sr_stage SET stage_end_time = NOW(), stage_status = %s " \
+                    "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
+            query_data = (sr_stage_status, each_sr_status_id[0], info_stage_id, post_build_project_id)
+            buildmonitor_db.do_query(query, query_data)
 
 def start_create_snapshot_for_sr_stage(project, bm_start_datetime):
     print '[%s] enter start_create_snapshot_for_sr_stage\n' % (__file__)
@@ -1137,18 +1192,27 @@ def end_create_snapshot_create_images_for_sr_stage(bm_snapshot_name,
     for each_sr_status_id in multi_sr_status_id:
         print '[%s] each_sr_status_id(%s)\n' % (__file__, each_sr_status_id)
 
-        # change the state_status of previous stage from 'R' to 'S'
+        ### [POST_SNAP] stage end : update 'S' status
+        sr_stage_status = 'S'
         info_stage_id = POST_SNAP
         query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
                 "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
-        query_data = (bm_end_datetime, 'S',
+        query_data = (bm_end_datetime, sr_stage_status,
                       each_sr_status_id[0], info_stage_id, post_build_project_id)
         buildmonitor_db.do_query(query, query_data)
 
+        ### [POST_IMAGE] stage end : update 'S' or 'R' status
+        if 'base' in bm_snapshot_name.lower():
+            sr_stage_status = 'S'
+            print '[%s] This is [Base] project!! sr_stage_status(%s)\n' \
+                  % (__file__, sr_stage_status)
+        else:
+            sr_stage_status = 'R'
+
         info_stage_id = POST_IMAGE
         query = "UPDATE sr_stage SET stage_end_time = %s, stage_status = %s " \
                 "WHERE sr_status_id = %s AND info_stage_id = %s AND build_project_id = %s"
-        query_data = (bm_end_datetime, 'R',
+        query_data = (bm_end_datetime, sr_stage_status,
                       each_sr_status_id[0], info_stage_id, post_build_project_id)
         buildmonitor_db.do_query(query, query_data)
 
@@ -1906,10 +1970,6 @@ def main():
         bm_snapshot_url = content.get("bm_snapshot_url")
         bm_snapshot_num = content.get("bm_snapshot_num")
 
-        # Skip [Pre_Snap_End] if Base project
-        if 'Base' in project:
-            print '[%s] This is [Base] project!! skip [Pre_Snap_End]\n' % (__file__)
-            return
 
         # func call
         if bm_stage == 'Pre_Snap_End':
index e680a94..33df42d 100755 (executable)
@@ -273,7 +273,6 @@ def main():
     buildmonitor_enabled = os.getenv("BUILDMONITOR_ENABLED", "0") != "0"
     print 'buildmonitor_enabled(%s)\n' % (buildmonitor_enabled)
     if buildmonitor_enabled:
-        buildmonitor_skip = 1 # for exception case
         global bm_start_datetime
         bm_start_datetime = datetime.datetime.now()
 
@@ -324,13 +323,6 @@ def main():
 
     # trigger snapdiff sync
     for index, repo in enumerate(trigger_snapdiff.keys()):
-        if buildmonitor_enabled:
-            # if there is one data at least then do not skip
-            if trigger_snapdiff[repo] != []:
-                buildmonitor_skip = 0
-                print '[%s] repo(%s), trigger_snapdiff[repo](%s)\n' \
-                      % (__file__, repo, trigger_snapdiff[repo])
-
         trigger_next('snapdiff-trigger_%s' %
                       index, {repo: trigger_snapdiff[repo]})
 
@@ -346,29 +338,30 @@ def main():
         trigger_next("update-nuget", data)
 
     if buildmonitor_enabled:
-        if buildmonitor_skip == 1:
-            print 'snapdiff empty, buildmonitor_skipped!!\n'
-        else:
-            bm_end_datetime = datetime.datetime.now()
-            # for sr_stage & build_snapshot
-            #buildmonitor.end_create_snapshot_create_images_for_sr_stage(project,
-            #                                                            bm_start_datetime,
-            #                                                            bm_end_datetime)
-            bm_snapshot_url = os.path.join(base_url, repo_data['repo_path'])
-            #buildmonitor.end_create_snapshot_for_post_build_snapshot(project,
-            #                                                         bm_start_datetime,
-            #                                                         bm_end_datetime,
-            #                                                         bm_snapshot_url,
-            #                                                         repo_data['build_id'])
-            bm_stage = 'Post_Snap_End'
-            bm_data = {"bm_stage" : bm_stage,
-                       "bm_start_datetime" : str(bm_start_datetime),
-                       "bm_end_datetime" : str(bm_end_datetime),
-                       "bm_snapshot_url" : bm_snapshot_url,
-                       "bm_snapshot_name" : repo_data['build_id']
-                      }
-            trigger_next("BUILD-MONITOR-4-%s" % bm_stage, bm_data)
+        bm_end_datetime = datetime.datetime.now()
+        # for sr_stage & build_snapshot
+        #buildmonitor.end_create_snapshot_create_images_for_sr_stage(project,
+        #                                                            bm_start_datetime,
+        #                                                            bm_end_datetime)
+        bm_snapshot_url = os.path.join(base_url, repo_data['repo_path'])
+        #buildmonitor.end_create_snapshot_for_post_build_snapshot(project,
+        #                                                         bm_start_datetime,
+        #                                                         bm_end_datetime,
+        #                                                         bm_snapshot_url,
+        #                                                         repo_data['build_id'])
+        bm_stage = 'Post_Snap_End'
+        bm_data = {"bm_stage" : bm_stage,
+                   "bm_start_datetime" : str(bm_start_datetime),
+                   "bm_end_datetime" : str(bm_end_datetime),
+                   "bm_snapshot_url" : bm_snapshot_url,
+                   "bm_snapshot_name" : repo_data['build_id']
+                  }
+        trigger_next("BUILD-MONITOR-4-%s" % bm_stage, bm_data)
 
+        # Skip [BUILD-MONITOR_Post_Image] if Base project
+        if 'base' in project.lower():
+            print '[%s] This is [Base] project!! skip Post_Image \n' % (__file__)
+        else:
             # To check the completion of image-creation stage at Post-release
             #buildmonitor.end_create_image_for_sr_stage(bm_start_datetime,
             #                                           project)