[autotest]: Run suites from AFE.
* Updated the AFE to allow for suite runs. When an image is provided
the create_job RPC will redirect to the create_suite_job RPC instead.
* Updated create_suite_job to allow for a control_file to be supplied.
create_suite_job will use this control file rather than what the
devserver stages when it creates the suite job.
* Removed the parameterized job code from create_job as it is not used
and broken.
* The create_job page now includes a 'Pool' text box to specify for
these jobs.
BUG=chromium:358579
TEST=Able to launch suite jobs from run_suite and AFE. And regular tests
kicked off via the AFE still work as well. rpc_interface and
site_rpc_interface unittests, suite_scheduler unittests.
DEPLOY=apache,afe,suite_scheduler
Change-Id: I53312419c32740e78fc07598babeb497c162ba81
Reviewed-on: https://chromium-review.googlesource.com/194349
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Simran Basi <sbasi@chromium.org>
Tested-by: Simran Basi <sbasi@chromium.org>
diff --git a/frontend/afe/site_rpc_interface.py b/frontend/afe/site_rpc_interface.py
index f69da13..aa7c349 100644
--- a/frontend/afe/site_rpc_interface.py
+++ b/frontend/afe/site_rpc_interface.py
@@ -13,6 +13,7 @@
from autotest_lib.client.common_lib import error
from autotest_lib.client.common_lib import priorities
from autotest_lib.client.common_lib.cros import dev_server
+from autotest_lib.server import utils
from autotest_lib.server.cros.dynamic_suite import constants
from autotest_lib.server.cros.dynamic_suite import control_file_getter
from autotest_lib.server.cros.dynamic_suite import job_status
@@ -43,14 +44,13 @@
return datetime.datetime.now().strftime(job_status.TIME_FMT)
-def get_control_file_contents_by_name(build, board, ds, suite_name):
+def _get_control_file_contents_by_name(build, ds, suite_name):
"""Return control file contents for |suite_name|.
Query the dev server at |ds| for the control file |suite_name|, included
in |build| for |board|.
@param build: unique name by which to refer to the image from now on.
- @param board: the kind of device to run the tests on.
@param ds: a dev_server.DevServer instance to fetch control file with.
@param suite_name: canonicalized suite name, e.g. test_suites/control.bvt.
@raises ControlFileNotFound if a unique suite control file doesn't exist.
@@ -65,7 +65,7 @@
try:
control_file_in = getter.get_control_file_contents_by_name(suite_name)
except error.CrosDynamicSuiteException as e:
- raise type(e)("%s while testing %s for %s." % (e, build, board))
+ raise type(e)("%s while testing %s." % (e, build))
if not control_file_in:
raise error.ControlFileEmpty(
"Fetching %s returned no data." % suite_name)
@@ -78,17 +78,44 @@
return control_file_in
-def create_suite_job(suite_name, board, build, pool, check_hosts=True,
- num=None, file_bugs=False, timeout=24, timeout_mins=None,
- priority=priorities.Priority.DEFAULT,
- suite_args=None, wait_for_results=True):
+def _stage_build_artifacts(build):
+ """
+ Ensure components of |build| necessary for installing images are staged.
+
+ @param build image we want to stage.
+
+ @raises StageBuildFailure: if the dev server throws 500 while staging
+ build.
+
+ @return: dev_server.ImageServer instance to use with this build.
+ @return: timings dictionary containing staging start/end times.
+ """
+ timings = {}
+ # Set synchronous to False to allow other components to be downloaded in
+ # the background.
+ ds = dev_server.ImageServer.resolve(build)
+ timings[constants.DOWNLOAD_STARTED_TIME] = formatted_now()
+ try:
+ ds.stage_artifacts(build, ['test_suites'])
+ except dev_server.DevServerException as e:
+ raise error.StageBuildFailure(
+ "Failed to stage %s: %s" % (build, e))
+ timings[constants.PAYLOAD_FINISHED_TIME] = formatted_now()
+ return (ds, timings)
+
+
+def create_suite_job(name='', board='', build='', pool='', control_file='',
+ check_hosts=True, num=None, file_bugs=False, timeout=24,
+ timeout_mins=None, priority=priorities.Priority.DEFAULT,
+ suite_args=None, wait_for_results=True, **kwargs):
"""
Create a job to run a test suite on the given device with the given image.
When the timeout specified in the control file is reached, the
job is guaranteed to have completed and results will be available.
- @param suite_name: the test suite to run, e.g. 'bvt'.
+ @param name: The test name if control_file is supplied, otherwise the name
+ of the test suite to run, e.g. 'bvt'.
@param board: the kind of device to run the tests on.
@param build: unique name by which to refer to the image from now on.
@param pool: Specify the pool of machines to use for scheduling
@@ -106,6 +133,7 @@
determine which tests to run.
@param wait_for_results: Set to False to run the suite job without waiting
for test jobs to finish. Default is True.
+ @param kwargs: extra keyword args. NOT USED.
@raises ControlFileNotFound: if a unique suite control file doesn't exist.
@raises NoControlFileList: if we can't list the control files at all.
@@ -115,8 +143,6 @@
@return: the job ID of the suite; -1 on error.
"""
- # All suite names are assumed under test_suites/control.XX.
- suite_name = canonicalize_suite_name(suite_name)
if type(num) is not int and num is not None:
raise error.SuiteArgumentException('Ill specified num argument %r. '
'Must be an integer or None.' % num)
@@ -124,26 +150,20 @@
logging.warning("Can't run on 0 hosts; using default.")
num = None
- timings = {}
- # Ensure components of |build| necessary for installing images are staged
- # on the dev server. However set synchronous to False to allow other
- # components to be downloaded in the background.
- ds = dev_server.ImageServer.resolve(build)
- timings[constants.DOWNLOAD_STARTED_TIME] = formatted_now()
- try:
- ds.stage_artifacts(build, ['test_suites'])
- except dev_server.DevServerException as e:
- raise error.StageBuildFailure(
- "Failed to stage %s for %s: %s" % (build, board, e))
- timings[constants.PAYLOAD_FINISHED_TIME] = formatted_now()
+ (ds, timings) = _stage_build_artifacts(build)
- control_file_in = get_control_file_contents_by_name(build, board, ds,
- suite_name)
+ if not control_file:
+ # No control file was supplied so look it up from the build artifacts.
+ suite_name = canonicalize_suite_name(name)
+ control_file = _get_control_file_contents_by_name(build, ds, suite_name)
+ name = '%s-%s' % (build, suite_name)
timeout_mins = timeout_mins or timeout * 60
+ if not board:
+ board = utils.ParseBuildName(build)[0]
- # prepend build and board to the control file
+ # Prepend build and board to the control file.
inject_dict = {'board': board,
'build': build,
'check_hosts': check_hosts,
@@ -158,9 +178,9 @@
'wait_for_results': wait_for_results
}
- control_file = tools.inject_vars(inject_dict, control_file_in)
+ control_file = tools.inject_vars(inject_dict, control_file)
- return _rpc_utils().create_job_common('%s-%s' % (build, suite_name),
+ return _rpc_utils().create_job_common(name,
priority=priority,
timeout_mins=timeout_mins,
max_runtime_mins=timeout*60,