From 4b5805f9690097b180f03ea54a9429cb3648879c Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Wed, 4 Sep 2013 11:34:58 +0800 Subject: [PATCH] Make sure project exist in obs before submission Before commit code to obs, it should check whether these target projects specified in git-obs-mapping already exist in obs. If not, quit the submission. Change-Id: I238cce10e04ad2b5ad7ea0348a823aa718074b67 Signed-off-by: Lin Yang Reviewed-on: https://otctools.jf.intel.com/review/6123 Tested-by: OTC Tools Tester Reviewed-by: Eduard Bartosh --- job_submitobs.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/job_submitobs.py b/job_submitobs.py index d110b5e..adb2651 100755 --- a/job_submitobs.py +++ b/job_submitobs.py @@ -20,6 +20,7 @@ from common import obspkg from common import mapping from common.gerrit import Gerrit, get_gerrit_event from common.send_mail import prepare_mail +from common.buildservice import BuildService from gbp.rpm import parse_spec from gbp.git.repository import GitRepositoryError @@ -266,6 +267,15 @@ def parse_specfile(specfile, tmp_dir, prj_dir, packaging_dir, tag, event, \ return spec, tarball_dir +def check_obs_project(apiurl, apiuser, apipasswd, obs_prjs): + """check whether the specific project exist in obs + return the list of non-exist project + """ + + bs = BuildService(apiurl, apiuser, apipasswd) + + return [prj for prj in set(obs_prjs) if not bs.exists(prj)] + def main(): """script entry point""" @@ -352,6 +362,21 @@ def main(): if not obs_stg_prj: obs_stg_prj = obs_dst_prj + # check whether these projects specified in git-obs-mapping exist in obs + non_exist_prjs = check_obs_project(apiurl, apiuser, apipasswd, \ + [obs_dst_prj, obs_stg_prj]) + if non_exist_prjs: + # SYNC_GERRIT_HOSTNAME exists only on sync instances + if os.getenv('SYNC_GERRIT_HOSTNAME'): + # for sync instances we don't need to sync this obs project + continue + else: + # for normal instance it means configuration mistake in git->obs + # mapping + for prj in non_exist_prjs: + print "Project %s doesn't exist in OBS" % prj + return 1 + # search specfile under packaging directory specfile = find_specfile(prjdir, packagingdir, tag, event, tagger, \ obs_pkg) -- 2.7.4