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: |
Alex Miller | edb936d | 2013-12-05 16:53:21 -0800 | [diff] [blame^] | 40 | raise Exception('This exception will be immediately discarded,' |
| 41 | ' and exists only to force all errors to the' |
| 42 | ' same error handling codepath below.') |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 43 | except Exception as e: |
Alex Miller | edb936d | 2013-12-05 16:53:21 -0800 | [diff] [blame^] | 44 | job.record('END FAIL', None, 'provision') |
| 45 | # Raising a blank exception is done here because any message we can |
| 46 | # give here would be less useful than whatever the failing test left as |
| 47 | # its own exception message. |
| 48 | # |
| 49 | # The gory details of how raising a blank exception accomplishes this |
| 50 | # is as follows: |
| 51 | # |
| 52 | # The scheduler only looks at the return code of autoserv to see if |
| 53 | # the special task failed. Therefore we need python to exit because |
| 54 | # of an unhandled exception or because someone called sys.exit(1). |
| 55 | # |
| 56 | # We can't call sys.exit, since there's post-job-running logic (like |
| 57 | # cleanup) that we'd be skipping out on. So therefore, we need to |
| 58 | # raise an exception. However, if we raise an exception, this |
| 59 | # exception ends up triggering server_job to write an INFO line with |
| 60 | # job_abort_reason equal to str(e), which the tko parser then picks |
| 61 | # up as the reason field for the job when the status.log we generate is |
| 62 | # parsed as the job's results. |
| 63 | # |
| 64 | # So therefore, we raise a blank exception, which then generates an |
| 65 | # empty job_abort_reason which the tko parser ignores just inserts as |
| 66 | # a SERVER_JOB failure with no reason, which we then ignore at suite |
| 67 | # results reporting time. |
| 68 | raise Exception('') |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 69 | else: |
Alex Miller | dfff2fd | 2013-05-28 13:05:06 -0700 | [diff] [blame] | 70 | # If we finish successfully, nothing in autotest ever looks at the |
| 71 | # status.log, so it's purely for human consumption and tracability. |
Alex Miller | 0516e4c | 2013-06-03 18:07:48 -0700 | [diff] [blame] | 72 | job.record('END GOOD', None, 'provision', |
| 73 | '%s provisioned successfully' % machine) |
| 74 | |
| 75 | |
| 76 | job.parallel_simple(provision_machine, machines) |
| 77 | |
| 78 | # vim: set syntax=python : |