Bug 1304428 - Adding a from_json test in decision task. r=jlund
authorKalpesh Krishna <kalpeshk2011@gmail.com>
Fri, 23 Sep 2016 19:26:39 +0530
changeset 315196 d23c6cdd5c3767c932d3cae447436c6abd2e2b50
parent 315195 14c0697b2dfb25d1b89c084df466cc82274d734a
child 315197 81ea83beadf846f0d8f691162e5ef74cddf3c47a
push id32563
push userihsiao@mozilla.com
push dateMon, 26 Sep 2016 11:18:33 +0000
treeherderautoland@eb840c87b5fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlund
bugs1304428
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1304428 - Adding a from_json test in decision task. r=jlund MozReview-Commit-ID: 7QgfSutjoFZ
taskcluster/taskgraph/action.py
taskcluster/taskgraph/decision.py
taskcluster/taskgraph/task/signing.py
taskcluster/taskgraph/taskgraph.py
taskcluster/taskgraph/test/test_taskgraph.py
--- a/taskcluster/taskgraph/action.py
+++ b/taskcluster/taskgraph/action.py
@@ -30,17 +30,17 @@ def taskgraph_action(options):
      a given gecko decision task and schedule these jobs.
     """
 
     parameters = get_action_parameters(options)
     decision_task_id = parameters['decision_id']
     # read in the full graph for reference
     full_task_json = get_artifact(decision_task_id, "public/full-task-graph.json")
     decision_params = get_artifact(decision_task_id, "public/parameters.yml")
-    all_tasks, full_task_graph = TaskGraph.from_json(full_task_json, options['root'])
+    all_tasks, full_task_graph = TaskGraph.from_json(full_task_json)
 
     target_tasks = set(parameters['task_labels'].split(','))
     target_graph = full_task_graph.graph.transitive_closure(target_tasks)
     target_task_graph = TaskGraph(
         {l: all_tasks[l] for l in target_graph.nodes},
         target_graph)
 
     existing_tasks = get_artifact(decision_task_id, "public/label-to-taskid.json")
--- a/taskcluster/taskgraph/decision.py
+++ b/taskcluster/taskgraph/decision.py
@@ -10,16 +10,17 @@ import os
 import json
 import logging
 import yaml
 
 from .generator import TaskGraphGenerator
 from .create import create_tasks
 from .parameters import Parameters
 from .target_tasks import get_method
+from .taskgraph import TaskGraph
 
 from taskgraph.util.templates import Templates
 from taskgraph.util.time import (
     json_time_from_now,
     current_json_time,
 )
 
 logger = logging.getLogger(__name__)
@@ -75,17 +76,21 @@ def taskgraph_decision(options):
 
     # write out the parameters used to generate this graph
     write_artifact('parameters.yml', dict(**parameters))
 
     # write out the yml file for action tasks
     write_artifact('action.yml', get_action_yml(parameters))
 
     # write out the full graph for reference
-    write_artifact('full-task-graph.json', tgg.full_task_graph.to_json())
+    full_task_json = tgg.full_task_graph.to_json()
+    write_artifact('full-task-graph.json', full_task_json)
+
+    # this is just a test to check whether the from_json() function is working
+    _, _ = TaskGraph.from_json(full_task_json)
 
     # write out the target task set to allow reproducing this as input
     write_artifact('target-tasks.json', tgg.target_task_set.tasks.keys())
 
     # write out the optimized task graph to describe what will actually happen,
     # and the map of labels to taskids
     write_artifact('task-graph.json', tgg.optimized_task_graph.to_json())
     write_artifact('label-to-taskid.json', tgg.label_to_taskid)
--- a/taskcluster/taskgraph/task/signing.py
+++ b/taskcluster/taskgraph/task/signing.py
@@ -45,8 +45,20 @@ class SigningTask(base.Task):
 
         return tasks
 
     def get_dependencies(self, taskgraph):
         return [(self.unsigned_artifact_label, 'unsigned-artifact')]
 
     def optimize(self, params):
         return False, None
+
+    @classmethod
+    def from_json(cls, task_dict):
+        unsigned_task_label = task_dict['dependencies']['unsigned-artifact']
+        task_dict['unsigned-task'] = {
+            'label': unsigned_task_label
+        }
+        signing_task = cls(kind='build-signing',
+                           name=task_dict['label'],
+                           attributes=task_dict['attributes'],
+                           task=task_dict)
+        return signing_task
--- a/taskcluster/taskgraph/taskgraph.py
+++ b/taskcluster/taskgraph/taskgraph.py
@@ -56,17 +56,17 @@ class TaskGraph(object):
 
     def __repr__(self):
         return "<TaskGraph graph={!r} tasks={!r}>".format(self.graph, self.tasks)
 
     def __eq__(self, other):
         return self.tasks == other.tasks and self.graph == other.graph
 
     @classmethod
-    def from_json(cls, tasks_dict, root):
+    def from_json(cls, tasks_dict):
         """
         This code is used to generate the a TaskGraph using a dictionary
         which is representative of the TaskGraph.
         """
         tasks = {}
         edges = set()
         for key, value in tasks_dict.iteritems():
             # We get the implementation from JSON
--- a/taskcluster/taskgraph/test/test_taskgraph.py
+++ b/taskcluster/taskgraph/test/test_taskgraph.py
@@ -28,14 +28,14 @@ class TestTargetTasks(unittest.TestCase)
                 }),
             'b': DockerImageTask(kind='docker-image',
                                  label='b',
                                  attributes={},
                                  task={"routes": []},
                                  index_paths=[]),
         }, graph=Graph(nodes={'a', 'b'}, edges=set()))
 
-        tasks, new_graph = TaskGraph.from_json(graph.to_json(), "taskcluster/ci")
+        tasks, new_graph = TaskGraph.from_json(graph.to_json())
         self.assertEqual(graph.tasks['a'], new_graph.tasks['a'])
         self.assertEqual(graph, new_graph)
 
 if __name__ == '__main__':
     main()