From 1964df62df9acf92a45ff28abd95276344769411 Mon Sep 17 00:00:00 2001 From: Hammad Akhtar Date: Tue, 13 Dec 2016 11:51:53 +0530 Subject: [PATCH] Bug 1323633 - Ensure that task graphs do not contain duplicate Treeherder symbols, also consider treeherder.collection.keys(); r=dustin MozReview-Commit-ID: 3F0BHQQmSOg --HG-- extra : rebase_source : 52ba5d93d689e5ca64cee04dd013dcd79919049d --- taskcluster/taskgraph/generator.py | 3 ++- taskcluster/taskgraph/taskgraph.py | 5 ++++ .../util/{verifydoc.py => verify.py} | 27 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) rename taskcluster/taskgraph/util/{verifydoc.py => verify.py} (61%) diff --git a/taskcluster/taskgraph/generator.py b/taskcluster/taskgraph/generator.py index dcd35523ecdd..926b007592af 100644 --- a/taskcluster/taskgraph/generator.py +++ b/taskcluster/taskgraph/generator.py @@ -12,7 +12,7 @@ from .graph import Graph from .taskgraph import TaskGraph from .optimize import optimize_task_graph from .util.python_path import find_object -from .util.verifydoc import verify_docs +from .util.verify import verify_docs, verify_task_graph_symbol logger = logging.getLogger(__name__) @@ -217,6 +217,7 @@ class TaskGraphGenerator(object): target_task_graph = TaskGraph( {l: all_tasks[l] for l in target_graph.nodes}, target_graph) + target_task_graph.for_each_task(verify_task_graph_symbol, scratch_pad={}) yield 'target_task_graph', target_task_graph logger.info("Generating optimized task graph") diff --git a/taskcluster/taskgraph/taskgraph.py b/taskcluster/taskgraph/taskgraph.py index 7736745ef50d..606ea209868a 100644 --- a/taskcluster/taskgraph/taskgraph.py +++ b/taskcluster/taskgraph/taskgraph.py @@ -46,6 +46,11 @@ class TaskGraph(object): tasks[key] = task_json return tasks + def for_each_task(self, f, *args, **kwargs): + for task_label in self.graph.visit_postorder(): + task = self.tasks[task_label] + f(task, self, *args, **kwargs) + def __getitem__(self, label): "Get a task by label" return self.tasks[label] diff --git a/taskcluster/taskgraph/util/verifydoc.py b/taskcluster/taskgraph/util/verify.py similarity index 61% rename from taskcluster/taskgraph/util/verifydoc.py rename to taskcluster/taskgraph/util/verify.py index 17ca13eeb199..8810968c7d1d 100644 --- a/taskcluster/taskgraph/util/verifydoc.py +++ b/taskcluster/taskgraph/util/verify.py @@ -38,3 +38,30 @@ def verify_docs(filename, identifiers, appearing_as): "{}: `{}` missing from doc file: `{}`" .format(appearing_as, identifier, filename) ) + + +def verify_task_graph_symbol(task, taskgraph, scratch_pad): + """ + This function verifies that tuple + (collection.keys(), machine.platform, groupSymbol, symbol) is unique + for a target task graph. + """ + task_dict = task.task + if "extra" in task_dict: + extra = task_dict["extra"] + if "treeherder" in extra: + treeherder = extra["treeherder"] + + collection_keys = tuple(sorted(treeherder.get('collection', {}).keys())) + platform = treeherder.get('machine', {}).get('platform') + group_symbol = treeherder.get('groupSymbol') + symbol = treeherder.get('symbol') + + key = (collection_keys, platform, group_symbol, symbol) + if key in scratch_pad: + raise Exception( + "conflict between `{}`:`{}` for values `{}`" + .format(task.label, scratch_pad[key], key) + ) + else: + scratch_pad[key] = task.label