[autotest] Special task control segments take label-dependant actions
Autoserv accepts the labels of a job via the --job-labels argument, and
feeds them into the control segment by injecting the variable
`job_labels` into the global namespace.
cleanup/verify/repair/reset now use the same sort of loop that provision
does to look up additional tests to run that depend on the labels passed
into the control segment.
Note that some care has to be taken here, as we're moving the labels
from --provision to --job-labels, and I'd rather remove a bit of
migration code later than make for a complicated deploy.
BUG=chromium:334418
TEST=special tasks still run fine
Change-Id: I1596b49905f1500e8ce01e81d9aab2a6c7db111f
Reviewed-on: https://chromium-review.googlesource.com/188454
Tested-by: Alex Miller <milleral@chromium.org>
Reviewed-by: Fang Deng <fdeng@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Alex Miller <milleral@chromium.org>
diff --git a/server/cros/provision.py b/server/cros/provision.py
index 49bedb5..b012786 100644
--- a/server/cros/provision.py
+++ b/server/cros/provision.py
@@ -211,6 +211,53 @@
return '%s:%s' % (provision_type, provision_value)
+class SpecialTaskActionException(Exception):
+ """
+ Exception raised when a special task fails to successfully run a test that
+ is required.
+
+ This is also a literally meaningless exception. It's always just discarded.
+ """
+
+
+def run_special_task_actions(job, host, labels, task):
+ """
+ Iterate through all `label`s and run any tests on `host` that `task` has
+ corresponding to the passed in labels.
+
+ Emits status lines for each run test, and INFO lines for each skipped label.
+
+ @param job: A job object from a control file.
+ @param host: The host to run actions on.
+ @param labels: The list of job labels to work on.
+ @param task: An instance of _SpecialTaskAction.
+ @returns: None
+ @raises: SpecialTaskActionException if a test fails.
+
+ """
+ capabilities, configuration = filter_labels(labels)
+
+ for label in capabilities:
+ if task.acts_on(label):
+ test = task.test_for(label)
+ success = job.run_test(test, host=host)
+ if not success:
+ raise SpecialTaskActionException()
+ else:
+ job.record('INFO', None, task.name,
+ "Can't %s label '%s'." % (task.name, label))
+
+ for name, value in split_labels(configuration).items():
+ if task.acts_on(name):
+ test = task.test_for(name)
+ success = job.run_test(test, host=host, value=value)
+ if not success:
+ raise SpecialTaskActionException()
+ else:
+ job.record('INFO', None, task.name,
+ "Can't %s label '%s:%s'." % (task.name, name, value))
+
+
# This has been copied out of dynamic_suite's reimager.py, which no longer
# exists. I'd prefer if this would go away by doing http://crbug.com/249424,
# so that labels are just automatically made when we try to add them to a host.