blob: f1dfece32c4df88eb1feb9ebe210b68815a18f9b [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
Hsinyu Chaoe0b08e62015-08-11 10:50:37 +00006from autotest_lib.client.cros import constants
Alex Miller0516e4c2013-06-03 18:07:48 -07007from autotest_lib.server.cros import provision
8
9
Alex Miller667b5f22014-02-28 15:33:39 -080010# job_labels should be a string like "name:setting,name:setting"
Alex Miller0516e4c2013-06-03 18:07:48 -070011# non-provisionable labels are currently skipped, so they're safe to pass in.
Alex Miller667b5f22014-02-28 15:33:39 -080012job_labels = locals().get('job_labels') or ','.join(args)
13labels_list = [label.strip() for label in job_labels.split(',') if label]
Alex Miller0516e4c2013-06-03 18:07:48 -070014
15
16def provision_machine(machine):
17 """
18 Run the appropriate provisioning tests to make the machine's labels match
Alex Miller667b5f22014-02-28 15:33:39 -080019 those given in job_labels.
Alex Miller0516e4c2013-06-03 18:07:48 -070020 """
Fang Denge545abb2014-12-30 18:43:47 -080021 host = hosts.create_host(machine, try_lab_servo=True)
Alex Miller0516e4c2013-06-03 18:07:48 -070022
Alex Miller0516e4c2013-06-03 18:07:48 -070023 job.record('START', None, 'provision')
Alex Miller0516e4c2013-06-03 18:07:48 -070024 try:
Alex Miller667b5f22014-02-28 15:33:39 -080025 job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG)
26 provision.run_special_task_actions(job, host, labels_list,
27 provision.Provision)
Richard Barnette459592e2016-04-20 16:06:25 -070028 host.verify()
Alex Miller0516e4c2013-06-03 18:07:48 -070029 except Exception as e:
Alex Miller789d6f12014-05-02 13:11:15 -070030 logging.exception(e)
Alex Milleredb936d2013-12-05 16:53:21 -080031 job.record('END FAIL', None, 'provision')
32 # Raising a blank exception is done here because any message we can
33 # give here would be less useful than whatever the failing test left as
34 # its own exception message.
35 #
36 # The gory details of how raising a blank exception accomplishes this
37 # is as follows:
38 #
39 # The scheduler only looks at the return code of autoserv to see if
40 # the special task failed. Therefore we need python to exit because
41 # of an unhandled exception or because someone called sys.exit(1).
42 #
43 # We can't call sys.exit, since there's post-job-running logic (like
44 # cleanup) that we'd be skipping out on. So therefore, we need to
45 # raise an exception. However, if we raise an exception, this
46 # exception ends up triggering server_job to write an INFO line with
47 # job_abort_reason equal to str(e), which the tko parser then picks
48 # up as the reason field for the job when the status.log we generate is
49 # parsed as the job's results.
50 #
51 # So therefore, we raise a blank exception, which then generates an
52 # empty job_abort_reason which the tko parser ignores just inserts as
53 # a SERVER_JOB failure with no reason, which we then ignore at suite
54 # results reporting time.
55 raise Exception('')
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 :