blob: f4395f008043643053a40477152e9f55c31adeb2 [file] [log] [blame]
Dan Shi07e09af2013-04-12 09:31:29 -07001import sys
2
Gabe Black1e1c41b2015-02-04 23:55:15 -08003from autotest_lib.client.common_lib.cros.graphite import autotest_stats
Richard Barnette28aa6892016-06-10 13:00:58 -07004from autotest_lib.server import utils
Alex Miller667b5f22014-02-28 15:33:39 -08005from autotest_lib.server.cros import provision
6
7
8# A string of the form 'label1,label2:value,label3'.
9job_labels = locals().get('job_labels') or ','.join(args)
10labels_list = [l.strip() for l in job_labels.split(',') if l]
11
Dan Shi07e09af2013-04-12 09:31:29 -070012
13def reset(machine):
Simran Basi1bf60eb2015-12-01 16:39:29 -080014 print 'Starting to reset host %s' % machine
Dan Shi07e09af2013-04-12 09:31:29 -070015 timer = None
16 try:
Alex Miller667b5f22014-02-28 15:33:39 -080017 job.record('START', None, 'reset')
Richard Barnette18dc8882016-08-11 17:08:48 -070018 target = hosts.create_target_machine(machine)
Gabe Black1e1c41b2015-02-04 23:55:15 -080019 timer = autotest_stats.Timer('reset_time')
Dan Shi07e09af2013-04-12 09:31:29 -070020 timer.start()
Alex Miller667b5f22014-02-28 15:33:39 -080021
Dan Shi07e09af2013-04-12 09:31:29 -070022 # Assume cleanup always runs first.
Dan Shid7f12422016-01-04 11:51:32 -080023 target.cleanup()
24 provision.run_special_task_actions(job, target, labels_list,
Alex Miller667b5f22014-02-28 15:33:39 -080025 provision.Cleanup)
26
Dan Shid7f12422016-01-04 11:51:32 -080027 target.verify()
28 provision.run_special_task_actions(job, target, labels_list,
Alex Miller667b5f22014-02-28 15:33:39 -080029 provision.Verify)
Dan Shi07e09af2013-04-12 09:31:29 -070030 except Exception as e:
Alex Miller789d6f12014-05-02 13:11:15 -070031 logging.exception(e)
Alex Miller667b5f22014-02-28 15:33:39 -080032 job.record('END FAIL', None, 'reset')
33 # See the provision control segment for the explanation of why we're
34 # doing this.
35 raise Exception('')
36 else:
Richard Barnette28aa6892016-06-10 13:00:58 -070037 hostname = utils.get_hostname_from_machine(machine)
Alex Miller667b5f22014-02-28 15:33:39 -080038 job.record('END GOOD', None, 'reset',
Richard Barnette28aa6892016-06-10 13:00:58 -070039 '%s reset successfully' % hostname)
Dan Shi07e09af2013-04-12 09:31:29 -070040 finally:
41 if timer:
42 timer.stop()
43
44
45job.parallel_simple(reset, machines)
Alex Miller667b5f22014-02-28 15:33:39 -080046
47# vim: set syntax=python :