Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 1 | import sys |
| 2 | |
Richard Barnette | 28aa689 | 2016-06-10 13:00:58 -0700 | [diff] [blame] | 3 | from autotest_lib.server import utils |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 4 | from autotest_lib.server.cros import provision |
| 5 | |
Dan Shi | 5e2efb7 | 2017-02-07 11:40:23 -0800 | [diff] [blame] | 6 | try: |
| 7 | from chromite.lib import metrics |
| 8 | except ImportError: |
| 9 | metrics = utils.metrics_mock |
| 10 | |
| 11 | |
Prathmesh Prabhu | a7556a9 | 2017-02-01 14:18:41 -0800 | [diff] [blame] | 12 | DURATION_METRIC = 'chromeos/autotest/autoserv/reset_duration' |
Allen Li | 41d531b | 2016-11-22 13:21:52 -0800 | [diff] [blame] | 13 | |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 14 | |
| 15 | # A string of the form 'label1,label2:value,label3'. |
| 16 | job_labels = locals().get('job_labels') or ','.join(args) |
| 17 | labels_list = [l.strip() for l in job_labels.split(',') if l] |
| 18 | |
Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 19 | |
| 20 | def reset(machine): |
Simran Basi | 1bf60eb | 2015-12-01 16:39:29 -0800 | [diff] [blame] | 21 | print 'Starting to reset host %s' % machine |
Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 22 | try: |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 23 | job.record('START', None, 'reset') |
Richard Barnette | 18dc888 | 2016-08-11 17:08:48 -0700 | [diff] [blame] | 24 | target = hosts.create_target_machine(machine) |
Allen Li | 41d531b | 2016-11-22 13:21:52 -0800 | [diff] [blame] | 25 | hostname = utils.get_hostname_from_machine(machine) |
| 26 | with metrics.SecondsTimer(DURATION_METRIC, |
| 27 | fields={'dut_host_name': hostname}): |
| 28 | # Assume cleanup always runs first. |
| 29 | target.cleanup() |
Allen Li | 24b1e6f | 2019-01-04 16:31:32 -0800 | [diff] [blame] | 30 | provision.Cleanup.run_task_actions(job, target, labels_list) |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 31 | |
Allen Li | 41d531b | 2016-11-22 13:21:52 -0800 | [diff] [blame] | 32 | target.verify() |
Allen Li | 24b1e6f | 2019-01-04 16:31:32 -0800 | [diff] [blame] | 33 | provision.Verify.run_task_actions(job, target, labels_list) |
Aviv Keshet | 5ae0a00 | 2017-05-05 10:23:33 -0700 | [diff] [blame] | 34 | except Exception: |
| 35 | logging.exception('Reset failed due to Exception.') |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 36 | job.record('END FAIL', None, 'reset') |
| 37 | # See the provision control segment for the explanation of why we're |
| 38 | # doing this. |
| 39 | raise Exception('') |
| 40 | else: |
Richard Barnette | 28aa689 | 2016-06-10 13:00:58 -0700 | [diff] [blame] | 41 | hostname = utils.get_hostname_from_machine(machine) |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 42 | job.record('END GOOD', None, 'reset', |
Richard Barnette | 28aa689 | 2016-06-10 13:00:58 -0700 | [diff] [blame] | 43 | '%s reset successfully' % hostname) |
Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 44 | |
| 45 | |
| 46 | job.parallel_simple(reset, machines) |
Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 47 | |
| 48 | # vim: set syntax=python : |