blob: 9da202c5ca62a482bbf0483b74b3ac57ffd0cf70 [file] [log] [blame]
Alex Miller0516e4c2013-06-03 18:07:48 -07001# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
Alex Miller0516e4c2013-06-03 18:07:48 -07006from autotest_lib.server.cros import provision
7
8
9# provision_labels should be a string like "name:setting,name:setting"
10# non-provisionable labels are currently skipped, so they're safe to pass in.
11# However, this is more of a current safeguard/leftover from some shady code in
12# the proof of concept, so I don't assure that passing in non-provisionable
13# labels will always be an okay and accepted thing to do.
14provision_labels = locals().get('provision_labels') or ','.join(args)
15
16
17def provision_machine(machine):
18 """
19 Run the appropriate provisioning tests to make the machine's labels match
20 those given in provision_labels.
21 """
22 host = hosts.create_host(machine)
23
24 labels_list = provision_labels.split(',')
25 fixed, provisionable = provision.filter_labels(labels_list)
26
27 job.record('START', None, 'provision')
28 for label in fixed:
29 job.record('INFO', None, 'provision',
Alex Millerdfff2fd2013-05-28 13:05:06 -070030 "Can't provision label '%s'. Skipping." % label)
Alex Miller0516e4c2013-06-03 18:07:48 -070031
32 try:
33 for name, value in provision.split_labels(provisionable).items():
34 test = provision.provisioner_for(name)
35 # sysinfo isn't really going to get us anything incredibly
36 # interesting here, and it takes a non-trivial amount of time, so
37 # we might as well just turn it off.
beeps7da4bda2013-10-15 07:20:12 -070038 success = job.run_test(test, host=host, value=value)
Alex Millerdfff2fd2013-05-28 13:05:06 -070039 if not success:
40 raise Exception('Provisioning %s:%s failed on %s' %
41 (name, value, machine))
Alex Miller0516e4c2013-06-03 18:07:48 -070042 except Exception as e:
J. Richard Barnettef34897a2013-12-03 11:18:03 -080043 job.record('END FAIL', None, 'provision', str(e))
Alex Millerdfff2fd2013-05-28 13:05:06 -070044 # (Re)raising the exception serves two purposes here:
45 # 1. The scheduler only looks at the return code of autoserv to see if
46 # the special task failed. Raising an exception here will get autoserv
47 # to exit with a non-zero exit code because of an unhandled exception.
48 # This then triggers the failure condition in ProvisionTask's epilog,
49 # which leads us into...
50 # 2. This exception ends up triggering server_job to write an INFO line
J. Richard Barnettef34897a2013-12-03 11:18:03 -080051 # with job_abort_reason equal to str(e), which is how str(e)
Alex Millerdfff2fd2013-05-28 13:05:06 -070052 # appears as the reason field for the job when the status.log we
53 # generate is parsed as the job's results.
54 raise
Alex Miller0516e4c2013-06-03 18:07:48 -070055 else:
Alex Millerdfff2fd2013-05-28 13:05:06 -070056 # If we finish successfully, nothing in autotest ever looks at the
57 # status.log, so it's purely for human consumption and tracability.
Alex Miller0516e4c2013-06-03 18:07:48 -070058 job.record('END GOOD', None, 'provision',
59 '%s provisioned successfully' % machine)
60
61
62job.parallel_simple(provision_machine, machines)
63
64# vim: set syntax=python :