From ec43bbd53ec1f1bdd958d964cd54e93e2aec0032 Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Jun 06 2018 09:47:59 +0000 Subject: [PATCH 1/3] put source target scratch into policy_data in make_task --- diff --git a/hub/kojihub.py b/hub/kojihub.py index d02dc8d..ad9ac50 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -54,6 +54,7 @@ import koji.db import koji.plugin import koji.policy import koji.xmlrpcplus +import koji.tasks from koji.context import context from koji.util import dslice from koji.util import md5_constructor @@ -514,18 +515,53 @@ def make_task(method, arglist, **opts): if 'channel' in opts: policy_data['req_channel'] = opts['channel'] req_channel_id = get_channel_id(opts['channel'], strict=True) - if method == 'build': - # arglist = source, target, [opts] - args = koji.decode_args2(arglist, ('source', 'target', 'opts')) - policy_data['source'] = args['source'] - if args['target'] is None: - #koji-shadow makes null-target builds - policy_data['target'] = None - else: - target = get_build_target(args['target'], strict=True) - policy_data['target'] = target['name'] - t_opts = args.get('opts', {}) + params = {} + try: + params = koji.tasks.parse_task_params(method, arglist) + except TypeError: + logger.warning("%s is not a standard koji task", method) + except koji.ParameterError: + logger.warning("Cannot parse parameters: %s of %s task", arglist, method) + except Exception: + logger.warning("Unexcepted error occurs when parsing parameters: %s of %s task", + arglist, method, exc_info=True) + if params: + # do not check newRepo task + if method != 'newRepo': + # src is the common signature of source + # spec_url for wrapperRPM task + # url for buildSRPMFromSCM, maven, etc + for k in ('src', 'spec_url', 'url'): + if k in params: + policy_data['source'] = params.get(k) + break + target = None + hastarget = False + # target(str) is the common signature + # build_target(dict) for wrapperRPM task + # target_info(dict) for some image tasks + for k in ('target', 'build_target', 'target_info'): + if k in params: + target = params.get(k) + hastarget = True + break + if hastarget: + if target is None: + policy_data['target'] = None + elif isinstance(target, dict): + if 'name' not in target: + hastarget = False + logger.warning("Bad build target: %s. It should contain " + "valid key: 'name'. Skipping putting " + "target into channel policy data", target) + else: + target = target.get('name') + if hastarget: + policy_data['target'] = get_build_target(target, strict=True)['name'] + t_opts = params.get('opts', {}) policy_data['scratch'] = t_opts.get('scratch', False) + else: + logger.warning("Proceeding with less data in channel policy.") ruleset = context.policy.get('channel') result = ruleset.apply(policy_data) if result is None: From 297986d83e5061eec2f38dadff369bd36690b748 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Jun 27 2018 18:58:05 +0000 Subject: [PATCH 2/3] drop redundant warning --- diff --git a/hub/kojihub.py b/hub/kojihub.py index ad9ac50..5242c45 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -560,8 +560,7 @@ def make_task(method, arglist, **opts): policy_data['target'] = get_build_target(target, strict=True)['name'] t_opts = params.get('opts', {}) policy_data['scratch'] = t_opts.get('scratch', False) - else: - logger.warning("Proceeding with less data in channel policy.") + ruleset = context.policy.get('channel') result = ruleset.apply(policy_data) if result is None: From 04346d24344725b83a5f39ba8a4a1390034db55d Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Jun 28 2018 14:57:25 +0000 Subject: [PATCH 3/3] minor adjustments for readability --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 5242c45..cc14732 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -526,20 +526,17 @@ def make_task(method, arglist, **opts): logger.warning("Unexcepted error occurs when parsing parameters: %s of %s task", arglist, method, exc_info=True) if params: - # do not check newRepo task - if method != 'newRepo': - # src is the common signature of source - # spec_url for wrapperRPM task - # url for buildSRPMFromSCM, maven, etc - for k in ('src', 'spec_url', 'url'): - if k in params: - policy_data['source'] = params.get(k) - break + # parameters that indicate source for build + for k in ('src', 'spec_url', 'url'): + if method == 'newRepo': + # newRepo has a 'src' parameter that means something else + break + if k in params: + policy_data['source'] = params.get(k) + break + # parameters that indicate build target target = None hastarget = False - # target(str) is the common signature - # build_target(dict) for wrapperRPM task - # target_info(dict) for some image tasks for k in ('target', 'build_target', 'target_info'): if k in params: target = params.get(k) @@ -551,9 +548,7 @@ def make_task(method, arglist, **opts): elif isinstance(target, dict): if 'name' not in target: hastarget = False - logger.warning("Bad build target: %s. It should contain " - "valid key: 'name'. Skipping putting " - "target into channel policy data", target) + logger.warning("Bad build target parameter: %r", target) else: target = target.get('name') if hastarget: