From f67606560ac61d63d753dd2fc8426501697edd58 Mon Sep 17 00:00:00 2001 From: Yonghee Han Date: Wed, 17 Jan 2018 11:32:25 +0900 Subject: [PATCH] Changed update function to use a api of BuildMonitorExtention move send_status_buildmonitor to update_project_mgr_log Change-Id: I0cceafc7ec16f7c856d8f639b7d71f15154f9ad1 --- common/buildmonitor_extention.py | 15 +++++++++++++++ job_obs_project_manager.py | 25 +++---------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/common/buildmonitor_extention.py b/common/buildmonitor_extention.py index a16a7ab..8f2d8df 100644 --- a/common/buildmonitor_extention.py +++ b/common/buildmonitor_extention.py @@ -233,6 +233,21 @@ class BuildMonitorExtention(object): query_data = ( sr_tag, profile, repa_user, comment, repa_decision_db) do_query(query, query_data) + def update_project_mgr_log(self, id, error_string): + + if not self.is_connect(): + return + + if error_string is None or error_string == "": + status = "succeeded" + error_string = "None" + else: + status = "failed" + + query = "UPDATE project_mgr_log SET status=%s, reason=%s WHERE id=%s" + query_data = ( status, error_string, id) + do_query(query, query_data) + def put_snapshot_manifest(bm_ext, project, manifest_items, start_datetime): """ PUT Snapshot Manifest diff --git a/job_obs_project_manager.py b/job_obs_project_manager.py index 8ab9189..6d5dd49 100644 --- a/job_obs_project_manager.py +++ b/job_obs_project_manager.py @@ -36,9 +36,8 @@ from osc import core from common.buildservice import BuildService from common.buildtrigger import trigger_info, trigger_next from common import runner -from common import buildmonitor_db from datetime import datetime - +from common.buildmonitor_extention import BuildMonitorExtention # set default char-set endcoding to utf-8 reload(sys) @@ -194,25 +193,6 @@ def obs_project_create_prj(build, prj, info=None, meta=None, config=None): except: raise LocalError("Unable to create project %s: %s" % (prj)) - -def send_status_buildmonitor(id, error_string): - """ - send status to build monitor - """ - buildmonitor_db.connect_db() - - if error_string is None or error_string == "": - status = "succeeded" - error_string = "None" - else: - status = "failed" - - query = "UPDATE project_mgr_log SET status=%s, reason=%s WHERE id=%s" - query_data = ( status, error_string, id) - buildmonitor_db.do_query(query, query_data) - - buildmonitor_db.connect_db() - def main(): """ @@ -239,6 +219,7 @@ def main(): obs_passwd = os.getenv("OBS_API_PASSWD") build = BuildService(obs_api, obs_user, obs_passwd) + bm_ext = BuildMonitorExtention() #check project #Check if we've got required field in env @@ -271,7 +252,7 @@ def main(): except ObsError, error: failures = (str(exc)) finally: - send_status_buildmonitor(id, failures) + bm_ext.update_project_mgr_log(id, failures) return 0 -- 2.7.4