Store pre-release images information into projet description
authorHasan Wan <hasan.wan@intel.com>
Mon, 19 Aug 2013 08:46:05 +0000 (11:46 +0300)
committerEduard Bartosh <eduard.bartosh@intel.com>
Tue, 20 Aug 2013 13:55:29 +0000 (06:55 -0700)
Fixes: #1179

Change-Id: Ie1b620d91d8f32150de1d54b098e7c2b85405c29
Signed-off-by: Hasan Wan <hasan.wan@intel.com>
Reviewed-on: https://otctools.jf.intel.com/review/5998
Tested-by: OTC Tools Tester <ed.bartosh@linux.intel.com>
Reviewed-by: Eduard Bartosh <eduard.bartosh@intel.com>
common/buildservice.py
job_imager.py
job_post_image.py [new file with mode: 0755]
job_pre_release_obs.py
packaging/jenkins-scripts.spec

index 8770f70..82e7e81 100644 (file)
@@ -457,9 +457,20 @@ class BuildService(OSC):
     def update_info(self, info, prj, pkg=None):
         """Updated jsoned info dictionary, saved in description."""
         saved_info = self.get_info(prj, pkg)
+
         projects = saved_info.get('projects') or []
+        images = saved_info.get('images') or []
+
         saved_info.update(info)
-        saved_info['projects'] = list(set(projects + info['projects']))
+        if 'projects' in info:
+            saved_info['projects'] = list(set(projects + info['projects']))
+        if 'images' in info:
+            # remove the old one if already exist
+            for image in images:
+                if info['images'][0]['name'] == image['name']:
+                    images.remove(image)
+
+            saved_info['images'] = images + info['images']
         self.set_description(json.dumps(saved_info), prj, pkg)
 
     def get_info(self, prj, pkg=None):
index 86e1889..b689078 100755 (executable)
@@ -6,9 +6,20 @@ import os
 import sys
 import subprocess
 
-from common.buildtrigger import trigger_info
+from common.buildtrigger import trigger_info, trigger_next
 from common.utils import sync
 
+def get_xml(image_dir, ks_name):
+    """ Get the xml the image, return the body as string """
+
+    for root, subdir, files in os.walk(image_dir):
+        for fname in files:
+            if fname.endswith("%s.xml" %(ks_name)):
+                return open(os.path.join(root,
+                                         fname)).read()
+
+    return ''
+
 def main():
     """The main body"""
 
@@ -50,14 +61,34 @@ def main():
                           stderr=sys.stderr,
                           shell=True)
 
+    status = 'success'
     if ret:
         print 'Error: mic returned %d' % ret
-        return ret
+        status = 'failed'
 
     # sync image, logs to SYNC_DEST
     sync_dest = os.path.join(os.getenv('IMG_SYNC_DEST_BASE'),
                              fields['repo_path'])
+
     sync(os.path.join(outdir, build_id), sync_dest)
 
+    xml_string = get_xml(os.path.join(outdir, build_id), name)
+
+    data = {"image_xml": xml_string,
+            "name": fields['name'],
+            "project": fields.get('project', ''),
+            "status": status,
+            "url": os.path.join(fields.get('url_pub_base', ''),
+                                fields['repo_path'],
+                                fields['images_path'])
+            }
+    # Trigger info for post image creation job
+    trigger_next("POST-IMAGE-CREATION", data)
+
+    if status == 'success':
+        return 0
+    else:
+        return -1
+
 if __name__ == "__main__":
     sys.exit(main())
diff --git a/job_post_image.py b/job_post_image.py
new file mode 100755 (executable)
index 0000000..59800d6
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+"""This script is used to update infomation about images"""
+
+import os
+import sys
+
+from common.buildtrigger import trigger_info
+from common.buildservice import BuildService
+
+def main():
+    """The main body"""
+    obs_api = os.getenv("OBS_API_URL")
+    obs_user = os.getenv("OBS_API_USERNAME")
+    obs_passwd = os.getenv("OBS_API_PASSWD")
+
+    content = trigger_info(os.getenv('TRIGGER_INFO'))
+
+    project = content.get('project', '')
+    name = content.get('name')
+    status = content.get('status', '')
+    url = content.get('url', '')
+
+    build = BuildService(obs_api, obs_user, obs_passwd)
+
+    info = {"images":
+                [{"name": name,
+                 "status": status,
+                 "url": url}]
+            }
+
+    build.update_info(info, project)
+    
+if __name__ == "__main__":
+    sys.exit(main())
index 15d4daf..bd8a1e6 100755 (executable)
@@ -117,7 +117,7 @@ def update_ks(imagedata, backenddb, info, base_url):
 
     return images_ks
 
-def trigger_image_creation(images_ks, build_id, path_repo):
+def trigger_image_creation(images_ks, build_id, path_repo, project, url_pub_base):
     """
     trigger_image_creation:
         Prepare the data and trigger the image_creation jobs
@@ -131,7 +131,9 @@ def trigger_image_creation(images_ks, build_id, path_repo):
                 'kickstart': kickstart,
                 'buildid': build_id,
                 'images_path': os.path.join("images", name),
-                'repo_path': path_repo
+                'project': project,
+                'repo_path': path_repo,
+                'url_pub_base': url_pub_base
                 }
         trigger_next('%s/image_trigger_%s' % (os.getenv('WORKSPACE'), index),
                      data)
@@ -191,7 +193,9 @@ def make_repo(project, repo, backenddb, base_url, base_path, live_repo_base):
 
     # trigger image creation jobs
     trigger_image_creation(images_ks, build_id,
-                           os.path.join(data['prerelease_dir'], build_id)
+                           os.path.join(data['prerelease_dir'], build_id),
+                           project,
+                           base_url
                            )
 
 def get_published_repo(repo_path_base, time_stamp):
index e1af26c..a7a90bc 100644 (file)
@@ -63,6 +63,7 @@ cp -r job_*.py common requests %{buildroot}%{destdir}/
 %{destdir}/job_buildcheck_post.py
 %{destdir}/job_deletetag.py
 %{destdir}/job_imager.py
+%{destdir}/job_post_image.py
 %{destdir}/job_jobs_dispatcher.py
 %{destdir}/job_load_repos.yaml.py
 %{destdir}/job_local_cache_cleanups.py