Bug 1143264 - Allow specifying flag aliases r=garndt
authorjlal@mozilla.com
Fri, 13 Mar 2015 20:26:58 -0700
changeset 233761 0dc6248a65850d0552209ef900fe434fd0057abb
parent 233760 d8d41a5834f203ec70d154fb244b59dfff946ef0
child 233762 cf6efa8bc292a64919808a8fdb73df2e52c903c6
push id28424
push usercbook@mozilla.com
push dateTue, 17 Mar 2015 10:13:09 +0000
treeherdermozilla-central@c3dc0e5f8b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgarndt
bugs1143264
milestone39.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 1143264 - Allow specifying flag aliases r=garndt
testing/taskcluster/taskcluster_graph/commit_parser.py
testing/taskcluster/tests/test_commit_parser.py
--- a/testing/taskcluster/taskcluster_graph/commit_parser.py
+++ b/testing/taskcluster/taskcluster_graph/commit_parser.py
@@ -18,30 +18,37 @@ TEST_CHUNK_SUFFIX = re.compile('(.*)-([0
 BUILD_TYPE_ALIASES = {
     'o': 'opt',
     'd': 'debug'
 }
 
 class InvalidCommitException(Exception):
     pass
 
-def normalize_platform_list(all_builds, build_list):
+def normalize_platform_list(alias, all_builds, build_list):
     if build_list == 'all':
         return all_builds
 
-    return [ build.strip() for build in build_list.split(',') ]
+    results = []
+    for build in build_list.split(','):
+        if build in alias:
+            build = alias[build]
+        results.append(build)
 
-def normalize_test_list(all_tests, job_list):
+    return results
+
+def normalize_test_list(aliases, all_tests, job_list):
     '''
     Normalize a set of jobs (builds or tests) there are three common cases:
 
         - job_list is == 'none' (meaning an empty list)
         - job_list is == 'all' (meaning use the list of jobs for that job type)
         - job_list is comma delimited string which needs to be split
 
+    :param dict aliases: Alias mapping for jobs...
     :param list all_tests: test flags from job_flags.yml structure.
     :param str job_list: see above examples.
     :returns: List of jobs
     '''
 
     # Empty job list case...
     if job_list is None or job_list == 'none':
         return []
@@ -56,42 +63,47 @@ def normalize_test_list(all_tests, job_l
         results = []
         all_entry = tests[0]
         for test in all_tests:
             entry = { 'test': test }
             # If there are platform restrictions copy them across the list.
             if 'platforms' in all_entry:
                 entry['platforms'] = list(all_entry['platforms'])
             results.append(entry)
-        return parse_test_chunks(results)
+        return parse_test_chunks(aliases, results)
     else:
-        return parse_test_chunks(tests)
+        return parse_test_chunks(aliases, tests)
 
-def parse_test_chunks(tests):
+def parse_test_chunks(aliases, tests):
     '''
     Test flags may include parameters to narrow down the number of chunks in a
     given push. We don't model 1 chunk = 1 job in taskcluster so we must check
     each test flag to see if it is actually specifying a chunk.
 
+    :param dict aliases: Dict of alias name -> real name.
     :param list tests: Result from normalize_test_list
     :returns: List of jobs
     '''
-
     results = []
     seen_chunks = {}
     for test in tests:
         matches = TEST_CHUNK_SUFFIX.match(test['test'])
 
         if not matches:
+            if test['test'] in aliases:
+                test['test'] = aliases[test['test']]
             results.append(test)
             continue
 
         name = matches.group(1)
         chunk = int(matches.group(2))
 
+        if name in aliases:
+            name = aliases[name]
+
         if name in seen_chunks:
             seen_chunks[name].add(chunk)
         else:
             seen_chunks[name] = set([chunk])
             test['test'] = name
             test['only_chunks'] = seen_chunks[name]
             results.append(test)
 
@@ -186,18 +198,20 @@ def parse_commit(message, jobs):
 
     # Then builds...
     if args.build_types is None:
         return []
 
     build_types = [ BUILD_TYPE_ALIASES.get(build_type, build_type) for
             build_type in args.build_types ]
 
-    platforms = normalize_platform_list(jobs['flags']['builds'], args.platforms)
-    tests = normalize_test_list(jobs['flags']['tests'], args.tests)
+    aliases = jobs['flags'].get('aliases', {})
+
+    platforms = normalize_platform_list(aliases, jobs['flags']['builds'], args.platforms)
+    tests = normalize_test_list(aliases, jobs['flags']['tests'], args.tests)
 
     result = []
 
     # Expand the matrix of things!
     for platform in platforms:
         # Silently skip unknown platforms.
         if platform not in jobs['builds']:
             continue
--- a/testing/taskcluster/tests/test_commit_parser.py
+++ b/testing/taskcluster/tests/test_commit_parser.py
@@ -11,37 +11,49 @@ from taskcluster_graph.commit_parser imp
     normalize_test_list,
     InvalidCommitException
 )
 
 class TestCommitParser(unittest.TestCase):
 
     def test_normalize_test_list_none(self):
         self.assertEqual(
-            normalize_test_list(['woot'], 'none'), []
+            normalize_test_list({}, ['woot'], 'none'), []
         )
 
     def test_normalize_test_list_all(self):
         self.assertEqual(
-            normalize_test_list(['woot'], 'all'),
+            normalize_test_list({}, ['woot'], 'all'),
             [{ 'test': 'woot' }]
         )
 
     def test_normalize_test_list_specific_tests(self):
         self.assertEqual(
-            normalize_test_list(['woot'], 'a,b,c'),
+            normalize_test_list({}, ['woot'], 'a,b,c'),
             [{ 'test': 'a' }, { 'test': 'b' }, { 'test': 'c' }]
         )
 
     def test_normalize_test_list_specific_tests_with_whitespace(self):
         self.assertEqual(
-            normalize_test_list(['woot'], 'a, b, c'),
+            normalize_test_list({}, ['woot'], 'a, b, c'),
             [{ 'test': 'a' }, { 'test': 'b' }, { 'test': 'c' }]
         )
 
+    def test_normalize_test_list_with_alias(self):
+        self.assertEqual(
+            normalize_test_list({ "a": "alpha" }, ['woot'], 'a, b, c'),
+            [{ 'test': 'alpha' }, { 'test': 'b' }, { 'test': 'c' }]
+        )
+
+    def test_normalize_test_list_with_alias_and_chunk(self):
+        self.assertEqual(
+            normalize_test_list({ "a": "alpha" }, ['woot'], 'a-1, a-3'),
+            [{ 'test': 'alpha', "only_chunks": set([1, 3])  }]
+        )
+
     def test_invalid_commit(self):
         '''
         Disallow invalid commit messages from being parsed...
         '''
         with self.assertRaises(InvalidCommitException):
             parse_commit("wootbarbaz", {})
 
     def test_commit_no_tests(self):
@@ -75,16 +87,52 @@ class TestCommitParser(unittest.TestCase
                 'dependents': [],
                 'additional-parameters': {}
             }
         ]
 
         result = parse_commit(commit, jobs)
         self.assertEqual(expected, result)
 
+    def test_flag_aliasing(self):
+        commit = 'try: -b o -p magic-alias -u none -t none'
+        jobs = {
+            'flags': {
+                'aliases': {
+                    'magic-alias': 'linux'
+                },
+                'builds': ['linux', 'linux64'],
+                'tests': ['web-platform-tests'],
+            },
+            'builds': {
+                'linux': {
+                    'types': {
+                        'opt': {
+                            'task': 'task/linux',
+                         },
+                        'debug': {
+                            'task': 'task/linux-debug'
+                        }
+                    }
+                },
+            },
+            'tests': {}
+        }
+
+        expected = [
+            {
+                'task': 'task/linux',
+                'dependents': [],
+                'additional-parameters': {}
+            }
+        ]
+
+        result = parse_commit(commit, jobs)
+        self.assertEqual(expected, result)
+
     def test_try_flag_in_middle_of_commit(self):
         '''
         The try command prefix may appear anywhere this test ensures that it
         works in some common cases.
         '''
         commit = 'Bug XXX - I like cheese try: -b o -p all -u none wootbar'
         jobs = {
             'flags': {