Teach the devserver to get control files for a specific suite.
Today the devserver is only capable of fecthing a list of
all control files. This cl adds a method that consults
a suite->control file map generated at build time, and returns
a list of control files for a specific suite.
BUG=chromium:252398, chromium:260980
TEST=Ran a suite with several control files and confirmed
that the tests are parsed in the same way as they were
when all control files were returned. Confirmed the
fallback path of just fetching all control files when
a suite not in the suite->control file map is specified.
CQ-DEPEND=CL:I5b42044c3e8242643e6576f96e0a7f98d4b96884
Change-Id: I6b590c8c40a863e6744875a26ac228ffd4dd8794
Reviewed-on: https://gerrit.chromium.org/gerrit/61623
Commit-Queue: Prashanth Balasubramanian <beeps@chromium.org>
Reviewed-by: Prashanth Balasubramanian <beeps@chromium.org>
Tested-by: Prashanth Balasubramanian <beeps@chromium.org>
diff --git a/common_util.py b/common_util.py
index 29cb8f1..385d083 100644
--- a/common_util.py
+++ b/common_util.py
@@ -4,6 +4,7 @@
"""Helper class for interacting with the Dev Server."""
+import ast
import base64
import binascii
import distutils.version
@@ -123,6 +124,44 @@
return control_file.read()
+def GetControlFileListForSuite(static_dir, build, suite_name):
+ """List all control files for a specified build, for the given suite.
+
+ If the specified suite_name isn't found in the suite to control file
+ map, this method will return all control files for the build by calling
+ GetControlFileList.
+
+ Args:
+ static_dir: Directory where builds are served from.
+ build: Fully qualified build string; e.g. R17-1234.0.0-a1-b983.
+ suite_name: Name of the suite for which we require control files.
+
+ Raises:
+ CommonUtilError: If the suite_to_control_file_map isn't found in
+ the specified build's staged directory.
+
+ Returns:
+ String of each control file separated by a newline.
+ """
+ suite_to_control_map = os.path.join(static_dir, build,
+ 'autotest', 'test_suites',
+ 'suite_to_control_file_map')
+
+ if not PathInDir(static_dir, suite_to_control_map):
+ raise CommonUtilError('suite_to_control_map not in "%s".' %
+ suite_to_control_map)
+
+ if not os.path.exists(suite_to_control_map):
+ raise CommonUtilError('Could not find this file. '
+ 'Is it staged? %s' % suite_to_control_map)
+
+ with open(suite_to_control_map, 'r') as fd:
+ try:
+ return '\n'.join(ast.literal_eval(fd.read())[suite_name])
+ except KeyError:
+ return GetControlFileList(static_dir, build)
+
+
def GetControlFileList(static_dir, build):
"""List all control|control. files in the specified board/build path.