From: Junghyun Kim Date: Tue, 10 Jan 2017 01:45:15 +0000 (+0900) Subject: JOB ADDED: repa accept/reject X-Git-Tag: submit/trunk/20190927.012743~569 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2ecef787adf784844aa1f55dbbf5bbfd6ba1899b;p=services%2Fjenkins-scripts.git JOB ADDED: repa accept/reject To log repa accept/reject, buildmonitor.py is also modified. Change-Id: Ib79aa65bc91986ca70205ddee50af92078eecd80 Signed-off-by: Junghyun Kim --- diff --git a/job_buildmonitor.py b/job_buildmonitor.py index 342efb0..7c97c60 100644 --- a/job_buildmonitor.py +++ b/job_buildmonitor.py @@ -1033,17 +1033,24 @@ def end_create_snapshot_for_post_build_snapshot(project, bm_start_datetime, def update_sr_submit_log(sr_submit_log_id, sr_tag, status, status_reason): print "[%s] update_str_submit_log %s, %s, %s\n" % (__file__, sr_submit_log_id, sr_tag, status_reason) - query = "update sr_submit_log set status=%s,sr_tag=%s,reason=%s where id=%s" + query = "UPDATE sr_submit_log SET status=%s,sr_tag=%s,reason=%s WHERE id=%s" query_data = (status, sr_tag, status_reason, sr_submit_log_id) buildmonitor_db.do_query(query, query_data) def update_sr_submit_log_completed(git_tag): print "[%s] update_sr_submit_log_completed %s\n" % (__file__, git_tag) - query = "update sr_submit_log set status='completed' where sr_tag=%s order by id desc limit 1" + query = "UPDATE sr_submit_log SET status='Completed' WHERE sr_tag=%s ORDER BY id DESC LIMIT 1" query_data = (git_tag) buildmonitor_db.do_query(query, query_data) +def update_repa(sr_tag, status, status_reason): + print "[%s] update_repa %s, %s, %s\n", (__file__, sr_tag, status, status_reason) + + query = "UPDATE sr_accept_log SET status=%s,status_reason=%s WHERE sr=%s ORDER BY id DESC LIMIT 1" + query_data = (status, status_reason, sr_tag) + buildmonitor_db.do_query(query, query_data) + #================================================================================== def main(): @@ -1276,6 +1283,16 @@ def main(): bm_project = content.get("bm_project") # func call update_fail_create_snapshot_for_sr_stage(bm_project) + + elif bm_stage == 'REPA': + print '[%s][REPA]\n' % (__file__) + sr_tag = content.get("sr_tag") + status = content.get("status") + status_str = content.get("status_reason") + + update_repa(sr_tag, status, status_str) + + #======================================================= # [POST] Image / Post_Image => N/A #======================================================= diff --git a/job_repa.py b/job_repa.py new file mode 100644 index 0000000..f7693e9 --- /dev/null +++ b/job_repa.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python +# vim: ai ts=4 sts=4 et sw=4 +# +# Copyright (C) 2016 Samsung +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +""" +This code is called by repa webpage +""" + +import os +import re +import sys +import shutil + +from xml.dom import minidom +import xml.etree.ElementTree as ElementTree + +from gbp.git.repository import GitRepositoryError + +from osc import core + +from common.gerrit import Gerrit, get_gerrit_event, GerritError, is_ref_deleted +from common.git import Git, clone_gitproject +from common.buildservice import BuildService +from common.prerelease import get_prerelease_project_name +from common.buildtrigger import trigger_info, trigger_next +from common import runner + +class LocalError(Exception): + """Local error exception.""" + pass + +#------------------------------------------------------------------------------- +# global variables +status_str = "" +error_string = "" +obs_api = os.getenv("OBS_API_URL") +obs_user = os.getenv("OBS_API_USERNAME") +obs_passwd = os.getenv("OBS_API_PASSWD") + +repa_decision = os.getenv("REPA_DECISION") +obs_project = os.getenv("OBS_PROJECT") +sr_tag = os.getenv("SR_TAG") +repa_comment = os.getenv("REPA_COMMENT") +repa_user = os.getenv("REPA_USER") + +#------------------------------------------------------------------------------- +def is_aggregate_package(build, proj, pack): + if re.search("aggregate", pack): + if "_aggregate" in build.get_src_file_list(proj, pack): + return True + + return False + + +def check_permission(build, project, userid): + meta_xml = build.get_meta(project) + print meta_xml + xml_root = ElementTree.fromstringlist(meta_xml) + for person in xml_root.findall('person'): + if person.attrib['role'] == 'maintainer' and userid == person.attrib['userid']: + return True + + return False + + +def accept_or_reject(build, prerelease_proj, git_tag, state, comment=''): + info = build.get_info(prerelease_proj) + + print "repa %s %s (%s)" % (state, git_tag, prerelease_proj) + global status_str + status_str = state + + submitter = info['submitter'] + projects = '[' + ', '.join(info['projects']) + ']' + message = '' + if submitter: + message = "Submitter: %s\n" % submitter + + message += "Comments: %s \nGit project: %s\nTag: %s" \ + % (comment or "submission %s" % str(git_tag), + projects, git_tag) + + target_prj = str(info['obs_target_prj']) + + # Create SR + org_source_packages=build.get_package_list(prerelease_proj) + source_packages=[] + for p in org_source_packages: + if not is_aggregate_package(build, prerelease_proj, p): + source_packages.append(p) + + reqid = build.create_sr(prerelease_proj, source_packages, + target_prj, message=message) + + print 'created SR %s' % reqid + + # and immediately set its state + message = "SR %s is set to %s" % (reqid, state) + if comment: + message += comment + build.set_sr_state(reqid, state=state, + message=str(message), force=True) + print 'set SR state to', state + +def repa_reject(build, proj, git_tag, comment=''): + accept_or_reject(build, proj, git_tag, 'declined', comment) + +def repa_accept(build, proj, git_tag, comment=''): + accept_or_reject(build, proj, git_tag, 'accepted', comment) + +def main(): + """Script entry point. + """ + + print '---[JOB STARTED: repa]-------------------------' + + print "OBS_PROJECT = ", obs_project + print "SR_TAG = ", sr_tag + print "REPA_COMMENT = ", repa_comment + print "REPA_DECISION = ", repa_decision + print "REPA_USER = ", repa_user + + build = BuildService(obs_api, obs_user, obs_passwd) + ret = 0 + + # home:prerelease:Tizen:Mobile:submit:tizen:20161025.103628 + prerelease_proj=get_prerelease_project_name(obs_project, sr_tag) + + if not check_permission(build, obs_project, repa_user): + raise LocalError("User %s does not have permission for OBS project %s" % (repa_user, obs_project)) + + if repa_decision == "accept": + repa_accept(build, prerelease_proj, sr_tag, repa_comment) + else: + repa_reject(build, prerelease_proj, sr_tag, repa_comment) + + return 0 + +if __name__ == '__main__': + try: + exit_status = main() + except Exception as err: + print err + global status_str, error_string + status_str = "Failed" + error_string = str(err) + exit_status = 1 + +bm_stage = "REPA" + +bm_data = {"bm_stage": bm_stage, + "sr_tag": sr_tag, + "status": status_str, + "status_reason": error_string} +trigger_next("BUILD-MONITOR", bm_data) + +sys.exit(exit_status) diff --git a/packaging/jenkins-scripts.spec b/packaging/jenkins-scripts.spec index 9b6a837..30936c3 100644 --- a/packaging/jenkins-scripts.spec +++ b/packaging/jenkins-scripts.spec @@ -138,6 +138,7 @@ fi %{destdir}/job_buildmonitor.py %{destdir}/job_update_nuget.py %{destdir}/job_add_git_tag.py +%{destdir}/job_repa.py %dir %{destdir}/templates %{destdir}/templates/index.html %{destdir}/job_update_local_git.py