From 2533a4c69a441b964068625953fd385a38d3a608 Mon Sep 17 00:00:00 2001 From: hyokeun Date: Tue, 10 Oct 2017 21:55:50 +0900 Subject: [PATCH] TPE-377 Block group submit if previous SR is already accepted or rejected Change-Id: If07b53522c2cd03ff3542dd287a59eff6424b0b5 --- common/workflow.py | 40 ++++++++++++++++++++++++++++++++++++++++ job_submit.py | 14 +++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/common/workflow.py b/common/workflow.py index a62d499..bbbbb9f 100644 --- a/common/workflow.py +++ b/common/workflow.py @@ -46,6 +46,8 @@ from gbp.rpm import SpecFile from gbp.git.repository import GitRepositoryError from gbp.errors import GbpError +from common import buildmonitor_db + # set default char-set endcoding to utf-8 reload(sys) sys.setdefaultencoding('utf-8') # pylint: disable-msg=E1101 @@ -84,6 +86,10 @@ NOT_ANNOTATED_MSG = '- Tag should be annotated tag.' SUGGESTION = 'Suggest to use "gbs submit" to trigger submission\n'\ +SR_PROCESS_FINISHED_MSG = '- Submit blocked due to group SR(%s) already been %s.\n'\ + ' Please refer to %s.\n'\ + ' Or re-submit with another tag if needed.' + class MailSender(object): email_title = '' email_head = '' @@ -756,6 +762,40 @@ def get_manifest_filelists_snapshot(profile, request_url, timeout=5, group=None) return results +def get_sr_process_status(sr): + + if os.getenv("BUILDMONITOR_ENABLED", "0") != "1": + return None + + buildmonitor_db.connect_db() + query = "SELECT ssd.obs_request_status, sc.git_repository, sc.sr_submitter " \ + "FROM sr_status s, sr_status_detail ssd, sr_commit sc " \ + "WHERE s.sr=%s " \ + "AND s.id = ssd.sr_status_id " \ + "AND s.id = sc.sr_status_id"; + ret_data = buildmonitor_db.get_multi_values_from_query_data(query, (sr,)) + buildmonitor_db.disconnect_db() + + message = None + repos = [] + submitters = [] + sr_decision = None + for row in ret_data: + if type(row) != tuple or len(row) <= 1: continue + if row[0] == "A": + sr_decision = "Accepted" + elif row[0] == "R": + sr_decision = "Rejected" + else: + continue + repos.append("%s" % row[1]) + submitters.append("%s" % row[2].strip()) + + if sr_decision is not None: + message = SR_PROCESS_FINISHED_MSG % (sr, sr_decision, repos) + '\n\n' + + return message + if __name__ == '__main__': print 'Non-executable module' sys.exit(0) diff --git a/job_submit.py b/job_submit.py index a4f6a4e..46f6acd 100755 --- a/job_submit.py +++ b/job_submit.py @@ -53,7 +53,7 @@ from gbp.rpm import SpecFile from gbp.git.repository import GitRepositoryError from gbp.errors import GbpError -from common.workflow import create_project, find_submit_tag, check_tag_format, find_specfile, parse_specfile +from common.workflow import create_project, find_submit_tag, check_tag_format, find_specfile, parse_specfile, get_sr_process_status # set default char-set endcoding to utf-8 reload(sys) @@ -234,6 +234,18 @@ def entry_github(option): def entry(option): print option if len(option) > 2 and option[2] == 'bypass': + + # Check BUILD-MONITOR DB + my_tag = os.getenv('GERRIT_REFNAME').replace('refs/tags/', '') + reas = get_sr_process_status(my_tag) + print reas + if reas is not None: + print 'Your SR process already completed' + send_mail(TITLE_FAILED % (my_tag, os.getenv('GERRIT_PROJECT')), \ + reas, {'author': os.getenv('GERRIT_EVENT_ACCOUNT_NAME'), \ + 'email':os.getenv('GERRIT_EVENT_ACCOUNT_EMAIL')}) + return + print '\n** Forward %s to group routine' % os.getenv('GERRIT_REFNAME') with open('PRE-RELEASE-SUBMIT-GROUP_%d.env' % int(os.getenv('BUILD_NUMBER')), 'w') as info_f: for x in ['EVENT_TYPE', 'EVENT_HASH', 'REFNAME', 'PROJECT', 'OLDREV', 'NEWREV', \ -- 2.7.4