Bug 1275409: remove taskcluster_graph.build_task; r?wcosta
MozReview-Commit-ID: IphYcikdlxX
--- a/taskcluster/taskgraph/kind/legacy.py
+++ b/taskcluster/taskgraph/kind/legacy.py
@@ -19,17 +19,16 @@ from functools import partial
from mozpack.path import match as mozpackmatch
from slugid import nice as slugid
from taskgraph.util.legacy_commit_parser import parse_commit
from taskgraph.util.time import (
json_time_from_now,
current_json_time,
)
from taskgraph.util.templates import Templates
-import taskcluster_graph.build_task
from taskgraph.util.docker import docker_image
ROOT = os.path.dirname(os.path.realpath(__file__))
GECKO = os.path.realpath(os.path.join(ROOT, '..', '..', '..'))
# TASKID_PLACEHOLDER is the "internal" form of a taskid; it is substituted with
# actual taskIds at the very last minute, in get_task_definition
TASKID_PLACEHOLDER = 'TaskLabel=={}'
@@ -246,16 +245,41 @@ def decorate_task_json_routes(task, json
:param parameters: dictionary of parameters to use in route templates
"""
routes = task.get('routes', [])
for route in json_routes:
routes.append(route.format(**parameters))
task['routes'] = routes
+class BuildTaskValidationException(Exception):
+ pass
+
+def validate_build_task(task):
+ '''The build tasks have some required fields in extra this function ensures
+ they are there. '''
+ if 'task' not in task:
+ raise BuildTaskValidationException('must have task field')
+
+ task_def = task['task']
+
+ if 'extra' not in task_def:
+ raise BuildTaskValidationException('build task must have task.extra props')
+
+ if 'locations' not in task_def['extra']:
+ raise BuildTaskValidationException('task.extra.locations missing')
+
+ locations = task_def['extra']['locations']
+
+ if 'build' not in locations:
+ raise BuildTaskValidationException('task.extra.locations.build missing')
+
+ if 'tests' not in locations and 'test_packages' not in locations:
+ raise BuildTaskValidationException('task.extra.locations.tests or '
+ 'task.extra.locations.tests_packages missing')
class LegacyKind(base.Kind):
"""
This kind generates a full task graph from the old YAML files in
`testing/taskcluster/tasks`. The tasks already have dependency links.
The existing task-graph generation generates slugids for tasks during task
generation, so this kind labels tasks using those slugids, with a prefix of
@@ -418,17 +442,17 @@ class LegacyKind(base.Kind):
params['revision_hash'])
decorate_task_treeherder_routes(build_task['task'],
treeherder_route)
decorate_task_json_routes(build_task['task'],
json_routes,
build_parameters)
# Ensure each build graph is valid after construction.
- taskcluster_graph.build_task.validate(build_task)
+ validate_build_task(build_task)
attributes = build_task['attributes'] = {'kind':'legacy', 'legacy_kind': 'build'}
if 'build_name' in build:
attributes['build_platform'] = build['build_name']
if 'build_type' in task_extra:
attributes['build_type'] = {'dbg': 'debug'}.get(task_extra['build_type'],
task_extra['build_type'])
if build.get('is_job'):
attributes['job'] = build['build_name']
--- a/taskcluster/taskgraph/test/test_kind_legacy.py
+++ b/taskcluster/taskgraph/test/test_kind_legacy.py
@@ -1,24 +1,47 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function, unicode_literals
import unittest
-from ..kind.legacy import LegacyKind, TASKID_PLACEHOLDER
+from ..kind.legacy import (
+ LegacyKind,
+ TASKID_PLACEHOLDER,
+ validate_build_task,
+ BuildTaskValidationException
+)
from ..types import Task
from mozunit import main
class TestLegacyKind(unittest.TestCase):
# NOTE: much of LegacyKind is copy-pasted from the old legacy code, which
# is emphatically *not* designed for testing, so this test class does not
# attempt to test the entire class.
def setUp(self):
self.kind = LegacyKind('/root', {})
+class TestValidateBuildTask(unittest.TestCase):
+
+ def test_validate_missing_extra(self):
+ with self.assertRaises(BuildTaskValidationException):
+ validate_build_task({})
+
+ def test_validate_valid(self):
+ with self.assertRaises(BuildTaskValidationException):
+ validate_build_task({
+ 'extra': {
+ 'locations': {
+ 'build': '',
+ 'tests': ''
+ }
+ }
+ })
+
+
if __name__ == '__main__':
main()
deleted file mode 100644
--- a/testing/taskcluster/taskcluster_graph/build_task.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this file,
-# You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# This module contains logic related to build tasks
-
-class BuildTaskValidationException(Exception):
- pass
-
-# XXX: Consider using JSON Schema here like we do elsewhere...
-def validate(task):
- '''
- The build tasks have some required fields in extra this function ensures
- they are there.
- '''
- if 'task' not in task:
- raise BuildTaskValidationException('must have task field')
-
- task_def = task['task']
-
- if 'extra' not in task_def:
- raise BuildTaskValidationException('build task must have task.extra props')
-
- if 'locations' not in task_def['extra']:
- raise BuildTaskValidationException('task.extra.locations missing')
-
- locations = task_def['extra']['locations']
-
- if 'build' not in locations:
- raise BuildTaskValidationException('task.extra.locations.build missing')
-
- if 'tests' not in locations and 'test_packages' not in locations:
- raise BuildTaskValidationException('task.extra.locations.tests or '
- 'task.extra.locations.tests_packages missing')
deleted file mode 100755
--- a/testing/taskcluster/tests/test_build_task.py
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env python
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this file,
-# You can obtain one at http://mozilla.org/MPL/2.0/.
-
-import unittest
-import mozunit
-import taskcluster_graph.build_task as build_task
-
-class TestBuildTask(unittest.TestCase):
-
- def test_validate_missing_extra(self):
- with self.assertRaises(build_task.BuildTaskValidationException):
- build_task.validate({})
-
- def test_validate_valid(self):
- with self.assertRaises(build_task.BuildTaskValidationException):
- build_task.validate({
- 'extra': {
- 'locations': {
- 'build': '',
- 'tests': ''
- }
- }
- })
-
-if __name__ == '__main__':
- mozunit.main()
-