2017-04-04 19:26:15 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
2018-04-04 19:22:42 +00:00
|
|
|
import pytest
|
2017-04-04 19:26:15 +00:00
|
|
|
|
2017-07-12 14:47:14 +00:00
|
|
|
from taskgraph import morph
|
|
|
|
from taskgraph.graph import Graph
|
|
|
|
from taskgraph.taskgraph import TaskGraph
|
|
|
|
from taskgraph.task import Task
|
2017-04-04 19:26:15 +00:00
|
|
|
|
|
|
|
from mozunit import main
|
|
|
|
|
|
|
|
|
2018-04-04 19:22:42 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def make_taskgraph():
|
|
|
|
def inner(tasks):
|
2017-08-15 15:37:40 +00:00
|
|
|
label_to_taskid = {k: k + '-tid' for k in tasks}
|
|
|
|
for label, task_id in label_to_taskid.iteritems():
|
|
|
|
tasks[label].task_id = task_id
|
|
|
|
graph = Graph(nodes=set(tasks), edges=set())
|
|
|
|
taskgraph = TaskGraph(tasks, graph)
|
|
|
|
return taskgraph, label_to_taskid
|
|
|
|
|
2018-04-04 19:22:42 +00:00
|
|
|
return inner
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_index_tasks(make_taskgraph):
|
|
|
|
task_def = {
|
|
|
|
'routes': [
|
|
|
|
"index.gecko.v2.mozilla-central.latest.firefox-l10n.linux64-opt.es-MX",
|
|
|
|
"index.gecko.v2.mozilla-central.latest.firefox-l10n.linux64-opt.fy-NL",
|
|
|
|
"index.gecko.v2.mozilla-central.latest.firefox-l10n.linux64-opt.sk",
|
|
|
|
"index.gecko.v2.mozilla-central.latest.firefox-l10n.linux64-opt.sl",
|
|
|
|
"index.gecko.v2.mozilla-central.latest.firefox-l10n.linux64-opt.uk",
|
|
|
|
"index.gecko.v2.mozilla-central.latest.firefox-l10n.linux64-opt.zh-CN",
|
|
|
|
"index.gecko.v2.mozilla-central.pushdate."
|
|
|
|
"2017.04.04.20170404100210.firefox-l10n.linux64-opt.es-MX",
|
|
|
|
"index.gecko.v2.mozilla-central.pushdate."
|
|
|
|
"2017.04.04.20170404100210.firefox-l10n.linux64-opt.fy-NL",
|
|
|
|
"index.gecko.v2.mozilla-central.pushdate."
|
|
|
|
"2017.04.04.20170404100210.firefox-l10n.linux64-opt.sk",
|
|
|
|
"index.gecko.v2.mozilla-central.pushdate."
|
|
|
|
"2017.04.04.20170404100210.firefox-l10n.linux64-opt.sl",
|
|
|
|
"index.gecko.v2.mozilla-central.pushdate."
|
|
|
|
"2017.04.04.20170404100210.firefox-l10n.linux64-opt.uk",
|
|
|
|
"index.gecko.v2.mozilla-central.pushdate."
|
|
|
|
"2017.04.04.20170404100210.firefox-l10n.linux64-opt.zh-CN",
|
|
|
|
"index.gecko.v2.mozilla-central.revision."
|
|
|
|
"b5d8b27a753725c1de41ffae2e338798f3b5cacd.firefox-l10n.linux64-opt.es-MX",
|
|
|
|
"index.gecko.v2.mozilla-central.revision."
|
|
|
|
"b5d8b27a753725c1de41ffae2e338798f3b5cacd.firefox-l10n.linux64-opt.fy-NL",
|
|
|
|
"index.gecko.v2.mozilla-central.revision."
|
|
|
|
"b5d8b27a753725c1de41ffae2e338798f3b5cacd.firefox-l10n.linux64-opt.sk",
|
|
|
|
"index.gecko.v2.mozilla-central.revision."
|
|
|
|
"b5d8b27a753725c1de41ffae2e338798f3b5cacd.firefox-l10n.linux64-opt.sl",
|
|
|
|
"index.gecko.v2.mozilla-central.revision."
|
|
|
|
"b5d8b27a753725c1de41ffae2e338798f3b5cacd.firefox-l10n.linux64-opt.uk",
|
|
|
|
"index.gecko.v2.mozilla-central.revision."
|
|
|
|
"b5d8b27a753725c1de41ffae2e338798f3b5cacd.firefox-l10n.linux64-opt.zh-CN"
|
|
|
|
],
|
|
|
|
'deadline': 'soon',
|
|
|
|
'metadata': {
|
|
|
|
'description': 'desc',
|
|
|
|
'owner': 'owner@foo.com',
|
|
|
|
'source': 'https://source',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
task = Task(kind='test', label='a', attributes={}, task=task_def)
|
|
|
|
docker_task = Task(kind='docker-image', label='build-docker-image-index-task',
|
|
|
|
attributes={}, task={})
|
|
|
|
taskgraph, label_to_taskid = make_taskgraph({
|
|
|
|
task.label: task,
|
|
|
|
docker_task.label: docker_task,
|
|
|
|
})
|
|
|
|
|
|
|
|
index_task = morph.make_index_task(task, taskgraph, label_to_taskid)
|
|
|
|
|
|
|
|
assert index_task.task['payload']['command'][0] == 'insert-indexes.js'
|
|
|
|
assert index_task.task['payload']['env']['TARGET_TASKID'] == 'a-tid'
|
|
|
|
|
|
|
|
# check the scope summary
|
|
|
|
assert index_task.task['scopes'] == ['index:insert-task:gecko.v2.mozilla-central.*']
|
|
|
|
|
|
|
|
|
|
|
|
TASKS = [
|
|
|
|
{
|
|
|
|
'kind': 'build',
|
|
|
|
'label': 'a',
|
|
|
|
'attributes': {},
|
|
|
|
'task': {
|
|
|
|
'extra': {
|
|
|
|
'treeherder': {
|
|
|
|
'group': 'tc',
|
|
|
|
'symbol': 'B'
|
|
|
|
}
|
2017-04-04 19:26:15 +00:00
|
|
|
},
|
2018-04-04 19:22:42 +00:00
|
|
|
'payload': {
|
|
|
|
'env': {
|
|
|
|
'FOO': 'BAR'
|
2017-08-15 15:37:40 +00:00
|
|
|
}
|
2018-04-04 19:22:42 +00:00
|
|
|
},
|
|
|
|
'tags': {
|
|
|
|
'kind': 'build'
|
2017-08-15 15:37:40 +00:00
|
|
|
}
|
2018-04-04 19:22:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'kind': 'test',
|
|
|
|
'label': 'b',
|
|
|
|
'attributes': {},
|
|
|
|
'task': {
|
|
|
|
'extra': {
|
2017-12-13 21:16:09 +00:00
|
|
|
'suite': {'name': 'talos'},
|
2018-04-04 19:22:42 +00:00
|
|
|
'treeherder': {
|
|
|
|
'group': 'tc',
|
|
|
|
'symbol': 't'
|
2017-08-15 15:37:40 +00:00
|
|
|
}
|
2017-11-07 15:22:35 +00:00
|
|
|
},
|
2018-04-04 19:22:42 +00:00
|
|
|
'payload': {
|
2017-11-07 15:22:35 +00:00
|
|
|
'env': {
|
2018-04-04 19:22:42 +00:00
|
|
|
'FOO': 'BAR'
|
2017-11-07 15:22:35 +00:00
|
|
|
}
|
|
|
|
},
|
2018-04-04 19:22:42 +00:00
|
|
|
'tags': {
|
|
|
|
'kind': 'test'
|
|
|
|
}
|
2017-11-07 15:22:35 +00:00
|
|
|
}
|
2018-04-04 19:22:42 +00:00
|
|
|
},
|
|
|
|
]
|
2017-08-25 19:24:22 +00:00
|
|
|
|
|
|
|
|
2018-04-04 19:22:42 +00:00
|
|
|
@pytest.fixture
|
2017-12-13 21:16:09 +00:00
|
|
|
def get_morphed(make_taskgraph):
|
|
|
|
def inner(try_task_config, tasks=None):
|
|
|
|
tasks = tasks or TASKS
|
|
|
|
taskgraph = make_taskgraph({
|
|
|
|
t['label']: Task(**t) for t in tasks[:]
|
|
|
|
})
|
2018-04-04 19:22:42 +00:00
|
|
|
|
2017-11-07 15:22:35 +00:00
|
|
|
fn = morph.apply_jsone_templates(try_task_config)
|
2018-04-04 19:22:42 +00:00
|
|
|
return fn(*taskgraph)[0]
|
|
|
|
return inner
|
|
|
|
|
|
|
|
|
|
|
|
def test_template_artifact(get_morphed):
|
|
|
|
morphed = get_morphed({
|
|
|
|
'templates': {
|
|
|
|
'artifact': {'enabled': 1}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert len(morphed.tasks) == 2
|
|
|
|
|
|
|
|
for t in morphed.tasks.values():
|
|
|
|
if t.kind == 'build':
|
|
|
|
assert t.task['extra']['treeherder']['group'] == 'tc'
|
|
|
|
assert t.task['extra']['treeherder']['symbol'] == 'Ba'
|
|
|
|
assert t.task['payload']['env']['USE_ARTIFACT'] == 1
|
|
|
|
else:
|
|
|
|
assert t.task['extra']['treeherder']['group'] == 'tc'
|
|
|
|
assert t.task['extra']['treeherder']['symbol'] == 't'
|
|
|
|
assert 'USE_ARTIFACT' not in t.task['payload']['env']
|
|
|
|
|
|
|
|
|
|
|
|
def test_template_env(get_morphed):
|
|
|
|
morphed = get_morphed({
|
|
|
|
'templates': {
|
|
|
|
'env': {
|
|
|
|
'ENABLED': 1,
|
|
|
|
'FOO': 'BAZ',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert len(morphed.tasks) == 2
|
|
|
|
for t in morphed.tasks.values():
|
|
|
|
assert len(t.task['payload']['env']) == 2
|
|
|
|
assert t.task['payload']['env']['ENABLED'] == 1
|
|
|
|
assert t.task['payload']['env']['FOO'] == 'BAZ'
|
|
|
|
|
|
|
|
morphed = get_morphed({
|
|
|
|
'templates': {
|
|
|
|
'env': {
|
|
|
|
'ENABLED': 0,
|
|
|
|
'FOO': 'BAZ',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert len(morphed.tasks) == 2
|
|
|
|
for t in morphed.tasks.values():
|
|
|
|
assert len(t.task['payload']['env']) == 2
|
|
|
|
assert t.task['payload']['env']['ENABLED'] == 0
|
|
|
|
assert t.task['payload']['env']['FOO'] == 'BAZ'
|
|
|
|
|
|
|
|
|
|
|
|
def test_template_rebuild(get_morphed):
|
|
|
|
morphed = get_morphed({
|
|
|
|
'tasks': ['b'],
|
|
|
|
'templates': {
|
|
|
|
'rebuild': 4,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
tasks = morphed.tasks.values()
|
|
|
|
assert len(tasks) == 2
|
|
|
|
|
|
|
|
for t in tasks:
|
|
|
|
if t.label == 'a':
|
|
|
|
assert 'task_duplicates' not in t.attributes
|
|
|
|
elif t.label == 'b':
|
|
|
|
assert 'task_duplicates' in t.attributes
|
|
|
|
assert t.attributes['task_duplicates'] == 4
|
2017-11-07 15:22:35 +00:00
|
|
|
|
2017-06-15 16:10:59 +00:00
|
|
|
|
2017-12-13 21:16:09 +00:00
|
|
|
@pytest.mark.parametrize('command', (
|
|
|
|
['foo --bar'],
|
|
|
|
['foo', '--bar'],
|
|
|
|
[['foo']],
|
|
|
|
[['foo', '--bar']],
|
|
|
|
))
|
|
|
|
def test_template_talos_profile(get_morphed, command):
|
|
|
|
tasks = TASKS[:]
|
|
|
|
for t in tasks:
|
|
|
|
t['task']['payload']['command'] = command
|
|
|
|
|
|
|
|
morphed = get_morphed({
|
|
|
|
'templates': {
|
|
|
|
'talos-profile': True,
|
|
|
|
}
|
|
|
|
}, tasks)
|
|
|
|
|
|
|
|
for t in morphed.tasks.values():
|
|
|
|
command = t.task['payload']['command']
|
|
|
|
if isinstance(command[0], list):
|
|
|
|
command = command[0]
|
|
|
|
command = ' '.join(command)
|
|
|
|
|
|
|
|
if t.label == 'a':
|
|
|
|
assert not command.endswith('--geckoProfile')
|
|
|
|
elif t.label == 'b':
|
|
|
|
assert command.endswith('--geckoProfile')
|
|
|
|
|
|
|
|
|
2017-04-04 19:26:15 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|