Bug 1289824 - Add "add-talos" taskgraph action draft
authorBrian Stack <bstack@mozilla.com>
Wed, 11 Jan 2017 11:13:19 -0500
changeset 465772 89859881bf26a0dfc25dc92d4b52f5f2cea1f796
parent 465527 8ff550409e1d1f8b54f6f7f115545dbef857be0b
child 543250 caf0fb21f95df94e827f651283a586887a55d976
push id42711
push userbstack@mozilla.com
push dateTue, 24 Jan 2017 21:05:24 +0000
bugs1289824
milestone54.0a1
Bug 1289824 - Add "add-talos" taskgraph action MozReview-Commit-ID: A5KVIgAZccV
taskcluster/mach_commands.py
taskcluster/taskgraph/action.py
--- a/taskcluster/mach_commands.py
+++ b/taskcluster/mach_commands.py
@@ -273,16 +273,40 @@ class MachCommands(MachCommandBase):
         import taskgraph.cron
         try:
             self.setup_logging()
             return taskgraph.cron.taskgraph_cron(options)
         except Exception:
             traceback.print_exc()
             sys.exit(1)
 
+    @SubCommand('taskgraph', 'add-talos',
+                description="Run the add-talos task")
+    @CommandArgument('--root', '-r',
+                     default='taskcluster/ci',
+                     help="root of the taskgraph definition relative to topsrcdir")
+    @CommandArgument('--decision-task-id',
+                     required=True,
+                     help="Id of the decision task that is part of the push to be talos'd")
+    @CommandArgument('--times',
+                     required=False,
+                     default=1,
+                     type=int,
+                     help="Number of times to add each job.")
+    def taskgraph_add_talos(self, **options):
+        """Add all talos jobs for a push."""
+
+        import taskgraph.action
+        try:
+            self.setup_logging()
+            return taskgraph.action.add_talos(options['decision_task_id'], options['times'])
+        except Exception:
+            traceback.print_exc()
+            sys.exit(1)
+
     def setup_logging(self, quiet=False, verbose=True):
         """
         Set up Python logging for all loggers, sending results to stderr (so
         that command output can be redirected easily) and adding the typical
         mach timestamp.
         """
         # remove the old terminal handler
         old = self.log_manager.replace_terminal_handler(None)
--- a/taskcluster/taskgraph/action.py
+++ b/taskcluster/taskgraph/action.py
@@ -95,16 +95,29 @@ def backfill(project, job_id):
     params = {"id__lt": job["result_set_id"], "count": MAX_BACKFILL_RESULTSETS}
     results = s.get(url=resultset_url, params=params).json()["results"]
     resultsets = [resultset["id"] for resultset in results]
 
     for decision in load_decisions(s, project, resultsets, filters):
         add_tasks(decision, [job["job_type_name"]], '{}-'.format(decision))
 
 
+def add_talos(decision_task_id, times=1):
+    """
+    Run the add-talos task.  This function implements `mach taskgraph add-talos`,
+    and is responsible for
+
+     * Adding all talos jobs to a push.
+    """
+    full_task_json = get_artifact(decision_task_id, "public/full-task-graph.json")
+    task_labels = [label for label in full_task_json if "talos" in label]
+    for time in xrange(times):
+        add_tasks(decision_task_id, task_labels, '{}-'.format(time))
+
+
 def load_decisions(s, project, resultsets, filters):
     """
     Given a project, a list of revisions, and a dict of filters, return
     a list of taskIds from decision tasks.
     """
     project_url = "{}/project/{}/jobs/".format(TREEHERDER_URL, project)
     decision_url = "{}/jobdetail/".format(TREEHERDER_URL)
     decisions = []