From 118aa9c6a42c320d1fc2f53c2bcab3a0ca3ae46c Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Aug 13 2018 20:53:00 +0000 Subject: put source target scratch into policy_data in make_task --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 4d53b1b..31bd6fd 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: