Bug 1419638 - Add schema validation to docker image transform. r=dustin draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 28 Dec 2017 15:46:14 +0900
changeset 715670 0525a6c2030c363339e616d02790eb1f3aa7d498
parent 715619 5afa32a16a2f7ebbd8bf19e49efc50832110980d
child 715671 56cbc4041aed566952dbe81eccc8e62cb95fa428
push id94224
push userbmo:mh+mozilla@glandium.org
push dateThu, 04 Jan 2018 11:02:43 +0000
reviewersdustin
bugs1419638
milestone59.0a1
Bug 1419638 - Add schema validation to docker image transform. r=dustin
taskcluster/taskgraph/transforms/docker_image.py
--- a/taskcluster/taskgraph/transforms/docker_image.py
+++ b/taskcluster/taskgraph/transforms/docker_image.py
@@ -1,31 +1,54 @@
 # 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/.
-"""
-Transform the upload-symbols task description template,
-  taskcluster/ci/upload-symbols/job-template.yml
-into an actual task description.
-"""
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import os
 
 from taskgraph.transforms.base import TransformSequence
 from .. import GECKO
 from taskgraph.util.docker import (
     docker_image,
     generate_context_hash,
 )
 from taskgraph.util.cached_tasks import add_optimization
+from taskgraph.util.schema import (
+    Schema,
+    validate_schema,
+)
+from voluptuous import (
+    Optional,
+    Required,
+)
 
 transforms = TransformSequence()
 
+docker_image_schema = Schema({
+    # Name of the docker image.
+    Required('name'): basestring,
+
+    # Treeherder symbol.
+    Required('symbol'): basestring,
+
+    # relative path (from config.path) to the file the docker image was defined
+    # in.
+    Optional('job-from'): basestring,
+})
+
+
+@transforms.add
+def validate(config, tasks):
+    for task in tasks:
+        yield validate_schema(
+            docker_image_schema, task,
+            "In docker image {!r}:".format(task.get('name', 'unknown')))
+
 
 @transforms.add
 def fill_template(config, tasks):
     for task in tasks:
         image_name = task.pop('name')
         job_symbol = task.pop('symbol')
 
         context_path = os.path.join('taskcluster', 'docker', image_name)