blob: 2b15b17e86cd6d3c37dcb912f81032bff462a1b0 [file] [log] [blame]
Dan Shi07e09af2013-04-12 09:31:29 -07001import sys
2
Richard Barnette28aa6892016-06-10 13:00:58 -07003from autotest_lib.server import utils
Alex Miller667b5f22014-02-28 15:33:39 -08004from autotest_lib.server.cros import provision
5
Dan Shi5e2efb72017-02-07 11:40:23 -08006try:
7 from chromite.lib import metrics
8except ImportError:
9 metrics = utils.metrics_mock
10
11
Prathmesh Prabhua7556a92017-02-01 14:18:41 -080012DURATION_METRIC = 'chromeos/autotest/autoserv/reset_duration'
Allen Li41d531b2016-11-22 13:21:52 -080013
Alex Miller667b5f22014-02-28 15:33:39 -080014
15# A string of the form 'label1,label2:value,label3'.
16job_labels = locals().get('job_labels') or ','.join(args)
17labels_list = [l.strip() for l in job_labels.split(',') if l]
18
Dan Shi07e09af2013-04-12 09:31:29 -070019
20def reset(machine):
Simran Basi1bf60eb2015-12-01 16:39:29 -080021 print 'Starting to reset host %s' % machine
Dan Shi07e09af2013-04-12 09:31:29 -070022 try:
Alex Miller667b5f22014-02-28 15:33:39 -080023 job.record('START', None, 'reset')
Richard Barnette18dc8882016-08-11 17:08:48 -070024 target = hosts.create_target_machine(machine)
Allen Li41d531b2016-11-22 13:21:52 -080025 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 Li24b1e6f2019-01-04 16:31:32 -080030 provision.Cleanup.run_task_actions(job, target, labels_list)
Alex Miller667b5f22014-02-28 15:33:39 -080031
Allen Li41d531b2016-11-22 13:21:52 -080032 target.verify()
Allen Li24b1e6f2019-01-04 16:31:32 -080033 provision.Verify.run_task_actions(job, target, labels_list)
Aviv Keshet5ae0a002017-05-05 10:23:33 -070034 except Exception:
35 logging.exception('Reset failed due to Exception.')
Alex Miller667b5f22014-02-28 15:33:39 -080036 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 Barnette28aa6892016-06-10 13:00:58 -070041 hostname = utils.get_hostname_from_machine(machine)
Alex Miller667b5f22014-02-28 15:33:39 -080042 job.record('END GOOD', None, 'reset',
Richard Barnette28aa6892016-06-10 13:00:58 -070043 '%s reset successfully' % hostname)
Dan Shi07e09af2013-04-12 09:31:29 -070044
45
46job.parallel_simple(reset, machines)
Alex Miller667b5f22014-02-28 15:33:39 -080047
48# vim: set syntax=python :