[autotest] Add a config to skip enforcing builds arg in suite job.

This is to allow testing older builds in Moblab, especially builds with suite
control files on private repo, that were not updated to the latest format.

TEST=unittest, local run suite

Change-Id: Ia0a653d24857f4bfc3d23830e18024771c4f55b5
Reviewed-on: https://chromium-review.googlesource.com/341730
Commit-Ready: Dan Shi <dshi@google.com>
Tested-by: Dan Shi <dshi@google.com>
Reviewed-by: John Carey <ranix@google.com>
diff --git a/global_config.ini b/global_config.ini
index 2dc99dc..a0ff00d 100644
--- a/global_config.ini
+++ b/global_config.ini
@@ -87,6 +87,8 @@
 # Set to True to allow servod to be started automatically in Moblab.
 auto_start_servod: False
+support_builds_arg_in_suite_job: True
 drop_caches: False
 drop_caches_between_iterations: False
diff --git a/server/cros/dynamic_suite/dynamic_suite.py b/server/cros/dynamic_suite/dynamic_suite.py
index 6acbd56..805a010 100644
--- a/server/cros/dynamic_suite/dynamic_suite.py
+++ b/server/cros/dynamic_suite/dynamic_suite.py
@@ -10,6 +10,7 @@
 from autotest_lib.client.common_lib import base_job
 from autotest_lib.client.common_lib import error
+from autotest_lib.client.common_lib import global_config
 from autotest_lib.client.common_lib import priorities
 from autotest_lib.client.common_lib import time_utils
 from autotest_lib.client.common_lib import utils
@@ -22,7 +23,6 @@
 from autotest_lib.tko import utils as tko_utils
 """CrOS dynamic test suite generation and execution module.
 This module implements runtime-generated test suites for CrOS.
@@ -197,6 +197,16 @@
 DEFAULT_TRY_JOB_TIMEOUT_MINS = tools.try_job_timeout_mins()
+# For builds older than R50 and suite control files in private repos, the suite
+# control files may not be updated to the new format, i.e., making call like:
+#   dynamic_suite.reimage_and_run(**args_dict)
+# The config AUTOSERV/support_builds_arg_in_suite_job can be manually set to
+# False to support these suite control files.
+# TODO (dshi): Remove this config once R52 is off the stable channel and there
+# is no more need to test older builds.
+SUPPORT_BUILDS_ARG = global_config.global_config.get_config_value(
+        'AUTOSERV', 'support_builds_arg_in_suite_job', type=bool, default=True)
 # Relevant CrosDynamicSuiteExceptions are defined in client/common_lib/error.py.
 class SuiteSpec(object):
@@ -316,8 +326,19 @@
         required_keywords = {'board': str,
                              'name': str,
                              'job': base_job.base_job,
-                             'devserver_url': str,
-                             'builds': dict}
+                             'devserver_url': str}
+            required_keywords['builds'] = dict
+        else:
+            logging.debug('Global config AUTOSERV/'
+                          'support_builds_arg_in_suite_job is set to False. '
+                          'Skip enforcing `builds` argument in the suite job.')
+            build = dargs.get('build')
+            if not build:
+                raise  error.SuiteArgumentException(
+                        'reimage_and_run() needs argument `build` or `builds`.')
+            builds = {provision.CROS_VERSION_PREFIX: build}
         for key, expected in required_keywords.iteritems():
             value = locals().get(key)
             if not value or not isinstance(value, expected):