Automatically provide 'name' to project templates
Provide the short name of a project (anything after the last '/') to project templates as the variable 'name'. If 'openstack/nova' invoked a template, the variable 'name' would automatically be set to 'nova' within the template. Ideally this means that most template invocations in OpenStack's layout will not need any variables defined. Change-Id: I596744917c30c92041b8ea5b1f518d50fb64e59b
This commit is contained in:
parent
3e98c02eba
commit
aea6cf6487
|
@ -634,8 +634,11 @@ key::
|
|||
- name: plugin-triggering
|
||||
jobprefix: plugin-foobar
|
||||
|
||||
You can pass several parameters to a template. A ``parameter`` value will be
|
||||
used for expansion of ``{parameter}`` in the template strings.
|
||||
You can pass several parameters to a template. A ``parameter`` value
|
||||
will be used for expansion of ``{parameter}`` in the template
|
||||
strings. The parameter ``name`` will be automatically provided and
|
||||
will contain the short name of the project, that is the portion of the
|
||||
project name after the last ``/`` character.
|
||||
|
||||
Multiple templates can be combined in a project, and the jobs from all
|
||||
of those templates will be added to the project. Individual jobs may
|
||||
|
|
|
@ -112,14 +112,14 @@ project-templates:
|
|||
- '{projectname}-test2'
|
||||
- name: test-three-and-four
|
||||
check:
|
||||
- '{projectname}-test3'
|
||||
- '{projectname}-test4'
|
||||
- '{name}-test3'
|
||||
- '{name}-test4'
|
||||
- name: test-five
|
||||
check:
|
||||
- '{projectname}-test5'
|
||||
- '{name}-{something}-test5'
|
||||
- name: test-five-also
|
||||
check:
|
||||
- '{projectname}-test5'
|
||||
- '{name}-{something}-test5'
|
||||
|
||||
projects:
|
||||
- name: org/project
|
||||
|
@ -213,11 +213,10 @@ projects:
|
|||
- name: test-one-and-two
|
||||
projectname: project
|
||||
- name: test-three-and-four
|
||||
projectname: project
|
||||
- name: test-five
|
||||
projectname: project
|
||||
something: foo
|
||||
- name: test-five-also
|
||||
projectname: project
|
||||
something: foo
|
||||
check:
|
||||
- project-test6
|
||||
|
||||
|
|
|
@ -1971,14 +1971,14 @@ class TestScheduler(testtools.TestCase):
|
|||
'SUCCESS')
|
||||
self.assertEqual(self.getJobFromHistory('project-test2').result,
|
||||
'SUCCESS')
|
||||
self.assertEqual(self.getJobFromHistory('project-test3').result,
|
||||
'SUCCESS')
|
||||
self.assertEqual(self.getJobFromHistory('project-test4').result,
|
||||
'SUCCESS')
|
||||
# project-test5 should run twice because two templates define it
|
||||
self.assertEqual(self.getJobFromHistory('layered-project-test3'
|
||||
).result, 'SUCCESS')
|
||||
self.assertEqual(self.getJobFromHistory('layered-project-test4'
|
||||
).result, 'SUCCESS')
|
||||
# test5 should run twice because two templates define it
|
||||
test5_count = 0
|
||||
for job in self.worker.build_history:
|
||||
if job.name == 'project-test5':
|
||||
if job.name == 'layered-project-foo-test5':
|
||||
test5_count += 1
|
||||
self.assertEqual(job.result, 'SUCCESS')
|
||||
self.assertEqual(test5_count, 2)
|
||||
|
|
|
@ -156,6 +156,9 @@ class LayoutSchema(object):
|
|||
# Craft the templates schemas
|
||||
schema = {v.Required('name'): v.Any(*template_names)}
|
||||
for required_param in template_parameters:
|
||||
# special case 'name' which will be automatically provided
|
||||
if required_param == 'name':
|
||||
continue
|
||||
# add this template parameters as requirements:
|
||||
schema.update({v.Required(required_param): str})
|
||||
|
||||
|
|
|
@ -286,6 +286,7 @@ class Scheduler(threading.Thread):
|
|||
|
||||
for config_project in data.get('projects', []):
|
||||
project = Project(config_project['name'])
|
||||
shortname = config_project['name'].split('/')[-1]
|
||||
|
||||
# This is reversed due to the prepend operation below, so
|
||||
# the ultimate order is templates (in order) followed by
|
||||
|
@ -296,6 +297,7 @@ class Scheduler(threading.Thread):
|
|||
tpl = project_templates.get(
|
||||
requested_template.get('name'))
|
||||
# Expand it with the project context
|
||||
requested_template['name'] = shortname
|
||||
expanded = deep_format(tpl, requested_template)
|
||||
# Finally merge the expansion with whatever has been
|
||||
# already defined for this project. Prepend our new
|
||||
|
|
Loading…
Reference in New Issue