TPE-486 Duplicated check into db 72/163472/3
authorhyokeun <hyokeun.jeon@samsung.com>
Mon, 11 Dec 2017 10:50:26 +0000 (19:50 +0900)
committerhyokeun <hyokeun.jeon@samsung.com>
Mon, 11 Dec 2017 23:59:30 +0000 (08:59 +0900)
Change-Id: I2575cf8365abea651e7d2a6d32c01b5a8e79e001

job_buildmonitor.py
job_create_snapshot.py

index cd491fc..775efd2 100644 (file)
@@ -1360,6 +1360,37 @@ def end_create_snapshot_for_post_build_snapshot(bm_end_datetime,
     query_data = (bm_snapshot_url, bm_end_datetime, 'S', bm_snapshot_name)
     buildmonitor_db.do_query(query, query_data)
 
+def update_duplicated_package_warning(bm_snapshot_name, duplicated):
+
+    if duplicated is not None and len(duplicated) > 0:
+        # Add git repository
+        for git_repo in duplicated:
+            query = "INSERT INTO git_repository (name) VALUES (%s)"
+            buildmonitor_db.do_query(query, (git_repo, ))
+
+        git_repo_str = "%s" % "','".join(duplicated)
+        param_count_str = ','.join(["%s"] * len(duplicated))
+        query = "SELECT id FROM git_repository WHERE name IN (%s)" % param_count_str
+        query_data = set(duplicated)
+        rows = buildmonitor_db.get_multi_values_from_query_data(query, query_data)
+        if rows == 0:
+            return
+        git_repo_ids = []
+        for x in rows:
+            git_repo_ids.append("%s" % x)
+
+        query = "SELECT status_info FROM build_snapshot WHERE snapshot_name=%s "
+        query_data = (bm_snapshot_name, )
+        existing_info = buildmonitor_db.get_value_from_query_data(query, query_data)
+        if existing_info == 0 or existing_info is None:
+            info_str = "dup(%s)" % ",".join(git_repo_ids)
+        else:
+            info_str = "%s dup(%s)" % (existing_info, ",".join(git_repo_ids))
+        query = "UPDATE build_snapshot SET status_info=%s WHERE snapshot_name=%s LIMIT 1"
+        query_data = (info_str, bm_snapshot_name)
+        buildmonitor_db.do_query(query, query_data)
+        sys.stdout.flush()
+
 def update_sr_submit_log(sr_submit_log_id, sr_tag, status, status_reason):
     print "[%s] update_str_submit_log %s, %s, %s\n" % (__file__, sr_submit_log_id, sr_tag, status_reason)
 
@@ -2692,6 +2723,8 @@ def main():
         end_create_snapshot_for_post_build_snapshot(bm_end_datetime,
                                                     bm_snapshot_url,
                                                     bm_snapshot_name)
+        update_duplicated_package_warning(bm_snapshot_name, bm_duplicated)
+
     elif bm_stage == 'Post_Snap_Fail':
         print '[%s][Post_Snap_Fail]\n' % (__file__)
         bm_snapshot_name = content.get("bm_snapshot_name")
index d95441f..e813290 100755 (executable)
@@ -134,6 +134,7 @@ def make_repo(project, backenddb, base_path, live_repo_base):
                                   project.replace(':', ':/'))
     repos = {}
     imagedatas = {}
+    duplicated_report = []
 
     if buildmonitor_enabled:
         bm_snapshot_name = local_build_id
@@ -283,18 +284,20 @@ def make_repo(project, backenddb, base_path, live_repo_base):
         # Check duplicated items
         path_list = [ t.keys()[0] for t in manifest_items if t.keys()[0] ]
         duplicated = set([x for x in path_list if path_list.count(x) > 1])
-        if len(duplicated) >= 1:
-            prepare_mail('error_report_manifest.env', \
-                         'Snapshot %s have duplicated packages' % (local_build_id), \
-                         '\nDuplicated items: %s' % duplicated, \
-                         os.getenv('NOREPLY_EMAIL_SENDER'), \
-                         os.getenv('MAILINGLIST_SYSTEM').split(','))
+        duplicated_report.extend(list(duplicated))
+        #if len(duplicated) >= 1:
+        #    prepare_mail('error_report_manifest.env', \
+        #                 'Snapshot %s have duplicated packages' % (local_build_id), \
+        #                 '\nDuplicated items: %s' % duplicated, \
+        #                 os.getenv('NOREPLY_EMAIL_SENDER'), \
+        #                 os.getenv('MAILINGLIST_SYSTEM').split(','))
 
     return {'project': project,
             'repo': repos,
             'repo_path': os.path.join(local_dir, local_build_id),
             'build_id': local_build_id,
-            'imagedata': imagedatas
+            'imagedata': imagedatas,
+            'duplicated': duplicated_report
         }
 
 def main():
@@ -390,7 +393,8 @@ def main():
                    "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']
+                   "bm_snapshot_name" : repo_data['build_id'],
+                   "bm_duplicated" : repo_data['duplicated']
                   }
         trigger_next("BUILD-MONITOR-4-%s" % bm_stage, bm_data)