diff options
author | Yves Duhem <yves.duhem@mongodb.com> | 2017-06-19 12:24:03 -0400 |
---|---|---|
committer | Yves Duhem <yves.duhem@mongodb.com> | 2017-06-21 15:25:48 -0400 |
commit | c6f39dd0e90169b252f87b28c4a01a934a06447b (patch) | |
tree | 727ce3334cd5c13ed16b3253513d17f9d2377ac8 /buildscripts | |
parent | 4201d8b14611387edfd448ba91c7195f9c6ec43c (diff) | |
download | mongo-c6f39dd0e90169b252f87b28c4a01a934a06447b.tar.gz |
SERVER-29639 New Python module to access evergreen.yml project configuration
Diffstat (limited to 'buildscripts')
-rw-r--r-- | buildscripts/tests/__init__.py | 0 | ||||
-rw-r--r-- | buildscripts/tests/ciconfig/__init__.py | 0 | ||||
-rw-r--r-- | buildscripts/tests/ciconfig/evergreen.yml | 148 | ||||
-rw-r--r-- | buildscripts/tests/ciconfig/test_evergreen.py | 177 |
4 files changed, 325 insertions, 0 deletions
diff --git a/buildscripts/tests/__init__.py b/buildscripts/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/buildscripts/tests/__init__.py diff --git a/buildscripts/tests/ciconfig/__init__.py b/buildscripts/tests/ciconfig/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/buildscripts/tests/ciconfig/__init__.py diff --git a/buildscripts/tests/ciconfig/evergreen.yml b/buildscripts/tests/ciconfig/evergreen.yml new file mode 100644 index 00000000000..e07d236a554 --- /dev/null +++ b/buildscripts/tests/ciconfig/evergreen.yml @@ -0,0 +1,148 @@ +functions: + "fetch source" : + - command: git.get_project + params: + directory: src + - command: shell.exec + params: + working_dir: src + script: | + echo "this is a 2nd command in the function!" + ls + "debug": + command: shell.exec + params: + script: | + echo "i am a debug function." + "run a task that fails" : + command: shell.exec + params: + working_dir: src + script: | + echo "this is a function with only a single command to run!" + ./run.py results fail + + "run a task that passes" : + command: shell.exec + params: + working_dir: src + script: | + ./run.py results pass + + "run a function with an arg": + command: shell.exec + params: + working_dir: src + script: | + echo "I was called with ${foobar}" + +pre: + command: shell.exec + params: + script: | + rm -rf src || true + echo "pre-task run. JUST ONE COMMAND" + +post: + - command: shell.exec + params: + script: | + echo "post-task run." + true + - command: attach.results + params: + file_location: src/results.json + +test_lifecycle_excluded_tasks: +- burn_in_tests +- no_lifecycle* + +tasks: +- name: compile + depends_on: [] + commands: + - func: "fetch source" + - func: "run a task that passes" + - func: "run a function with an arg" + vars: + foobar: "TESTING: ONE" + - func: "run a function with an arg" + vars: + foobar: "TESTING: TWO" + +- name: passing_test + depends_on: + - name: compile + commands: + - func: "fetch source" + - func: "run a task that passes" + +- name: failing_test + depends_on: + - name: compile + commands: + - func: "fetch source" + - func: "run a task that fails" + +- name: timeout_test + depends_on: + - name: compile + commands: + - func: "fetch source" + - command: shell.exec + timeout_secs: 20 + params: + working_dir: src + script: | + echo "this is going to timeout" + ./run.py timeout + +- name: no_lifecycle_task + depends_on: + - name: compile + commands: + - func: "fetch source" + - func: "do something incompatible with test lifecycle" +- name: resmoke_task + depends_on: + - name: compile + commands: + - func: "setup" + - func: "run tests" + vars: + resmoke_args: "--suites=somesuite --storageEngine=mmapv1" + + +modules: +- name: render-module + repo: git@github.com:evergreen-ci/render.git + prefix: modules + branch: master + +buildvariants: +- name: osx-108 + display_name: OSX + modules: ~ + run_on: + - localtestdistro + expansions: + num_jobs_available: 549 + tasks: + - name: compile + - name: passing_test + - name: failing_test + - name: timeout_test +- name: ubuntu + display_name: Ubuntu + batchtime: 1440 + modules: ["render-module"] + run_on: + - ubuntu1404-test + expansions: + test_flags: "--param=value --ubuntu" + tasks: + - name: compile + - name: passing_test + - name: failing_test + - name: timeout_test + - name: resmoke_task diff --git a/buildscripts/tests/ciconfig/test_evergreen.py b/buildscripts/tests/ciconfig/test_evergreen.py new file mode 100644 index 00000000000..0911bfa8e9f --- /dev/null +++ b/buildscripts/tests/ciconfig/test_evergreen.py @@ -0,0 +1,177 @@ +"""Unit tests for the buildscripts.ciconfig.evergreen module.""" + +from __future__ import absolute_import + +import datetime +import os +import unittest + +import buildscripts.ciconfig.evergreen as _evergreen + + +TEST_FILE_PATH = os.path.join(os.path.dirname(__file__), "evergreen.yml") + + +class TestEvergreenProjectConfig(unittest.TestCase): + """Unit tests for the Evergreen for the EvergreenProjectConfig class.""" + + @classmethod + def setUpClass(cls): + cls.conf = _evergreen.EvergreenProjectConfig(TEST_FILE_PATH) + + def test_invalid_path(self): + invalid_path = "non_existing_file" + with self.assertRaises(IOError): + _evergreen.EvergreenProjectConfig(invalid_path) + + def test_list_tasks(self): + self.assertEqual(6, len(self.conf.tasks)) + self.assertEqual(6, len(self.conf.task_names)) + self.assertIn("compile", self.conf.task_names) + self.assertIn("passing_test", self.conf.task_names) + self.assertIn("failing_test", self.conf.task_names) + self.assertIn("timeout_test", self.conf.task_names) + self.assertIn("no_lifecycle_task", self.conf.task_names) + self.assertIn("resmoke_task", self.conf.task_names) + + def test_list_lifecycle_task_names(self): + self.assertEqual(5, len(self.conf.lifecycle_task_names)) + self.assertIn("compile", self.conf.task_names) + self.assertIn("passing_test", self.conf.task_names) + self.assertIn("failing_test", self.conf.task_names) + self.assertIn("timeout_test", self.conf.task_names) + self.assertIn("resmoke_task", self.conf.task_names) + + def test_list_variants(self): + self.assertEqual(2, len(self.conf.variants)) + self.assertEqual(2, len(self.conf.variant_names)) + self.assertIn("osx-108", self.conf.variant_names) + self.assertIn("ubuntu", self.conf.variant_names) + + def test_get_variant(self): + variant = self.conf.get_variant("osx-108") + + self.assertIsNotNone(variant) + self.assertEqual("osx-108", variant.name) + + def test_list_distro_names(self): + self.assertEqual(2, len(self.conf.distro_names)) + self.assertIn("localtestdistro", self.conf.distro_names) + self.assertIn("ubuntu1404-test", self.conf.distro_names) + + +class TestTask(unittest.TestCase): + """Unit tests for the Task class.""" + + def test_from_dict(self): + task_dict = { + "name": "compile", + "depends_on": [], + "commands": [ + {"func": "fetch source"}, + {"func": "run a task that passes"}, + {"func": "run a function with an arg", + "vars": {"foobar": "TESTING: ONE"}}, + {"func": "run a function with an arg", + "vars": {"foobar": "TESTING: TWO"}}]} + task = _evergreen.Task(task_dict) + + self.assertEqual("compile", task.name) + self.assertEqual([], task.depends_on) + self.assertEqual(task_dict, task.raw) + + def test_resmoke_args(self): + task_dict = { + "name": "jsCore", + "commands": [ + {"func": "run tests", + "vars": {"resmoke_args": "--suites=core --shellWriteMode=commands"}}]} + task = _evergreen.Task(task_dict) + + self.assertEqual("--suites=core --shellWriteMode=commands", task.resmoke_args) + self.assertEqual("core", task.resmoke_suite) + + +class TestVariant(unittest.TestCase): + """Unit tests for the Variant class.""" + + @classmethod + def setUpClass(cls): + cls.conf = _evergreen.EvergreenProjectConfig(TEST_FILE_PATH) + + def test_from_dict(self): + task = _evergreen.Task({"name": "compile"}) + tasks_map = {task.name: task} + variant_dict = { + "name": "ubuntu", + "display_name": "Ubuntu", + "run_on": ["ubuntu1404-test"], + "tasks": [{"name": "compile"}], + } + variant = _evergreen.Variant(variant_dict, tasks_map) + + self.assertEqual("ubuntu", variant.name) + self.assertEqual("Ubuntu", variant.display_name) + self.assertEqual(["ubuntu1404-test"], variant.run_on) + self.assertEqual(1, len(variant.tasks)) + self.assertEqual("compile", variant.tasks[0].name) + + def test_display_name(self): + variant_ubuntu = self.conf.get_variant("ubuntu") + self.assertEqual("Ubuntu", variant_ubuntu.display_name) + + variant_osx = self.conf.get_variant("osx-108") + self.assertEqual("OSX", variant_osx.display_name) + + def test_batchtime(self): + variant_ubuntu = self.conf.get_variant("ubuntu") + batchtime = datetime.timedelta(minutes=1440) + self.assertEqual(batchtime, variant_ubuntu.batchtime) + + variant_osx = self.conf.get_variant("osx-108") + self.assertIsNone(variant_osx.batchtime) + + def test_modules(self): + variant_ubuntu = self.conf.get_variant("ubuntu") + self.assertEqual(["render-module"], variant_ubuntu.modules) + + variant_osx = self.conf.get_variant("osx-108") + self.assertEqual([], variant_osx.modules) + + def test_run_on(self): + variant_ubuntu = self.conf.get_variant("ubuntu") + self.assertEqual(["ubuntu1404-test"], variant_ubuntu.run_on) + + variant_osx = self.conf.get_variant("osx-108") + self.assertEqual(["localtestdistro"], variant_osx.run_on) + + def test_test_flags(self): + variant_ubuntu = self.conf.get_variant("ubuntu") + self.assertEqual("--param=value --ubuntu", variant_ubuntu.test_flags) + + variant_osx = self.conf.get_variant("osx-108") + self.assertIsNone(variant_osx.test_flags) + + def test_num_jobs_available(self): + variant_ubuntu = self.conf.get_variant("ubuntu") + self.assertIsNone(variant_ubuntu.num_jobs_available) + + variant_osx = self.conf.get_variant("osx-108") + self.assertEqual(549, variant_osx.num_jobs_available) + + def test_variant_tasks(self): + variant_ubuntu = self.conf.get_variant("ubuntu") + self.assertEqual(5, len(variant_ubuntu.tasks)) + for task_name in ["compile", "passing_test", "failing_test", + "timeout_test", "resmoke_task"]: + task = variant_ubuntu.get_task(task_name) + self.assertIsNotNone(task) + self.assertEqual(variant_ubuntu, task.variant) + self.assertIn(task_name, variant_ubuntu.task_names) + + resmoke_task = variant_ubuntu.get_task("resmoke_task") + self.assertEqual("--suites=somesuite --storageEngine=mmapv1 --param=value --ubuntu", + resmoke_task.combined_resmoke_args) + +if __name__ == "__main__": + unittest.main() |