Bug 1378212 - Default to grabbing 'parameters.yml' file from latest mozilla-central decision task, r=dustin
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 04 Jul 2017 16:10:05 -0400
changeset 367400 051408cf1c53ae86857be4354d54792b5514b61e
parent 367399 5d448af9b09ee460ae23ae942450629c3dff9135
child 367401 aecdc7b7c8303f80717392bfc8a977ab4132d2ff
push id32134
push userkwierso@gmail.com
push dateWed, 05 Jul 2017 23:45:30 +0000
treeherdermozilla-central@e25d645e59ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdustin
bugs1378212
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1378212 - Default to grabbing 'parameters.yml' file from latest mozilla-central decision task, r=dustin MozReview-Commit-ID: 1993ISgb1Dn
taskcluster/mach_commands.py
taskcluster/taskgraph/parameters.py
taskcluster/taskgraph/test/test_parameters.py
--- a/taskcluster/mach_commands.py
+++ b/taskcluster/mach_commands.py
@@ -36,17 +36,17 @@ class ShowTaskGraphSubCommand(SubCommand
             CommandArgument('--verbose', '-v', action="store_true",
                             help="include debug-level logging output"),
             CommandArgument('--json', '-J', action="store_const",
                             dest="format", const="json",
                             help="Output task graph as a JSON object"),
             CommandArgument('--labels', '-L', action="store_const",
                             dest="format", const="labels",
                             help="Output the label for each task in the task graph (default)"),
-            CommandArgument('--parameters', '-p', required=True,
+            CommandArgument('--parameters', '-p', default="project=mozilla-central",
                             help="parameters file (.yml or .json; see "
                                  "`taskcluster/docs/parameters.rst`)`"),
             CommandArgument('--no-optimize', dest="optimize", action="store_false",
                             default="true",
                             help="do not remove tasks from the graph that are found in the "
                             "index (a.k.a. optimize the graph)"),
             CommandArgument('--tasks-regex', '--tasks', default=None,
                             help="only return tasks with labels matching this regular "
@@ -334,17 +334,17 @@ class MachCommands(MachCommandBase):
 
     def show_taskgraph(self, graph_attr, options):
         import taskgraph.parameters
         import taskgraph.target_tasks
         import taskgraph.generator
 
         try:
             self.setup_logging(quiet=options['quiet'], verbose=options['verbose'])
-            parameters = taskgraph.parameters.load_parameters_file(options)
+            parameters = taskgraph.parameters.load_parameters_file(options['parameters'])
             parameters.check()
 
             tgg = taskgraph.generator.TaskGraphGenerator(
                 root_dir=options['root'],
                 parameters=parameters)
 
             tg = getattr(tgg, graph_attr)
 
--- a/taskcluster/taskgraph/parameters.py
+++ b/taskcluster/taskgraph/parameters.py
@@ -52,35 +52,43 @@ class Parameters(ReadOnlyDict):
         if k not in PARAMETER_NAMES:
             raise KeyError("no such parameter {!r}".format(k))
         try:
             return super(Parameters, self).__getitem__(k)
         except KeyError:
             raise KeyError("taskgraph parameter {!r} not found".format(k))
 
 
-def load_parameters_file(options):
+def load_parameters_file(filename):
     """
-    Load parameters from the --parameters option
+    Load parameters from a path, url, decision task-id or project.
+
+    Examples:
+        task-id=fdtgsD5DQUmAQZEaGMvQ4Q
+        project=mozilla-central
     """
     import urllib
-    from taskgraph.util.taskcluster import get_artifact_url
-
-    filename = options['parameters']
+    from taskgraph.util.taskcluster import get_artifact_url, find_task_id
 
     if not filename:
         return Parameters()
 
     try:
         # reading parameters from a local parameters.yml file
         f = open(filename)
     except IOError:
-        # fetching parameters.yml using task task-id or supplied url
+        # fetching parameters.yml using task task-id, project or supplied url
+        task_id = None
         if filename.startswith("task-id="):
             task_id = filename.split("=")[1]
+        elif filename.startswith("project="):
+            index = "gecko.v2.{}.latest.firefox.decision".format(filename.split("=")[1])
+            task_id = find_task_id(index)
+
+        if task_id:
             filename = get_artifact_url(task_id, 'public/parameters.yml')
         f = urllib.urlopen(filename)
 
     if filename.endswith('.yml'):
         return Parameters(**yaml.safe_load(f))
     elif filename.endswith('.json'):
         return Parameters(**json.load(f))
     else:
--- a/taskcluster/taskgraph/test/test_parameters.py
+++ b/taskcluster/taskgraph/test/test_parameters.py
@@ -44,20 +44,20 @@ class TestParameters(unittest.TestCase):
 
     def test_Parameters_check_extra(self):
         p = Parameters(xyz=10, **self.vals)
         self.assertRaises(Exception, lambda: p.check())
 
     def test_load_parameters_file_yaml(self):
         with MockedOpen({"params.yml": "some: data\n"}):
             self.assertEqual(
-                    load_parameters_file({'parameters': 'params.yml'}),
+                    load_parameters_file('params.yml'),
                     {'some': 'data'})
 
     def test_load_parameters_file_json(self):
         with MockedOpen({"params.json": '{"some": "data"}'}):
             self.assertEqual(
-                    load_parameters_file({'parameters': 'params.json'}),
+                    load_parameters_file('params.json'),
                     {'some': 'data'})
 
 
 if __name__ == '__main__':
     main()