From 2b0e8c93229dd6efd56093a13aa61380a32ccad4 Mon Sep 17 00:00:00 2001 From: Junghyun Kim Date: Mon, 16 Jan 2017 11:29:14 +0900 Subject: [PATCH] Add DB logging for buildlogs Change-Id: I7a9b5a02233c148bfb3cc154d4057eaae4752e69 Signed-off-by: Junghyun Kim --- job_buildlogs.py | 28 +++++++++++++++++++++++++++- job_buildmonitor.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/job_buildlogs.py b/job_buildlogs.py index 8b90a04..1d64b2f 100755 --- a/job_buildlogs.py +++ b/job_buildlogs.py @@ -31,6 +31,24 @@ from common.buildtrigger import trigger_info, trigger_next from common.buildservice import BuildService from common.utils import sync +def update_buildlog_in_buildmonitor(package_build_dict, download_url, + repo_path, proj, repo, target_path): + data = {} + data['bm_stage'] = "UPDATE_BUILD_LOG" + data['project'] = proj + data['repo'] = repo + data['base_url'] = os.path.join(download_url, repo_path, target_path) + data['pkgs'] = {} + + for (pkg_name, arch), (status, dummy, path_to_log) in \ + package_build_dict.items(): + if arch not in data['pkgs']: + data['pkgs'][arch] = {} + + data['pkgs'][arch][pkg_name] = os.path.join(arch, status, + "%s.buildlog.txt" % pkg_name) + trigger_next("BUILD-MONITOR-%s" % repo, data) + def restructure_output_dir(package_build_dict, target_path): """ Put the logs in request structure """ @@ -98,7 +116,7 @@ def main(): obs_api = os.getenv("OBS_API_URL") obs_user = os.getenv("OBS_API_USERNAME") obs_passwd = os.getenv("OBS_API_PASSWD") - + build = BuildService(obs_api, obs_user, obs_passwd) for repository in content.get("repo").keys(): @@ -114,6 +132,14 @@ def main(): 'builddata', 'buildlogs', repository)) + update_buildlog_in_buildmonitor(packages_data, + os.getenv("URL_PUBLIC_REPO_BASE"), + content['repo_path'], + project, + repository, + os.path.join('builddata', + 'buildlogs', + repository)) # Make file at packages depends of OBS os.makedirs(os.path.join(sync_out_dir,'builddata','depends')) diff --git a/job_buildmonitor.py b/job_buildmonitor.py index 7c97c60..f32cc87 100644 --- a/job_buildmonitor.py +++ b/job_buildmonitor.py @@ -1051,6 +1051,50 @@ def update_repa(sr_tag, status, status_reason): query_data = (status, status_reason, sr_tag) buildmonitor_db.do_query(query, query_data) +def update_build_log(content): + project = content.get('project') + repo = content.get('repo') + base_url = content.get('base_url') + pkgs = content.get('pkgs') + + print "[%s] update build log %s %s %s\n" % (__file__, project, repo, base_url) + query = "SELECT bt.id, ipa.id, bt.arch, ipa.package_name "+ \ + "FROM info_project ip, build_project bp, build_target bt, info_package ipa "+\ + "WHERE bp.info_project_id = ip.id "+ \ + "AND bt.build_project_id = bp.id "+\ + "AND ipa.info_project_id = ip.id "+\ + "AND ip.project_name = %s "+ \ + "AND bt.repository = %s ORDER BY bt.id" + query_data = (project, repo) + rows = buildmonitor_db.get_multi_values_from_query_data(query, query_data) + id_data = {} + for row in rows: + if len(row) == 1: + raise LocalError("Got no data! exiting...\n") + build_target_id = row[0] + info_package_id = row[1] + arch = row[2] + package_name = row[3] + + if arch not in id_data: + id_data[arch] = {} + if package_name not in id_data[arch]: + id_data[arch][package_name] = {} + + id_data[arch][package_name]['bt_id'] = build_target_id + id_data[arch][package_name]['ipa_id'] = info_package_id + + for arch in pkgs.keys(): + for pkg in pkgs[arch].keys(): + build_log_url = os.path.join(base_url, pkgs[arch][pkg]) + print '[%s] build_log %s %s %s\n' % (__file__, arch, pkg, build_log_url) + query = "UPDATE build_package SET build_log_url=%s WHERE build_target_id=%s AND info_package_id=%s" + build_target_id = id_data[arch][pkg]['bt_id'] + info_package_id = id_data[arch][pkg]['ipa_id'] + query_data = (build_log_url, build_target_id, info_package_id) + buildmonitor_db.do_query(query, query_data) + + #================================================================================== def main(): @@ -1292,6 +1336,10 @@ def main(): update_repa(sr_tag, status, status_str) + elif bm_stage == "UPDATE_BUILD_LOG": + print "[%s][UPDATE_BUILD_LOG]\n" % (__file__) + update_build_log(content) + #======================================================= # [POST] Image / Post_Image => N/A -- 2.7.4