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):
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"""
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())
--- /dev/null
+#!/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())
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
'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)
# 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):
%{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