Add status field in sr_commit table and updated on dashboard 18/168718/1
authorYonghee Han <onstudy@samsung.com>
Tue, 30 Jan 2018 08:42:22 +0000 (17:42 +0900)
committerYonghee Han <onstudy@samsung.com>
Tue, 30 Jan 2018 08:42:22 +0000 (17:42 +0900)
N : New package
R : Renamed package or Git Repository

Change-Id: Ieabca49f4ce6be64e32a5f0c2a69aae47ac41e94

common/buildmonitor_extention.py
job_buildmonitor.py
job_submit.py

index a9395c9..3879304 100644 (file)
@@ -345,26 +345,112 @@ class BuildMonitorExtention(object):
         do_query(query, (package_name, package_name))
 
 
-    def get_manifest(self, build_project_id):
+    def get_git_repo_for_manifest(self, build_project_id, git_repo=None):
 
         if not self.is_connect():
             return
 
-        manifest_list = []
-        # Select git_repository name
-        query = "SELECT gr.name FROM snapshot_manifest sm, git_repository gr, git_commit gc \
-                 WHERE sm.build_project_id = %s \
-                 AND gr.id = sm.git_repository_id \
-                 AND gc.id = sm.git_commit_id \
-                 GROUP BY gr.name"
-        query_data = (build_project_id,)
+        manifest_data = {}
+
+        if git_repo:
+            query = "SELECT gr.name, gc.commit_id, op.name FROM \
+                     ( SELECT * FROM snapshot_manifest order by date desc) as sm, \
+                     git_repository gr, git_commit gc, obs_package op \
+                     WHERE sm.build_project_id = %s \
+                     AND sm.git_repository_id = \
+                     ( SELECT id FROM git_repository WHERE name = %s ) \
+                     AND gr.id = sm.git_repository_id \
+                     AND gc.id = sm.git_commit_id \
+                     AND op.id = sm.obs_package_id \
+                     GROUP BY gr.name"
+            query_data = (build_project_id,git_repo)
+        else:
+            query = "SELECT gr.name, gc.commit_id, op.name FROM \
+                     ( SELECT * FROM snapshot_manifest order by date desc) as sm, \
+                     git_repository gr, git_commit gc, obs_package op \
+                     WHERE sm.build_project_id = %s \
+                     AND gr.id = sm.git_repository_id \
+                     AND gc.id = sm.git_commit_id \
+                     AND op.id = sm.obs_package_id \
+                     GROUP BY gr.name"
+            query_data = (build_project_id,)
         rows = get_multi_values_from_query_data(query, query_data)
-        if rows == 0:
-            return manifest_list
-        for x in rows:
-            manifest_list.append("%s" % x)
-    
-        return manifest_list
+        if len(rows) == 1 and rows[0] == 0:
+            return manifest_data
+        for x,y,z in rows:
+            manifest = []
+            manifest.append((y,z))
+            manifest_data[x] = manifest
+        # return data
+        # {'git_repo': [(commit,obs_package)]}
+        return manifest_data
+
+    def get_obs_package_for_manifest(self, build_project_id, obs_package=None):
+
+        if not self.is_connect():
+            return
+
+        manifest_data = {}
+
+        if obs_package:
+            query = "SELECT gr.name, gc.commit_id, op.name FROM \
+                     ( SELECT * FROM snapshot_manifest order by date desc) as sm, \
+                     git_repository gr, git_commit gc, obs_package op \
+                     WHERE sm.build_project_id = %s \
+                     AND sm.obs_package_id = \
+                     ( SELECT id FROM obs_package WHERE name = %s ) \
+                     AND gr.id = sm.git_repository_id \
+                     AND gc.id = sm.git_commit_id \
+                     AND op.id = sm.obs_package_id \
+                     GROUP BY gr.name"
+            query_data = (build_project_id, obs_package)
+
+        else:
+            query = "SELECT gr.name, gc.commit_id, op.name FROM \
+                     ( SELECT * FROM snapshot_manifest order by date desc) as sm, \
+                     git_repository gr, git_commit gc, obs_package op \
+                     WHERE sm.build_project_id = %s \
+                     AND gr.id = sm.git_repository_id \
+                     AND gc.id = sm.git_commit_id \
+                     AND op.id = sm.obs_package_id \
+                     GROUP BY gr.name"
+            query_data = (build_project_id,)
+        rows = get_multi_values_from_query_data(query, query_data)
+        if len(rows) == 1 and rows[0] == 0:
+            return manifest_data
+        for x,y,z in rows:
+            manifest = []
+            manifest.append((x,y))
+            manifest_data[z] = manifest
+        # return data
+        # {'package': [(git_repo,commit)]}
+        return manifest_data
+
+
+    def is_contain_git_in_project(self, project, git_repo, package_name):
+
+        if not self.is_connect():
+            return [0,'']
+
+        build_project_id = self.get_build_project_id(project)
+        if build_project_id == 0:
+            return [0,'']
+
+        manifest_data = self.get_git_repo_for_manifest(build_project_id, git_repo)
+        if not manifest_data.get(git_repo):
+            manifest_data = self.get_obs_package_for_manifest(build_project_id, package_name)
+            if not manifest_data.get(package_name):
+                return [-1,'']
+
+            gitrepo, _commit = manifest_data.get(package_name)[0]
+            if git_repo != gitrepo:
+                return [-2, gitrepo]
+        else:
+            _commit, obs_package_name = manifest_data.get(git_repo)[0]
+            if package_name != obs_package_name:
+                return [-2, obs_package_name]
+
+        return [0,'']
 
     def update_manifest_bulkdata(self, manifest_data_bulk_data):
 
@@ -400,7 +486,7 @@ class BuildMonitorExtention(object):
             error_string = "None"
         else:
             status = "failed"
-
+    
         query = "UPDATE project_mgr_log SET status=%s, reason=%s WHERE id=%s"
         query_data = ( status, error_string, id)
         do_query(query, query_data)
index 358cf64..9ff5930 100644 (file)
@@ -173,7 +173,7 @@ def sr_submit_for_sr_status(bm_git_tag):
 
 def sr_submit_for_sr_commit(commit_date, commit_msg, submit_date, submit_msg,
                             submitter, git_tag, gerrit_project,
-                            gerrit_newrev, gerrit_account_name, obs_package_name):
+                            gerrit_newrev, gerrit_account_name, obs_package_name, status):
     print '[%s] enter sr_submit_for_sr_commit\n' % (__file__)
 
     # get current_sr_status_id (should be here, after sr_submit_for_sr_status)
@@ -189,12 +189,12 @@ def sr_submit_for_sr_commit(commit_date, commit_msg, submit_date, submit_msg,
     query = "INSERT INTO sr_commit (sr_status_id, git_repository," \
             "obs_package_name, git_commit_id, git_commit_date, "   \
             "git_commit_message, git_committer, sr_submit_date, "  \
-            "sr_submit_message, sr_submitter) " \
-            "VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
+            "sr_submit_message, sr_submitter, status) " \
+            "VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
     query_data = (curr_sr_status_id, gerrit_project, obs_pkg_name,
                     gerrit_newrev, commit_date, commit_msg,
                     gerrit_account_name, submit_date, submit_msg,
-                    bm_submitter)
+                    bm_submitter, status)
     buildmonitor_db.do_query(query, query_data)
 
 def start_pre_build_for_sr_stage(git_tag, bm_start_datetime,
@@ -2347,6 +2347,7 @@ def main():
         submit_date = transform_date(content.get("submit_date"))
         submit_msg = truncate_msg(content.get("submit_msg"))
         submitter = content.get("submitter")
+        status = content.get("status")
         git_tag = content.get("git_tag")
         obs_package_name = content.get("obs_package_name")
         gerrit_project = content.get("gerrit_project")
@@ -2370,7 +2371,7 @@ def main():
         sr_submit_for_sr_status(git_tag)
         sr_submit_for_sr_commit(commit_date, commit_msg, submit_date, submit_msg,
                                 submitter, git_tag, gerrit_project,
-                                gerrit_newrev, gerrit_account_name, obs_package_name)
+                                gerrit_newrev, gerrit_account_name, obs_package_name, status)
 
         if bm_stage == 'Submit':
             print '[%s][Submit]\n' % (__file__)
index 78a5fb1..20d2a58 100755 (executable)
@@ -55,6 +55,8 @@ from gbp.errors import GbpError
 
 from common.workflow import create_project, find_submit_tag, check_tag_format, find_specfile, parse_specfile, get_sr_process_status
 
+from common.buildmonitor_extention import BuildMonitorExtention
+
 # set default char-set endcoding to utf-8
 reload(sys)
 sys.setdefaultencoding('utf-8') # pylint: disable-msg=E1101
@@ -475,6 +477,8 @@ def main(build_type, build, event, sr_count):
             print 'The check for the tag format is error, exit now\n'
             return 0
 
+    bm_ext = BuildMonitorExtention()
+
     packagingdir = utils.parse_link('%s/%s' % (prjdir, 'packaging'))
     print 'packaging dir is %s/%s' % (prjdir, packagingdir)
 
@@ -647,6 +651,18 @@ def main(build_type, build, event, sr_count):
             #buildmonitor.package_build_for_sr_detail_sr_stage(git_tag, bm_start_datetime,
             #                                                  bm_end_datetime,
             #                                                  submit_info['pre_created'])
+
+            contains, renamed = bm_ext.is_contain_git_in_project(obs_target_prj, event['project'], package)
+
+            if contains == -1:
+                # different git path
+                status = "N"
+            elif contains == -2:
+                # different package name
+                status = "R,(%s)" %(renamed)
+            else:
+                status = ""
+
             bm_stage = 'Submit'
             bm_data = {"bm_stage" : bm_stage,
                        "commit_date" : commit_date,
@@ -654,6 +670,7 @@ def main(build_type, build, event, sr_count):
                        "submit_date" : submit_date,
                        "submit_msg" : submit_msg,
                        "submitter" : submitter,
+                       "status" : status,
                        "git_tag" : git_tag,
                        "obs_package_name" : package,
                        "gerrit_project" : event['project'],