commit 6376725ec8e5130aa9b6f94d1caedea0b9cb1b51
parent 4063ac0be66aee9b28af94eaa055364b88b6fd73
Author: abhishekmadan30 <amadan@mozilla.com>
Date: Wed, 22 Oct 2025 18:22:22 +0000
Bug 1990567 - Updated taskgraph to use taskcluster package instead of REST API.r=ahal,taskgraph-reviewers,releng-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D266033
Diffstat:
6 files changed, 41 insertions(+), 45 deletions(-)
diff --git a/taskcluster/gecko_taskgraph/actions/create_interactive.py b/taskcluster/gecko_taskgraph/actions/create_interactive.py
@@ -159,7 +159,7 @@ def create_interactive_action(parameters, graph_config, input, task_group_id, ta
if email and email != "noreply@noreply.mozilla.org":
info = {
"url": taskcluster_urls.ui(
- get_root_url(False), "tasks/${status.taskId}/connect"
+ get_root_url(block_proxy=True), "tasks/${status.taskId}/connect"
),
"label": label,
"revision": parameters["head_rev"],
diff --git a/taskcluster/gecko_taskgraph/test/test_optimize_strategies.py b/taskcluster/gecko_taskgraph/test/test_optimize_strategies.py
@@ -587,18 +587,19 @@ def test_mozlint_should_remove_task2(
assert result == expected
-def test_skip_unless_missing(responses, params):
+def test_skip_unless_missing(responses, params, session_mocker):
opt = SkipUnlessMissing()
task = deepcopy(default_tasks[0])
task.task["deadline"] = "2024-01-02T00:00:00.000Z"
index = "foo.bar.baz"
task_id = "abc"
- root_url = "https://firefox-ci-tc.services.mozilla.com/api"
+ root_url = "https://firefox-ci-tc.services.mozilla.com"
+ session_mocker.patch.dict("os.environ", {"TASKCLUSTER_ROOT_URL": root_url})
# Task is missing, don't optimize
responses.add(
responses.GET,
- f"{root_url}/index/v1/task/{index}",
+ f"{root_url}/api/index/v1/task/{index}",
status=404,
)
result = opt.should_remove_task(task, params, index)
@@ -607,13 +608,13 @@ def test_skip_unless_missing(responses, params):
# Task is found but failed, don't optimize
responses.replace(
responses.GET,
- f"{root_url}/index/v1/task/{index}",
+ f"{root_url}/api/index/v1/task/{index}",
json={"taskId": task_id},
status=200,
)
responses.add(
responses.GET,
- f"{root_url}/queue/v1/task/{task_id}/status",
+ f"{root_url}/api/queue/v1/task/{task_id}/status",
json={"status": {"state": "failed"}},
status=200,
)
@@ -623,13 +624,13 @@ def test_skip_unless_missing(responses, params):
# Task is found and passed but expires before deadline, don't optimize
responses.replace(
responses.GET,
- f"{root_url}/index/v1/task/{index}",
+ f"{root_url}/api/index/v1/task/{index}",
json={"taskId": task_id},
status=200,
)
responses.replace(
responses.GET,
- f"{root_url}/queue/v1/task/{task_id}/status",
+ f"{root_url}/api/queue/v1/task/{task_id}/status",
json={"status": {"state": "completed", "expires": "2024-01-01T00:00:00.000Z"}},
status=200,
)
@@ -639,13 +640,13 @@ def test_skip_unless_missing(responses, params):
# Task is found and passed and expires after deadline, optimize
responses.replace(
responses.GET,
- f"{root_url}/index/v1/task/{index}",
+ f"{root_url}/api/index/v1/task/{index}",
json={"taskId": task_id},
status=200,
)
responses.replace(
responses.GET,
- f"{root_url}/queue/v1/task/{task_id}/status",
+ f"{root_url}/api/queue/v1/task/{task_id}/status",
json={"status": {"state": "completed", "expires": "2024-01-03T00:00:00.000Z"}},
status=200,
)
@@ -656,13 +657,13 @@ def test_skip_unless_missing(responses, params):
task.task["deadline"] = {"relative-datestamp": "1 day"}
responses.replace(
responses.GET,
- f"{root_url}/index/v1/task/{index}",
+ f"{root_url}/api/index/v1/task/{index}",
json={"taskId": task_id},
status=200,
)
responses.replace(
responses.GET,
- f"{root_url}/queue/v1/task/{task_id}/status",
+ f"{root_url}/api/queue/v1/task/{task_id}/status",
json={"status": {"state": "completed", "expires": "2024-01-03T00:00:00.000Z"}},
status=200,
)
diff --git a/taskcluster/gecko_taskgraph/test/test_util_backstop.py b/taskcluster/gecko_taskgraph/test/test_util_backstop.py
@@ -147,14 +147,19 @@ def params():
),
),
)
-def test_is_backstop(responses, params, response_args, extra_params, expected):
+def test_is_backstop(
+ responses, params, response_args, extra_params, expected, session_mocker
+):
+ root_url = "https://firefox-ci-tc.services.mozilla.com"
+ session_mocker.patch.dict("os.environ", {"TASKCLUSTER_ROOT_URL": root_url})
+
urls = {
"index": get_index_url(
BACKSTOP_INDEX.format(
**{"trust-domain": "gecko", "project": params["project"]}
)
),
- "artifact": get_artifact_url(LAST_BACKSTOP_PUSHID, "public/parameters.yml"),
+ "artifact": get_artifact_url(LAST_BACKSTOP_PUSHID, "public%2Fparameters.yml"),
"status": get_task_url(LAST_BACKSTOP_PUSHID) + "/status",
}
diff --git a/taskcluster/gecko_taskgraph/transforms/job/distro_package.py b/taskcluster/gecko_taskgraph/transforms/job/distro_package.py
@@ -178,7 +178,7 @@ def common_package(config, job, taskdesc, distro, version):
# Make the artifacts directory usable as an APT repository.
"apt-ftparchive sources apt | gzip -c9 > apt/Sources.gz && "
"apt-ftparchive packages apt | gzip -c9 > apt/Packages.gz".format(
- root_url=get_root_url(False),
+ root_url=get_root_url(),
package=package,
src_url=src_url,
src_file=src_file,
diff --git a/taskcluster/gecko_taskgraph/util/backstop.py b/taskcluster/gecko_taskgraph/util/backstop.py
@@ -3,7 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-from requests import HTTPError
+from taskcluster.exceptions import TaskclusterRestFailure
from taskgraph.util.taskcluster import find_task_id, get_artifact
from gecko_taskgraph.util.attributes import INTEGRATION_PROJECTS, TRY_PROJECTS
@@ -62,7 +62,7 @@ def is_backstop(
try:
last_backstop_id = find_task_id(index)
- except KeyError:
+ except TaskclusterRestFailure:
# Index wasn't found, implying there hasn't been a backstop push yet.
return True
@@ -72,12 +72,12 @@ def is_backstop(
try:
last_params = get_artifact(last_backstop_id, "public/parameters.yml")
- except HTTPError as e:
+ except TaskclusterRestFailure as e:
# If the last backstop decision task exists in the index, but
# parameters.yml isn't available yet, it means the decision task is
# still running. If that's the case, we can be pretty sure the time
# component will not cause a backstop, so just return False.
- if e.response.status_code == 404:
+ if e.status_code == 404:
return False
raise
diff --git a/taskcluster/gecko_taskgraph/util/taskcluster.py b/taskcluster/gecko_taskgraph/util/taskcluster.py
@@ -4,32 +4,26 @@
import logging
-import os
-import taskcluster_urls as liburls
from taskcluster import Hooks
from taskgraph.util import taskcluster as tc_util
from taskgraph.util.taskcluster import (
- _do_request,
- get_index_url,
get_root_url,
get_task_definition,
- get_task_url,
+ get_taskcluster_client,
)
logger = logging.getLogger(__name__)
def insert_index(index_path, task_id, data=None, use_proxy=False):
- index_url = get_index_url(index_path, use_proxy=use_proxy)
-
# Find task expiry.
- expires = get_task_definition(task_id, use_proxy)["expires"]
+ expires = get_task_definition(task_id)["expires"]
- response = _do_request(
- index_url,
- method="put",
- json={
+ index = get_taskcluster_client("index")
+ response = index.insertTask(
+ index_path,
+ {
"taskId": task_id,
"rank": 0,
"data": data or {},
@@ -55,9 +49,10 @@ def status_task(task_id, use_proxy=False):
if tc_util.testing:
logger.info(f"Would have gotten status for {task_id}.")
else:
- resp = _do_request(get_task_url(task_id, use_proxy) + "/status")
- status = resp.json().get("status", {})
- return status
+ queue = get_taskcluster_client("queue")
+ response = queue.status(task_id)
+ if response:
+ return response.get("status", {})
def state_task(task_id, use_proxy=False):
@@ -82,12 +77,12 @@ def state_task(task_id, use_proxy=False):
def trigger_hook(hook_group_id, hook_id, hook_payload):
- hooks = Hooks({"rootUrl": get_root_url(True)})
+ hooks = Hooks({"rootUrl": get_root_url()})
response = hooks.triggerHook(hook_group_id, hook_id, hook_payload)
logger.info(
"Task seen here: {}/tasks/{}".format(
- get_root_url(os.environ.get("TASKCLUSTER_PROXY_URL")),
+ get_root_url(),
response["status"]["taskId"],
)
)
@@ -96,14 +91,9 @@ def trigger_hook(hook_group_id, hook_id, hook_payload):
def list_task_group_tasks(task_group_id):
"""Generate the tasks in a task group"""
params = {}
+ queue = get_taskcluster_client("queue")
while True:
- url = liburls.api(
- get_root_url(False),
- "queue",
- "v1",
- f"task-group/{task_group_id}/list",
- )
- resp = _do_request(url, method="get", params=params).json()
+ resp = queue.listTaskGroup(task_group_id, params)
yield from resp["tasks"]
if resp.get("continuationToken"):
params = {"continuationToken": resp.get("continuationToken")}
@@ -129,5 +119,5 @@ def list_task_group_complete_tasks(task_group_id):
def find_task(index_path, use_proxy=False):
- response = _do_request(get_index_url(index_path, use_proxy))
- return response.json()
+ index = get_taskcluster_client("index")
+ return index.findTask(index_path)