Skip to content

Commit e06be22

Browse files
authored
Be resilient to the presence of taskQueueId, projectId (#499)
Taskcluster v41 includes these properties in task definitions. When comparing tasks, this normalizes the tasks to always contain `projectId` and `taskQueueId` and ever `providerId` or `workerType`, following the same defaults for those properties as Taskcluster itself.
1 parent 95360d7 commit e06be22

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/scriptworker/cot/verify.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
)
5454
from scriptworker.utils import (
5555
add_enumerable_item_to_dict,
56+
add_projectid,
57+
add_taskqueueid,
5658
format_json,
5759
get_hash,
5860
get_loggable_url,
@@ -1597,6 +1599,15 @@ def compare_jsone_task_definition(parent_link, rebuilt_definitions):
15971599
compare_definition = remove_empty_keys(compare_definition)
15981600
runtime_definition = remove_empty_keys(parent_link.task)
15991601

1602+
# add projectId properties if they do not already appear
1603+
compare_definition = add_projectid(compare_definition)
1604+
runtime_definition = add_projectid(runtime_definition)
1605+
1606+
# add taskQueueId properties if they do not already appear, and
1607+
# remove provisionerId / workerType
1608+
compare_definition = add_taskqueueid(compare_definition)
1609+
runtime_definition = add_taskqueueid(runtime_definition)
1610+
16001611
diff = list(dictdiffer.diff(compare_definition, runtime_definition))
16011612
if diff:
16021613
diffs.append(pprint.pformat(diff))

src/scriptworker/utils.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,42 @@ def remove_empty_keys(values, remove=({}, None, [], "null")):
854854
return values
855855

856856

857+
# add_projectid {{{1
858+
def add_projectid(task_def):
859+
"""Add a projectId property to a task, if none already exists, using
860+
the Taskcluster default value of 'none'.
861+
862+
Args:
863+
task_def (dict): the task definition
864+
865+
Returns:
866+
task_def (dict): the task definition, with projectId
867+
"""
868+
return {"projectId": "none", **task_def}
869+
870+
871+
# add_taskqueueid {{{1
872+
def add_taskqueueid(task_def):
873+
"""Add a taskQueueId property to a task, if none already exists, based
874+
on the provisionerId and workerType. Then remove those two properties.
875+
876+
Args:
877+
task_def (dict): the task definition
878+
879+
Returns:
880+
task_def (dict): the task definition, with taskQueueId
881+
"""
882+
if "taskQueueId" not in task_def or "provisionerId" in task_def or "workerType" in task_def:
883+
task_def = task_def.copy()
884+
if "taskQueueId" not in task_def:
885+
task_def["taskQueueId"] = task_def["provisionerId"] + "/" + task_def["workerType"]
886+
if "provisionerId" in task_def:
887+
del task_def["provisionerId"]
888+
if "workerType" in task_def:
889+
del task_def["workerType"]
890+
return task_def
891+
892+
857893
# get_single_item_from_sequence {{{1
858894
def get_single_item_from_sequence(
859895
sequence,

0 commit comments

Comments
 (0)