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 | |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 6 | from 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. |
| 14 | provision_labels = locals().get('provision_labels') or ','.join(args) |
| 15 | |
| 16 | |
| 17 | def 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 Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame] | 30 | "Can't provision label '%s'. Skipping." % label) |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 31 | |
| 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. |
beeps | 7da4bda | 2013-10-15 07:20:12 -0700 | [diff] [blame] | 38 | success = job.run_test(test, host=host, value=value) |
Alex Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame] | 39 | if not success: |
| 40 | raise Exception('Provisioning %s:%s failed on %s' % |
| 41 | (name, value, machine)) |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 42 | except Exception as e: |
J. Richard Barnette | f34897a | 2013-12-03 11:18:03 -0800 | [diff] [blame] | 43 | job.record('END FAIL', None, 'provision', str(e)) |
Alex Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame] | 44 | # (Re)raising the exception serves two purposes here: |
| 45 | # 1. The scheduler only looks at the return code of autoserv to see if |
| 46 | # the special task failed. Raising an exception here will get autoserv |
| 47 | # to exit with a non-zero exit code because of an unhandled exception. |
| 48 | # This then triggers the failure condition in ProvisionTask's epilog, |
| 49 | # which leads us into... |
| 50 | # 2. This exception ends up triggering server_job to write an INFO line |
J. Richard Barnette | f34897a | 2013-12-03 11:18:03 -0800 | [diff] [blame] | 51 | # with job_abort_reason equal to str(e), which is how str(e) |
Alex Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame] | 52 | # appears as the reason field for the job when the status.log we |
| 53 | # generate is parsed as the job's results. |
| 54 | raise |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 55 | else: |
Alex Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame] | 56 | # If we finish successfully, nothing in autotest ever looks at the |
| 57 | # status.log, so it's purely for human consumption and tracability. |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 58 | job.record('END GOOD', None, 'provision', |
| 59 | '%s provisioned successfully' % machine) |
| 60 | |
| 61 | |
| 62 | job.parallel_simple(provision_machine, machines) |
| 63 | |
| 64 | # vim: set syntax=python : |