Skip to content

Commit a1601dd

Browse files
author
Jonathan Abrahams
committed
SERVER-33963 Add task_groups & display_tasks for compile, compile_all, compile_unittests & unittests
1 parent 96f2a1a commit a1601dd

File tree

4 files changed

+469
-280
lines changed

4 files changed

+469
-280
lines changed

buildscripts/ciconfig/evergreen.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import yaml
1212

1313

14-
class EvergreenProjectConfig(object):
14+
class EvergreenProjectConfig(object): # pylint: disable=too-many-instance-attributes
1515
"""Represent an Evergreen project configuration file."""
1616

1717
def __init__(self, path):
@@ -21,8 +21,12 @@ def __init__(self, path):
2121
self.path = path
2222
self.tasks = [Task(task_dict) for task_dict in self._conf["tasks"]]
2323
self._tasks_by_name = {task.name: task for task in self.tasks}
24+
self.task_groups = [
25+
TaskGroup(task_group_dict) for task_group_dict in self._conf.get("task_groups", [])
26+
]
27+
self._task_groups_by_name = {task_group.name: task_group for task_group in self.task_groups}
2428
self.variants = [
25-
Variant(variant_dict, self._tasks_by_name)
29+
Variant(variant_dict, self._tasks_by_name, self._task_groups_by_name)
2630
for variant_dict in self._conf["buildvariants"]
2731
]
2832
self._variants_by_name = {variant.name: variant for variant in self.variants}
@@ -39,6 +43,15 @@ def get_task(self, task_name):
3943
"""Return the task with the given name as a Task instance."""
4044
return self._tasks_by_name.get(task_name)
4145

46+
@property
47+
def task_group_names(self):
48+
"""Get the list of task_group names."""
49+
return self._task_groups_by_name.keys()
50+
51+
def get_task_group(self, task_group_name):
52+
"""Return the task_group with the given name as a Task instance."""
53+
return self._task_groups_by_name.get(task_group_name)
54+
4255
@property
4356
def lifecycle_task_names(self):
4457
"""Get the list of names of the tasks that have not been excluded from test lifecycle."""
@@ -99,17 +112,45 @@ def __str__(self):
99112
return self.name
100113

101114

115+
class TaskGroup(object):
116+
"""Represent a task_group configuration as found in an Evergreen project configuration file."""
117+
118+
def __init__(self, conf_dict):
119+
"""Initialize a TaskGroup from a dictionary containing its configuration."""
120+
self.raw = conf_dict
121+
122+
@property
123+
def name(self):
124+
"""Get the task_group name."""
125+
return self.raw["name"]
126+
127+
@property
128+
def tasks(self):
129+
"""Get the list of task names for task_group."""
130+
return self.raw.get("tasks", [])
131+
132+
def __str__(self):
133+
return self.name
134+
135+
102136
class Variant(object):
103137
"""Build variant configuration as found in an Evergreen project configuration file."""
104138

105-
def __init__(self, conf_dict, task_map):
139+
def __init__(self, conf_dict, task_map, task_group_map):
106140
"""Initialize Variant."""
107141
self.raw = conf_dict
108142
run_on = self.run_on
109-
self.tasks = [
110-
VariantTask(task_map.get(t["name"]), t.get("distros", run_on), self)
111-
for t in conf_dict["tasks"]
112-
]
143+
self.tasks = []
144+
for task in conf_dict["tasks"]:
145+
task_name = task.get("name")
146+
if task_name in task_group_map:
147+
# A task in conf_dict may be a task_group, containing a list of tasks.
148+
for task_in_group in task_group_map.get(task_name).tasks:
149+
self.tasks.append(
150+
VariantTask(task_map.get(task_in_group), task.get("distros", run_on), self))
151+
else:
152+
self.tasks.append(
153+
VariantTask(task_map.get(task["name"]), task.get("distros", run_on), self))
113154
self.distro_names = set(run_on)
114155
for task in self.tasks:
115156
self.distro_names.update(task.run_on)

buildscripts/tests/ciconfig/evergreen.yml

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ functions:
99
script: |
1010
echo "this is a 2nd command in the function!"
1111
ls
12+
1213
"debug":
1314
command: shell.exec
1415
params:
1516
script: |
1617
echo "i am a debug function."
18+
1719
"run a task that fails" :
1820
command: shell.exec
1921
params:
@@ -36,19 +38,32 @@ functions:
3638
script: |
3739
echo "I was called with ${foobar}"
3840
39-
pre:
40-
command: shell.exec
41-
params:
42-
script: |
43-
rm -rf src || true
44-
echo "pre-task run. JUST ONE COMMAND"
41+
"do pre work":
42+
command: shell.exec
43+
params:
44+
script: |
45+
rm -rf src || true
46+
echo "pre-task run. JUST ONE COMMAND"
4547
46-
post:
47-
- command: shell.exec
48+
"do post work":
49+
command: shell.exec
4850
params:
4951
script: |
5052
echo "post-task run."
5153
true
54+
55+
"run timeout work":
56+
command: shell.exec
57+
params:
58+
script: |
59+
echo "timeout run."
60+
true
61+
62+
pre: &pre
63+
- func: "do pre work"
64+
65+
post:
66+
- func: "do post work"
5267
- command: attach.results
5368
params:
5469
file_location: src/results.json
@@ -57,6 +72,23 @@ test_lifecycle_excluded_tasks:
5772
- burn_in_tests
5873
- no_lifecycle*
5974

75+
task_groups:
76+
- name: tg_1
77+
max_hosts: 1
78+
tasks:
79+
- compile
80+
- passing_test
81+
setup_task:
82+
- func: "fetch source"
83+
teardown_task:
84+
- func: "debug"
85+
setup_group:
86+
*pre
87+
teardown_group:
88+
- func: "do post work"
89+
timeout:
90+
- func: "run timeout work"
91+
6092
tasks:
6193
- name: compile
6294
depends_on: []
@@ -154,3 +186,10 @@ buildvariants:
154186
- debian-stretch
155187
tasks:
156188
- name: resmoke_task
189+
- name: amazon
190+
display_name: Amazon
191+
run_on:
192+
- amazon
193+
tasks:
194+
- name: tg_1
195+
- name: timeout_test

buildscripts/tests/ciconfig/test_evergreen.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def test_list_tasks(self):
3535
self.assertIn("no_lifecycle_task", self.conf.task_names)
3636
self.assertIn("resmoke_task", self.conf.task_names)
3737

38+
def test_list_task_groups(self):
39+
self.assertEqual(1, len(self.conf.task_groups))
40+
self.assertEqual(1, len(self.conf.task_group_names))
41+
self.assertIn("tg_1", self.conf.task_group_names)
42+
3843
def test_list_lifecycle_task_names(self):
3944
self.assertEqual(5, len(self.conf.lifecycle_task_names))
4045
self.assertIn("compile", self.conf.task_names)
@@ -44,11 +49,12 @@ def test_list_lifecycle_task_names(self):
4449
self.assertIn("resmoke_task", self.conf.task_names)
4550

4651
def test_list_variants(self):
47-
self.assertEqual(3, len(self.conf.variants))
48-
self.assertEqual(3, len(self.conf.variant_names))
52+
self.assertEqual(4, len(self.conf.variants))
53+
self.assertEqual(4, len(self.conf.variant_names))
4954
self.assertIn("osx-108", self.conf.variant_names)
5055
self.assertIn("ubuntu", self.conf.variant_names)
5156
self.assertIn("debian", self.conf.variant_names)
57+
self.assertIn("amazon", self.conf.variant_names)
5258

5359
def test_get_variant(self):
5460
variant = self.conf.get_variant("osx-108")
@@ -57,11 +63,12 @@ def test_get_variant(self):
5763
self.assertEqual("osx-108", variant.name)
5864

5965
def test_list_distro_names(self):
60-
self.assertEqual(4, len(self.conf.distro_names))
66+
self.assertEqual(5, len(self.conf.distro_names))
6167
self.assertIn("localtestdistro", self.conf.distro_names)
6268
self.assertIn("ubuntu1404-test", self.conf.distro_names)
6369
self.assertIn("pdp-11", self.conf.distro_names)
6470
self.assertIn("debian-stretch", self.conf.distro_names)
71+
self.assertIn("amazon", self.conf.distro_names)
6572

6673

6774
class TestTask(unittest.TestCase):
@@ -95,6 +102,34 @@ def test_resmoke_args(self):
95102
self.assertEqual("core", task.resmoke_suite)
96103

97104

105+
class TestTaskGroup(unittest.TestCase):
106+
"""Unit tests for the TaskGroup class."""
107+
108+
def test_from_list(self):
109+
task_group_dict = {
110+
"name": "my_group", "max_hosts": 3, "tasks": ["task1", "task2"], "setup_task": [],
111+
"teardown_task": [], "setup_group": [], "teardown_group": [], "timeout": []
112+
}
113+
task_group = _evergreen.TaskGroup(task_group_dict)
114+
115+
self.assertEqual("my_group", task_group.name)
116+
self.assertEqual(2, len(task_group.tasks))
117+
self.assertEqual(task_group_dict, task_group.raw)
118+
119+
def test_resmoke_args(self):
120+
task_dict = {
121+
"name":
122+
"jsCore", "commands": [{
123+
"func": "run tests",
124+
"vars": {"resmoke_args": "--suites=core --shellWriteMode=commands"}
125+
}]
126+
}
127+
task = _evergreen.Task(task_dict)
128+
129+
self.assertEqual("--suites=core --shellWriteMode=commands", task.resmoke_args)
130+
self.assertEqual("core", task.resmoke_suite)
131+
132+
98133
class TestVariant(unittest.TestCase):
99134
"""Unit tests for the Variant class."""
100135

@@ -105,13 +140,14 @@ def setUpClass(cls):
105140
def test_from_dict(self):
106141
task = _evergreen.Task({"name": "compile"})
107142
tasks_map = {task.name: task}
143+
task_groups_map = {}
108144
variant_dict = {
109145
"name": "ubuntu",
110146
"display_name": "Ubuntu",
111147
"run_on": ["ubuntu1404-test"],
112148
"tasks": [{"name": "compile"}],
113149
}
114-
variant = _evergreen.Variant(variant_dict, tasks_map)
150+
variant = _evergreen.Variant(variant_dict, tasks_map, task_groups_map)
115151

116152
self.assertEqual("ubuntu", variant.name)
117153
self.assertEqual("Ubuntu", variant.display_name)
@@ -194,3 +230,8 @@ def test_variant_tasks(self):
194230
resmoke_task = variant_debian.get_task("resmoke_task")
195231
self.assertEqual("--suites=somesuite --storageEngine=mmapv1",
196232
resmoke_task.combined_resmoke_args)
233+
234+
# Check for tasks included in task_groups
235+
variant_amazon = self.conf.get_variant("amazon")
236+
self.assertEqual(3, len(variant_amazon.tasks))
237+
self.assertIn("compile", variant_amazon.task_names)

0 commit comments

Comments
 (0)