From 8adbb1120185cda02c28cdb25189ac99b8bee2b1 Mon Sep 17 00:00:00 2001 From: SoonKyu Park Date: Wed, 21 Feb 2018 20:50:36 +0900 Subject: [PATCH] gbs_stage table update on gbs dashboard building Change-Id: If06be50b894bbfa795e12b132e474894da43dc3f --- common/gbsutils.py | 5 ++++- job_gbs_dashboard_build.py | 15 ++++++++------ job_gbsdbbuild_create_snapshot.py | 22 ++++++++++++-------- job_gbsfullbuild_image_creator.py | 43 +++++++++++++++++++++++++++++++-------- 4 files changed, 61 insertions(+), 24 deletions(-) diff --git a/common/gbsutils.py b/common/gbsutils.py index a3d7c34..bc352c5 100644 --- a/common/gbsutils.py +++ b/common/gbsutils.py @@ -768,7 +768,10 @@ def gbs_update_dashboard(raw_data, via='trigger', trigger_name=''): raw_data["_worker"] = {"node_name": os.getenv('NODE_NAME'), "ip": find_my_ip()} if via == 'trigger': - trigger_next("DASHBOARD_UPDATE_%s_%s" % (trigger_name,raw_data.get("tag").replace('/', '_')), raw_data) + if trigger_name: + trigger_next("DASHBOARD_UPDATE_%s" % trigger_name, raw_data) + else: + trigger_next("DASHBOARD_UPDATE_%s" % raw_data.get("tag").replace('/', '_'), raw_data) else: try: encoded_data = base64.b64encode(json.dumps(raw_data)) diff --git a/job_gbs_dashboard_build.py b/job_gbs_dashboard_build.py index bd0eca0..044bb46 100644 --- a/job_gbs_dashboard_build.py +++ b/job_gbs_dashboard_build.py @@ -89,15 +89,12 @@ def main(): } trigger_next("BUILD-MONITOR-%s" % bm_stage, bm_data) + repo_arch_list = [] for repo in gbsbuild_dic['repository']: for arch in gbsbuild_dic['arch_list'][repo]: print 'OBS Project: %s, repository: %s, architecture: %s gbs build start'\ %(gbsbuild_dic['obs_prj'],repo,arch) - if buildmonitor_enabled: - gbs_update_data = {"tag" : gbsbuild_dic['gbsbuild_tag'], - "mode" : "build_queued", - "reason" : {"repo":repo,"arch":arch}} - gbs_update_dashboard(gbs_update_data,via='direct_call') + repo_arch_list.append({"repo":repo,"arch":arch}) trigger_next('gbsdbbuild_one_repoarch_build_%s_%s' % (repo, arch),\ {'gbsbuild_dic':gbsbuild_dic, 'repository':repo, @@ -107,9 +104,15 @@ def main(): if buildmonitor_enabled: gbs_update_data = {"tag" : gbsbuild_dic['gbsbuild_tag'], - "mode" : "snapshot_queued"} + "mode" : "build_queued", + "reason" : {"repo_arch_list":repo_arch_list}} gbs_update_dashboard(gbs_update_data,via='direct_call') + mode = "snapshot_queued" + gbs_update_data = {"tag" : gbsbuild_dic['gbsbuild_tag'], + "mode" : mode} + gbs_update_dashboard(gbs_update_data,via='trigger',trigger_name=mode) + # TRIGGER NEXT GBSFULLBUILD-CREATE-SNAPSHOT trigger_next("gbsdbbuild-create-snapshot",\ {'gbsbuild_dic':gbsbuild_dic}) diff --git a/job_gbsdbbuild_create_snapshot.py b/job_gbsdbbuild_create_snapshot.py index e4d58b2..06398e3 100755 --- a/job_gbsdbbuild_create_snapshot.py +++ b/job_gbsdbbuild_create_snapshot.py @@ -73,7 +73,7 @@ def replace_ks_file_for_gbsdbbuild(kickstart,build_id): def prepare_trigger_data(images, build_id, path_repo, project, - url_pub_base): + url_pub_base,gbsbuild_tag): """ prepare_trigger_data: Prepare the trigger data @@ -112,7 +112,8 @@ def prepare_trigger_data(images, build_id, path_repo, project, 'project': project, 'repo': repo_name, 'repo_path': path_repo, - 'url_pub_base': url_pub_base + 'url_pub_base': url_pub_base, + 'gbsbuild_tag': gbsbuild_tag } trigger_data[repo_name].append(data) @@ -125,16 +126,13 @@ def prepare_trigger_data(images, build_id, path_repo, project, def trigger_image_creation(trigger_data): """Trigger the image_creation jobs""" + ks_name_list = [] count = 0 for repo in trigger_data.keys(): for index, data in enumerate(trigger_data[repo]): - if buildmonitor_enabled: - gbs_update_data = {"tag" : gbsbuild_dic['gbsbuild_tag'], - "mode" : "image_queued", - "reason" : {"ks_name":data['name']}} - gbs_update_dashboard(gbs_update_data,via='direct_call') trigger_next('gbsfullbuild_image_trigger_%s_%s' % (repo, index), data) count += 1 + ks_name_list.append(data['name']) # Request number of imager nodes if os.getenv("ONDEMAND_SLAVE_CONFIGURATION_ENABLED", "0") == "1": if count > 0: @@ -142,6 +140,12 @@ def trigger_image_creation(trigger_data): extra_params={"ACTION": "REQUEST_WORKER", \ "PURPOSE": "JENKINS_IMAGER", \ "REQUESTED_NUM_EXECUTORS": "%d" % count}) + if buildmonitor_enabled: + gbs_update_data = {"tag" : data['gbsbuild_tag'], + "mode" : "image_queued", + "reason" : {"ks_name_list":ks_name_list}} + gbs_update_dashboard(gbs_update_data,via='direct_call') + def create_local_targets(gbsbuild_dic): @@ -317,7 +321,7 @@ def main(): if buildmonitor_enabled: gbs_update_data = {"tag" : gbsbuild_dic['gbsbuild_tag'], - "mode" : "snapshot_started", + "mode" : "snapshot_started"} gbs_update_dashboard(gbs_update_data,via='direct_call') if buildmonitor_enabled: @@ -337,7 +341,7 @@ def main(): repo_data['imagedata'], repo_data['build_id'], repo_data['repo_path'], - project, base_url) + project, base_url, gbsbuild_dic['gbsbuild_tag']) # trigger image creation jobs trigger_image_creation(trigger_data) diff --git a/job_gbsfullbuild_image_creator.py b/job_gbsfullbuild_image_creator.py index 9411266..980f1fc 100755 --- a/job_gbsfullbuild_image_creator.py +++ b/job_gbsfullbuild_image_creator.py @@ -35,9 +35,33 @@ from StringIO import StringIO from random import randint -from common.buildtrigger import trigger_info, trigger_next +from common.buildtrigger import trigger_info, trigger_next, remote_jenkins_build_job from common.utils import sync, sync_get, set_permissions, Workdir -from common.gbsutils import gbs_update_dashboard +from urllib import quote_plus + +def find_my_ip(): + try: + return os.getenv('SSH_CONNECTION').split(' ')[2] + except Exception as err: + return '0.0.0.0' + +def gbs_update_dashboard(raw_data, via='trigger', trigger_name=''): + raw_data["_timestamp"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + raw_data["_worker"] = {"node_name": os.getenv('NODE_NAME'), + "ip": find_my_ip()} + if via == 'trigger': + trigger_next("DASHBOARD_UPDATE_%s" % trigger_name, raw_data) + else: + try: + encoded_data = base64.b64encode(json.dumps(raw_data)) + remote_jenkins_build_job(os.getenv('JENKINS_URL_INTERNAL'), \ + os.getenv('JENKINS_USER'), \ + os.getenv('JENKINS_PW'), \ + jobname=os.getenv('DASHBOARD_UPDATE_JOB_NAME', 'BUILD-MONITOR-GBS'), \ + data='TRIGGER_INFO="%s"' % (quote_plus(encoded_data))) + except Exception as err: + trigger_next("DASHBOARD_UPDATE_%s" % trigger_name, raw_data) + # Returns the list of baseurls from kickstart configuration. def get_base_url(kickstart,buildid): @@ -221,10 +245,11 @@ def main(): # Update dashboard gbs build status if buildmonitor_enabled: - gbs_update_data = {"tag" : gbsbuild_dic['gbsbuild_tag'], - "mode" : "image_started", + mode = "image_started" + gbs_update_data = {"tag" : fields['gbsbuild_tag'], + "mode" : mode, "reason" : {"ks_name":fields['name']}} - gbs_update_dashboard(gbs_update_data,via='direct_call') + gbs_update_dashboard(gbs_update_data,via='trigger',trigger_name=mode) # Check if we've got required fields in TRIGGER_INFO for field in ('kickstart', 'name', 'buildid', 'repo_path'): @@ -351,10 +376,12 @@ def main(): gbs_img_status = 'S' if status == 'failed': gbs_img_status = 'F' - gbs_update_data = {"tag" : gbsbuild_dic['gbsbuild_tag'], - "mode" : "image_finished", + mode = "image_finished" + gbs_update_data = {"tag" : fields['gbsbuild_tag'], + "mode" : mode, "reason" : {"ks_name":fields['name'],"status":gbs_img_status}} - gbs_update_dashboard(gbs_update_data,via='direct_call') + gbs_update_dashboard(gbs_update_data,via='trigger',trigger_name=mode) + xml_string = get_xml(os.path.join(outdir, build_id), name) -- 2.7.4