put source target scratch into policy_data in make_task

This commit is contained in:
Yuming Zhu 2018-05-30 17:22:07 +08:00 committed by Mike McLean
parent ef977eaebb
commit 1b085035d9

View file

@ -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: