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 | |
| 6 | from autotest_lib.client.common_lib import utils |
| 7 | from 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. |
| 15 | provision_labels = locals().get('provision_labels') or ','.join(args) |
| 16 | |
| 17 | |
| 18 | def 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 Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame^] | 31 | "Can't provision label '%s'. Skipping." % label) |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 32 | |
| 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. |
Alex Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame^] | 39 | success = job.run_test(test, host=host, value=value, |
| 40 | disable_sysinfo=True) |
| 41 | if not success: |
| 42 | raise Exception('Provisioning %s:%s failed on %s' % |
| 43 | (name, value, machine)) |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 44 | except Exception as e: |
Alex Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame^] | 45 | job.record('END FAIL', None, 'provision', e.message) |
| 46 | # (Re)raising the exception serves two purposes here: |
| 47 | # 1. The scheduler only looks at the return code of autoserv to see if |
| 48 | # the special task failed. Raising an exception here will get autoserv |
| 49 | # to exit with a non-zero exit code because of an unhandled exception. |
| 50 | # This then triggers the failure condition in ProvisionTask's epilog, |
| 51 | # which leads us into... |
| 52 | # 2. This exception ends up triggering server_job to write an INFO line |
| 53 | # with job_abort_reason equal to e.message, which is how e.message |
| 54 | # appears as the reason field for the job when the status.log we |
| 55 | # generate is parsed as the job's results. |
| 56 | raise |
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 : |