Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 1 | # 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 | |
Eric Caruso | a4ac7a8 | 2015-08-06 10:53:54 -0700 | [diff] [blame] | 6 | from autotest_lib.client.common_lib.cros import constants |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 7 | from autotest_lib.server.cros import provision |
| 8 | |
| 9 | |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 10 | # job_labels should be a string like "name:setting,name:setting" |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 11 | # non-provisionable labels are currently skipped, so they're safe to pass in. |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 12 | job_labels = locals().get('job_labels') or ','.join(args) |
| 13 | labels_list = [label.strip() for label in job_labels.split(',') if label] |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 14 | |
| 15 | |
| 16 | def provision_machine(machine): |
| 17 | """ |
| 18 | Run the appropriate provisioning tests to make the machine's labels match |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 19 | those given in job_labels. |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 20 | """ |
Fang Deng | e545abb | 2014-12-30 18:43:47 -0800 | [diff] [blame] | 21 | host = hosts.create_host(machine, try_lab_servo=True) |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 22 | |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 23 | fixed, provisionable = provision.filter_labels(labels_list) |
| 24 | |
| 25 | job.record('START', None, 'provision') |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 26 | try: |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 27 | job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG) |
| 28 | provision.run_special_task_actions(job, host, labels_list, |
| 29 | provision.Provision) |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 30 | except Exception as e: |
Alex Miller | 789d6f1 | 2014-05-02 13:11:15 -0700 | [diff] [blame] | 31 | logging.exception(e) |
Alex Miller | edb936d | 2013-12-05 16:53:21 -0800 | [diff] [blame] | 32 | job.record('END FAIL', None, 'provision') |
| 33 | # Raising a blank exception is done here because any message we can |
| 34 | # give here would be less useful than whatever the failing test left as |
| 35 | # its own exception message. |
| 36 | # |
| 37 | # The gory details of how raising a blank exception accomplishes this |
| 38 | # is as follows: |
| 39 | # |
| 40 | # The scheduler only looks at the return code of autoserv to see if |
| 41 | # the special task failed. Therefore we need python to exit because |
| 42 | # of an unhandled exception or because someone called sys.exit(1). |
| 43 | # |
| 44 | # We can't call sys.exit, since there's post-job-running logic (like |
| 45 | # cleanup) that we'd be skipping out on. So therefore, we need to |
| 46 | # raise an exception. However, if we raise an exception, this |
| 47 | # exception ends up triggering server_job to write an INFO line with |
| 48 | # job_abort_reason equal to str(e), which the tko parser then picks |
| 49 | # up as the reason field for the job when the status.log we generate is |
| 50 | # parsed as the job's results. |
| 51 | # |
| 52 | # So therefore, we raise a blank exception, which then generates an |
| 53 | # empty job_abort_reason which the tko parser ignores just inserts as |
| 54 | # a SERVER_JOB failure with no reason, which we then ignore at suite |
| 55 | # results reporting time. |
| 56 | raise Exception('') |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 57 | else: |
Alex Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame] | 58 | # If we finish successfully, nothing in autotest ever looks at the |
| 59 | # status.log, so it's purely for human consumption and tracability. |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 60 | job.record('END GOOD', None, 'provision', |
| 61 | '%s provisioned successfully' % machine) |
| 62 | |
| 63 | |
| 64 | job.parallel_simple(provision_machine, machines) |
| 65 | |
| 66 | # vim: set syntax=python : |