Add zuul legacy vars filter

Change-Id: I087bd0de3356a8606fe40d4762e620e4d465a719
This commit is contained in:
James E. Blair 2017-09-13 16:19:56 -06:00 committed by Monty Taylor
parent d6d9144a0e
commit a6a4555896
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
3 changed files with 72 additions and 0 deletions

View File

@ -24,6 +24,12 @@
- zuul.project.canonical_name == 'review.example.com/org/project'
- zuul.project.src_dir == 'src/review.example.com/org/project'
- name: Assert legacy zuul vars are valid
assert:
that:
- zuul.project.name == '{{ (zuul | zuul_legacy_vars).ZUUL_PROJECT }}'
- zuul.branch == '{{ (zuul | zuul_legacy_vars).ZUUL_BRANCH }}'
- debug:
msg: "vartest secret {{ vartest_secret }}"

View File

@ -0,0 +1,63 @@
# Copyright 2017 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
def zuul_legacy_vars(zuul):
# omitted:
# ZUUL_URL
# ZUUL_REF
# ZUUL_COMMIT
short_name = zuul['project']['name'].split('/')[-1]
params = dict(ZUUL_UUID=zuul['build'],
ZUUL_PROJECT=zuul['project']['name'],
ZUUL_SHORT_PROJECT_NAME=short_name,
ZUUL_PIPELINE=zuul['pipeline'],
ZUUL_VOTING=zuul['voting'],
WORKSPACE='/home/zuul')
if 'branch' in zuul:
params['ZUUL_BRANCH'] = zuul['branch']
if 'change' in zuul:
changes_str = '^'.join(
['%s:%s:refs/changes/%s/%s/%s' % (
i['project']['name'],
i['branch'],
str(i['change'])[:-2:],
i['change'],
i['patchset'])
for i in zuul['items']])
params['ZUUL_CHANGES'] = changes_str
change_ids = ' '.join(['%s,%s' % (i['change'], i['patchset'])
for i in zuul['items']])
params['ZUUL_CHANGE_IDS'] = change_ids
params['ZUUL_CHANGE'] = str(zuul['change'])
params['ZUUL_PATCHSET'] = str(zuul['patchset'])
if 'newrev' in zuul or 'oldrev' in zuul:
params['ZUUL_REFNAME'] = zuul['ref']
params['ZUUL_OLDREV'] = zuul.get('oldrev', '0' * 40)
params['ZUUL_NEWREV'] = zuul.get('newrev', '0' * 40)
params['TOX_TESTENV_PASSENV'] = ' '.join(params.keys())
return params
class FilterModule(object):
def filters(self):
return {
'zuul_legacy_vars': zuul_legacy_vars,
}

View File

@ -567,6 +567,7 @@ class ExecutorServer(object):
self.action_dir = os.path.join(plugin_dir, 'action')
self.callback_dir = os.path.join(plugin_dir, 'callback')
self.lookup_dir = os.path.join(plugin_dir, 'lookup')
self.filter_dir = os.path.join(plugin_dir, 'filter')
_copy_ansible_files(zuul.ansible, plugin_dir)
@ -1446,6 +1447,8 @@ class AnsibleJob(object):
config.write('command_warnings = False\n')
config.write('callback_plugins = %s\n' % callback_path)
config.write('stdout_callback = zuul_stream\n')
config.write('filter_plugins = %s\n'
% self.executor_server.filter_dir)
# bump the timeout because busy nodes may take more than
# 10s to respond
config.write('timeout = 30\n')