blob: d2503bcbcb7d7da1965acc415bbf9747bbc421e1 [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
Dan Shi2e251102014-01-13 15:31:17 -08006from autotest_lib.client.cros import constants
Alex Miller0516e4c2013-06-03 18:07:48 -07007from 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():
Dan Shi2e251102014-01-13 15:31:17 -080035 # Save preserved log after autoupdate is completed.
36 job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG)
37
Alex Miller0516e4c2013-06-03 18:07:48 -070038 test = provision.provisioner_for(name)
39 # sysinfo isn't really going to get us anything incredibly
40 # interesting here, and it takes a non-trivial amount of time, so
41 # we might as well just turn it off.
beeps7da4bda2013-10-15 07:20:12 -070042 success = job.run_test(test, host=host, value=value)
Alex Millerdfff2fd2013-05-28 13:05:06 -070043 if not success:
Alex Milleredb936d2013-12-05 16:53:21 -080044 raise Exception('This exception will be immediately discarded,'
45 ' and exists only to force all errors to the'
46 ' same error handling codepath below.')
Alex Miller0516e4c2013-06-03 18:07:48 -070047 except Exception as e:
Alex Milleredb936d2013-12-05 16:53:21 -080048 job.record('END FAIL', None, 'provision')
49 # Raising a blank exception is done here because any message we can
50 # give here would be less useful than whatever the failing test left as
51 # its own exception message.
52 #
53 # The gory details of how raising a blank exception accomplishes this
54 # is as follows:
55 #
56 # The scheduler only looks at the return code of autoserv to see if
57 # the special task failed. Therefore we need python to exit because
58 # of an unhandled exception or because someone called sys.exit(1).
59 #
60 # We can't call sys.exit, since there's post-job-running logic (like
61 # cleanup) that we'd be skipping out on. So therefore, we need to
62 # raise an exception. However, if we raise an exception, this
63 # exception ends up triggering server_job to write an INFO line with
64 # job_abort_reason equal to str(e), which the tko parser then picks
65 # up as the reason field for the job when the status.log we generate is
66 # parsed as the job's results.
67 #
68 # So therefore, we raise a blank exception, which then generates an
69 # empty job_abort_reason which the tko parser ignores just inserts as
70 # a SERVER_JOB failure with no reason, which we then ignore at suite
71 # results reporting time.
72 raise Exception('')
Alex Miller0516e4c2013-06-03 18:07:48 -070073 else:
Alex Millerdfff2fd2013-05-28 13:05:06 -070074 # If we finish successfully, nothing in autotest ever looks at the
75 # status.log, so it's purely for human consumption and tracability.
Alex Miller0516e4c2013-06-03 18:07:48 -070076 job.record('END GOOD', None, 'provision',
77 '%s provisioned successfully' % machine)
78
79
80job.parallel_simple(provision_machine, machines)
81
82# vim: set syntax=python :