From e2c4c8e3178f92dea8b54fde877cbc1251ad9646 Mon Sep 17 00:00:00 2001 From: Wander Lairson Costa Date: Wed, 26 Nov 2014 10:11:32 -0800 Subject: [PATCH] Bug 1085505 part3: Add the "ci-tests" mach command r=lightsofapollo,garndt. The --task-id cli allows you to pass the task id of the correspondent build task. That's where the b2g image and test file are get from to run the tests. --HG-- extra : rebase_source : 8b781137abbd2e72d0cbbc256de571e6ec31448c extra : source : 12deaa98e57508737850bfb628b183c46e0efe85 --- testing/taskcluster/README.md | 4 ++ testing/taskcluster/mach_commands.py | 59 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/testing/taskcluster/README.md b/testing/taskcluster/README.md index d7b31375c618..ebb74b7c2e36 100644 --- a/testing/taskcluster/README.md +++ b/testing/taskcluster/README.md @@ -136,3 +136,7 @@ Creating only a build task and submitting to taskcluster: ```sh mach ci-build --revision=33c0181c4a25 --repository=http://hg.mozilla.org/mozilla-central --owner=user@domain.com tasks/builds/b2g_desktop.yml | taskcluster run-task --verbose ``` + +```sh +mach ci-tests --task-id=Mcnvz7wUR_SEMhmWb7cGdQ --owner=user@domain.com tasks/tests/b2g_mochitest.yml | taskcluster run-task --verbose +``` diff --git a/testing/taskcluster/mach_commands.py b/testing/taskcluster/mach_commands.py index d9e9318a50ce..369cf6871c06 100644 --- a/testing/taskcluster/mach_commands.py +++ b/testing/taskcluster/mach_commands.py @@ -11,6 +11,7 @@ import copy import datetime import subprocess import sys +import urllib2 import pystache import yaml @@ -89,6 +90,9 @@ def docker_image(name): return '{}/{}:{}'.format(repository, name, version) +def get_task(task_id): + return json.load(urllib2.urlopen("https://queue.taskcluster.net/v1/task/" + task_id)) + @CommandProvider class TryGraph(object): @Command('trygraph', category="ci", @@ -241,3 +245,58 @@ class CIBuild(object): taskcluster_graph.build_task.validate(build_task) print(json.dumps(build_task['task'], indent=4)) + +@CommandProvider +class CITest(object): + @Command('ci-test', category='ci', + description='Create taskcluster try server test task') + @CommandArgument('--task-id', + help='the task id to pick the correct build and tests') + @CommandArgument('--total-chunks', type=int, + help='total number of chunks') + @CommandArgument('--chunk', type=int, + help='current chunk') + @CommandArgument('--owner', + help='email address of who owns this graph') + @CommandArgument('test_task', + help='path to the test task definition') + def create_ci_test(self, test_task, task_id='', total_chunks=1, chunk=1, owner=''): + if total_chunks is None: + total_chunks = 1 + + if chunk is None: + chunk = 1 + + if chunk < 1 or chunk > total_chunks: + raise ValueError( + '"chunk" must be a value between 1 and "total_chunks (default 1)"') + + build_url, tests_url = self._get_build_and_tests_url(task_id) + + test_parameters = { + 'docker_image': docker_image, + 'build_url': ARTIFACT_URL.format(task_id, build_url), + 'tests_url': ARTIFACT_URL.format(task_id, tests_url), + 'total_chunks': total_chunks, + 'chunk': chunk, + 'owner': owner, + 'from_now': json_time_from_now, + 'now': current_json_time() + } + + try: + test_task = import_yaml(test_task, test_parameters) + except IOError: + sys.stderr.write( + "Could not load test task file. Ensure path is a relative " \ + "path from testing/taskcluster" + ) + sys.exit(1) + + print(json.dumps(test_task['task'], indent=4)) + + def _get_build_and_tests_url(self, task_id): + task = get_task(task_id) + locations = task['extra']['locations'] + return locations['build'], locations['tests'] +