blob: bc1acf5ee5e790a80eff6987eded1c63d7c96537 [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
6from autotest_lib.client.common_lib import utils
7from autotest_lib.server.cros import provision
8
9
10# provision_labels should be a string like "name:setting,name:setting"
11# non-provisionable labels are currently skipped, so they're safe to pass in.
12# However, this is more of a current safeguard/leftover from some shady code in
13# the proof of concept, so I don't assure that passing in non-provisionable
14# labels will always be an okay and accepted thing to do.
15provision_labels = locals().get('provision_labels') or ','.join(args)
16
17
18def provision_machine(machine):
19 """
20 Run the appropriate provisioning tests to make the machine's labels match
21 those given in provision_labels.
22 """
23 host = hosts.create_host(machine)
24
25 labels_list = provision_labels.split(',')
26 fixed, provisionable = provision.filter_labels(labels_list)
27
28 job.record('START', None, 'provision')
29 for label in fixed:
30 job.record('INFO', None, 'provision',
Alex Millerdfff2fd2013-05-28 13:05:06 -070031 "Can't provision label '%s'. Skipping." % label)
Alex Miller0516e4c2013-06-03 18:07:48 -070032
33 try:
34 for name, value in provision.split_labels(provisionable).items():
35 test = provision.provisioner_for(name)
36 # sysinfo isn't really going to get us anything incredibly
37 # interesting here, and it takes a non-trivial amount of time, so
38 # we might as well just turn it off.
beeps7da4bda2013-10-15 07:20:12 -070039 success = job.run_test(test, host=host, value=value)
Alex Millerdfff2fd2013-05-28 13:05:06 -070040 if not success:
41 raise Exception('Provisioning %s:%s failed on %s' %
42 (name, value, machine))
Alex Miller0516e4c2013-06-03 18:07:48 -070043 except Exception as e:
Alex Millerdfff2fd2013-05-28 13:05:06 -070044 job.record('END FAIL', None, 'provision', e.message)
45 # (Re)raising the exception serves two purposes here:
46 # 1. The scheduler only looks at the return code of autoserv to see if
47 # the special task failed. Raising an exception here will get autoserv
48 # to exit with a non-zero exit code because of an unhandled exception.
49 # This then triggers the failure condition in ProvisionTask's epilog,
50 # which leads us into...
51 # 2. This exception ends up triggering server_job to write an INFO line
52 # with job_abort_reason equal to e.message, which is how e.message
53 # appears as the reason field for the job when the status.log we
54 # generate is parsed as the job's results.
55 raise
Alex Miller0516e4c2013-06-03 18:07:48 -070056 else:
Alex Millerdfff2fd2013-05-28 13:05:06 -070057 # If we finish successfully, nothing in autotest ever looks at the
58 # status.log, so it's purely for human consumption and tracability.
Alex Miller0516e4c2013-06-03 18:07:48 -070059 job.record('END GOOD', None, 'provision',
60 '%s provisioned successfully' % machine)
61
62
63job.parallel_simple(provision_machine, machines)
64
65# vim: set syntax=python :