blob: 6cef6f3508c17caf556fd5dc55abc70f2eae1c5a [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:
Alex Milleredb936d2013-12-05 16:53:21 -080040 raise Exception('This exception will be immediately discarded,'
41 ' and exists only to force all errors to the'
42 ' same error handling codepath below.')
Alex Miller0516e4c2013-06-03 18:07:48 -070043 except Exception as e:
Alex Milleredb936d2013-12-05 16:53:21 -080044 job.record('END FAIL', None, 'provision')
45 # Raising a blank exception is done here because any message we can
46 # give here would be less useful than whatever the failing test left as
47 # its own exception message.
48 #
49 # The gory details of how raising a blank exception accomplishes this
50 # is as follows:
51 #
52 # The scheduler only looks at the return code of autoserv to see if
53 # the special task failed. Therefore we need python to exit because
54 # of an unhandled exception or because someone called sys.exit(1).
55 #
56 # We can't call sys.exit, since there's post-job-running logic (like
57 # cleanup) that we'd be skipping out on. So therefore, we need to
58 # raise an exception. However, if we raise an exception, this
59 # exception ends up triggering server_job to write an INFO line with
60 # job_abort_reason equal to str(e), which the tko parser then picks
61 # up as the reason field for the job when the status.log we generate is
62 # parsed as the job's results.
63 #
64 # So therefore, we raise a blank exception, which then generates an
65 # empty job_abort_reason which the tko parser ignores just inserts as
66 # a SERVER_JOB failure with no reason, which we then ignore at suite
67 # results reporting time.
68 raise Exception('')
Alex Miller0516e4c2013-06-03 18:07:48 -070069 else:
Alex Millerdfff2fd2013-05-28 13:05:06 -070070 # If we finish successfully, nothing in autotest ever looks at the
71 # status.log, so it's purely for human consumption and tracability.
Alex Miller0516e4c2013-06-03 18:07:48 -070072 job.record('END GOOD', None, 'provision',
73 '%s provisioned successfully' % machine)
74
75
76job.parallel_simple(provision_machine, machines)
77
78# vim: set syntax=python :