Bug 1370343 - Update mochitest actions to be up to the new spec draft
authorBrian Stack <bstack@mozilla.com>
Wed, 09 Aug 2017 16:30:07 -0700
changeset 643656 7c17fa2884b3b08791da2d5289bb9bad0c89713a
parent 643655 c103399d42f1a2992a809d379eb31fa85c9ea8fb
child 643657 a70ce1dfc232393085cd83a1be3a1a5202c58a6d
push id73171
push userbstack@mozilla.com
push dateThu, 10 Aug 2017 00:47:17 +0000
bugs1370343
milestone57.0a1
Bug 1370343 - Update mochitest actions to be up to the new spec MozReview-Commit-ID: ItpfzhvqnN5
taskcluster/taskgraph/actions/test-retrigger-action.py
--- a/taskcluster/taskgraph/actions/test-retrigger-action.py
+++ b/taskcluster/taskgraph/actions/test-retrigger-action.py
@@ -1,40 +1,37 @@
 # -*- coding: utf-8 -*-
 
 # 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
 
-import copy
 import json
 import logging
 
-import requests
 from slugid import nice as slugid
 
+from .util import (find_decision_task, create_task)
 from .registry import register_callback_action
-from taskgraph.create import create_task
-from taskgraph.util.time import (
-    current_json_time,
-    json_time_from_now
-)
+from taskgraph.util.taskcluster import get_artifact
+from taskgraph.util.parameterization import resolve_task_references
+from taskgraph.taskgraph import TaskGraph
 
 TASKCLUSTER_QUEUE_URL = "https://queue.taskcluster.net/v1/task"
 
 logger = logging.getLogger(__name__)
 
 
 @register_callback_action(
-    name='run-with-options',
-    title='Schedule test retrigger',
+    name='retrigger-mochitest-reftest-with-options',
+    title='Mochitest/Reftest Retrigger',
     symbol='tr',
-    description="Retriggers the specified test job with additional options",
+    description="Retriggers the specified mochitest/reftest job with additional options",
     context=[{'test-type': 'mochitest'},
              {'test-type': 'reftest'}],
     order=0,
     schema={
         'type': 'object',
         'properties': {
             'path': {
                 'type': 'string',
@@ -64,40 +61,46 @@ logger = logging.getLogger(__name__)
                 'title': 'Run tests N times',
                 'description': ('Run tests repeatedly (usually used in '
                                 'conjunction with runUntilFail)')
             },
             'environment': {
                 'type': 'object',
                 'default': {'MOZ_LOG': ''},
                 'title': 'Extra environment variables',
-                'description': 'Extra environment variables to use for this run'
+                'description': 'Extra environment variables to use for this run',
+                'additionalProperties': {'type': 'string'}
             },
             'preferences': {
                 'type': 'object',
                 'default': {'mygeckopreferences.pref': 'myvalue2'},
                 'title': 'Extra gecko (about:config) preferences',
-                'description': 'Extra gecko (about:config) preferences to use for this run'
+                'description': 'Extra gecko (about:config) preferences to use for this run',
+                'additionalProperties': {'type': 'string'}
             }
         },
         'additionalProperties': False,
         'required': ['path']
     }
 )
-def test_retrigger_action(parameters, input, task_group_id, task_id, task):
-    new_task_definition = copy.copy(task)
+def mochitest_retrigger_action(parameters, input, task_group_id, task_id, task):
+    decision_task_id = find_decision_task(parameters)
+
+    full_task_graph = get_artifact(decision_task_id, "public/full-task-graph.json")
+    _, full_task_graph = TaskGraph.from_json(full_task_graph)
+    label_to_taskid = get_artifact(decision_task_id, "public/label-to-taskid.json")
 
-    # set new created, deadline, and expiry fields
-    new_task_definition['created'] = current_json_time()
-    new_task_definition['deadline'] = json_time_from_now('1d')
-    new_task_definition['expires'] = json_time_from_now('30d')
+    pre_task = full_task_graph.tasks[task['metadata']['name']]
 
-    # reset artifact expiry
-    for artifact in new_task_definition['payload'].get('artifacts', {}).values():
-        artifact['expires'] = new_task_definition['expires']
+    # fix up the task's dependencies, similar to how optimization would
+    # have done in the decision
+    dependencies = {name: label_to_taskid[label]
+                    for name, label in pre_task.dependencies.iteritems()}
+    new_task_definition = resolve_task_references(pre_task.label, pre_task.task, dependencies)
+    new_task_definition.setdefault('dependencies', []).extend(dependencies.itervalues())
 
     # don't want to run mozharness tests, want a custom mach command instead
     new_task_definition['payload']['command'] += ['--no-run-tests']
 
     custom_mach_command = [task['tags']['test-type']]
 
     # mochitests may specify a flavor
     if new_task_definition['payload']['env'].get('MOCHITEST_FLAVOR'):
@@ -108,21 +111,21 @@ def test_retrigger_action(parameters, in
         ]
 
     enable_e10s = json.loads(new_task_definition['payload']['env'].get(
         'ENABLE_E10S', 'true'))
     if not enable_e10s:
         custom_mach_command += ['--disable-e10s']
 
     custom_mach_command += ['--log-tbpl=-',
-                            '--log-tbpl-level={}'.format(input['logLevel'])]
+                            '--log-tbpl-level={}'.format(input.get('logLevel', 'debug'))]
     if input.get('runUntilFail'):
         custom_mach_command += ['--run-until-failure']
     if input.get('repeat'):
-        custom_mach_command += ['--repeat', str(input['repeat'])]
+        custom_mach_command += ['--repeat', str(input.get('repeat', 30))]
 
     # add any custom gecko preferences
     for (key, val) in input.get('preferences', {}).iteritems():
         custom_mach_command += ['--setpref', '{}={}'.format(key, val)]
 
     custom_mach_command += [input['path']]
     new_task_definition['payload']['env']['CUSTOM_MACH_COMMAND'] = ' '.join(
         custom_mach_command)
@@ -132,11 +135,9 @@ def test_retrigger_action(parameters, in
 
     # tweak the treeherder symbol
     new_task_definition['extra']['treeherder']['symbol'] += '-custom'
 
     logging.info("New task definition: %s", new_task_definition)
 
     # actually create the new task
     new_task_id = slugid()
-    logger.info("Creating new mochitest task with id %s", new_task_id)
-    session = requests.Session()
-    create_task(session, new_task_id, 'test-retrigger', new_task_definition)
+    create_task(new_task_id, new_task_definition, parameters['level'])