Add download_num in a obs description. Block build info update if download_num mismatch 23/99123/1
authorYonghee Han <onstudy@samsung.com>
Tue, 22 Nov 2016 03:48:06 +0000 (12:48 +0900)
committerYonghee Han <onstudy@samsung.com>
Tue, 22 Nov 2016 03:48:06 +0000 (12:48 +0900)
Change-Id: I1e18c38ee53fdbc93fb777aad16493a262e6cfc8

common/buildservice.py
job_imager.py
job_post_image.py
job_pre_release_obs.py

index e76ffa8..0fc06bb 100755 (executable)
@@ -580,7 +580,7 @@ class BuildService(OSC):
         packages = saved_info.get('packages') or []
         images = saved_info.get('images') or []
         submitter = saved_info.get('submitter') or []
-
+        download_num = saved_info.get('download_num') or int(0)
         saved_info.update(info)
         if 'projects' in info:
             saved_info['projects'] = list(set(projects + info['projects']))
@@ -606,6 +606,9 @@ class BuildService(OSC):
                 saved_info['snapshot'] = info['snapshot']
             if 'chksnap' in info:
                 saved_info['chksnap'] = info['chksnap']
+        if 'download_num' in info:
+            saved_info['download_num'] = int(download_num) + int(info['download_num'])
+        
         self.set_description(json.dumps(saved_info), prj, pkg)
 
     def get_info(self, prj, pkg=None):
index 3b0ce83..e4b69ea 100755 (executable)
@@ -218,7 +218,7 @@ def main():
     fields = trigger_info(os.getenv('TRIGGER_INFO'))
 
     # Check if we've got required fields in TRIGGER_INFO
-    for field in ('kickstart', 'name', 'buildid', 'repo_path'):
+    for field in ('kickstart', 'name', 'buildid', 'repo_path', 'download_num'):
         if field not in fields:
             print 'Error: TRIGGER_INFO doesn\'t contain %s'
             return 1
@@ -241,7 +241,8 @@ def main():
             "name": fields['name'],
             "project": fields.get('project', ''),
             "status": "failed",
-            "url": url
+            "url": url,
+            "download_num": int(fields['download_num'])
             }
     trigger_next("POST-IMAGE-CREATION", data)
 
@@ -322,7 +323,8 @@ def main():
             "name": fields['name'],
             "project": fields.get('project', ''),
             "status": status,
-            "url": url
+            "url": url,
+            "download_num": int(fields['download_num'])
             }
 
     trigger_next("POST-IMAGE-CREATION", data)
index a8b9e09..2225305 100755 (executable)
@@ -63,6 +63,13 @@ def main():
     if is_prerelease_project(project):
         build = BuildService(obs_api, obs_user, obs_passwd)
 
+        saveinfo = build.get_info(project)
+        if saveinfo.get('download_num', 0) != content.get('download_num', 1):
+            print 'EXCEPTION* mismatch download_num current:%s, obs:%s' \
+                  % (content.get('download_num'), saveinfo.get('download_num'))
+            print 'SKIP UPDATING BUILD INFO'
+            return
+
         info = {"images":
                     [{"name": name,
                      "status": status,
@@ -72,7 +79,7 @@ def main():
 
         if buildmonitor_enabled:
             saveinfo = build.get_info(project)
-                if len(saveinfo['images']) == saveinfo['images_count']:
+                if len(saveinfo['images']) == int(saveinfo['images_count']):
                     print '[%s] last image(%s)\n' \
                           % (__file__, len(saveinfo['images']))
                     #buildmonitor.end_create_image_for_sr_stage(bm_start_datetime,
index 9c39182..b8342c0 100755 (executable)
@@ -81,7 +81,7 @@ def update_ks(imagedata, snapshot_id, pkg_urls):
     return images_ks
 
 def trigger_image_creation(images_ks, build_id, path_repo,
-                           project, url_pub_base, repo_name):
+                           project, url_pub_base, repo_name, download_num=1):
     """
     trigger_image_creation:
         Prepare the data and trigger the image_creation jobs
@@ -100,7 +100,8 @@ def trigger_image_creation(images_ks, build_id, path_repo,
                 'project': project,
                 'repo_path': path_repo,
                 'repo': repo_name,
-                'url_pub_base': url_pub_base
+                'url_pub_base': url_pub_base,
+                'download_num': download_num
                 }
         # add image_building for iris
         pub_enabled = os.getenv("IRIS_PUB_ENABLED", "0") != "0"
@@ -132,6 +133,9 @@ def make_repo(project, repo, backenddb, base_url, base_path,
     """
     images_count = 0
 
+    current_download_num = build.get_info(project).get('download_num') or int(1)
+    print 'Current download_num = %d' % current_download_num
+
     # Make build id from latest snapshot + project suffix
     target_project, tstamp = get_info_from_prerelease_name(project)
 
@@ -263,7 +267,7 @@ def make_repo(project, repo, backenddb, base_url, base_path,
         images_count += trigger_image_creation(images_ks, prerelease.build_id,
                                os.path.join(prerelease.dir,
                                             prerelease.build_id),
-                               project, base_url, repo['Name'])
+                               project, base_url, repo['Name'], download_num=current_download_num)
     # reset 'images' and add download_url meta info
     build.update_info({'images_count': images_count,
                        'images': [],