| Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 1 | import sys | 
 | 2 |  | 
| Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 3 | from autotest_lib.client.common_lib.cros.graphite import autotest_stats | 
| Richard Barnette | 28aa689 | 2016-06-10 13:00:58 -0700 | [diff] [blame] | 4 | from autotest_lib.server import utils | 
| Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 5 | from autotest_lib.server.cros import provision | 
 | 6 |  | 
 | 7 |  | 
 | 8 | # A string of the form 'label1,label2:value,label3'. | 
 | 9 | job_labels = locals().get('job_labels') or ','.join(args) | 
 | 10 | labels_list = [l.strip() for l in job_labels.split(',') if l] | 
 | 11 |  | 
| Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 12 |  | 
 | 13 | def reset(machine): | 
| Simran Basi | 1bf60eb | 2015-12-01 16:39:29 -0800 | [diff] [blame] | 14 |     print 'Starting to reset host %s' % machine | 
| Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 15 |     timer = None | 
 | 16 |     try: | 
| Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 17 |         job.record('START', None, 'reset') | 
| Richard Barnette | 18dc888 | 2016-08-11 17:08:48 -0700 | [diff] [blame^] | 18 |         target = hosts.create_target_machine(machine) | 
| Gabe Black | 1e1c41b | 2015-02-04 23:55:15 -0800 | [diff] [blame] | 19 |         timer = autotest_stats.Timer('reset_time') | 
| Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 20 |         timer.start() | 
| Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 21 |  | 
| Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 22 |         # Assume cleanup always runs first. | 
| Dan Shi | d7f1242 | 2016-01-04 11:51:32 -0800 | [diff] [blame] | 23 |         target.cleanup() | 
 | 24 |         provision.run_special_task_actions(job, target, labels_list, | 
| Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 25 |                                            provision.Cleanup) | 
 | 26 |  | 
| Dan Shi | d7f1242 | 2016-01-04 11:51:32 -0800 | [diff] [blame] | 27 |         target.verify() | 
 | 28 |         provision.run_special_task_actions(job, target, labels_list, | 
| Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 29 |                                            provision.Verify) | 
| Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 30 |     except Exception as e: | 
| Alex Miller | 789d6f1 | 2014-05-02 13:11:15 -0700 | [diff] [blame] | 31 |         logging.exception(e) | 
| Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 32 |         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 Barnette | 28aa689 | 2016-06-10 13:00:58 -0700 | [diff] [blame] | 37 |         hostname = utils.get_hostname_from_machine(machine) | 
| Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 38 |         job.record('END GOOD', None, 'reset', | 
| Richard Barnette | 28aa689 | 2016-06-10 13:00:58 -0700 | [diff] [blame] | 39 |                    '%s reset successfully' % hostname) | 
| Dan Shi | 07e09af | 2013-04-12 09:31:29 -0700 | [diff] [blame] | 40 |     finally: | 
 | 41 |         if timer: | 
 | 42 |             timer.stop() | 
 | 43 |  | 
 | 44 |  | 
 | 45 | job.parallel_simple(reset, machines) | 
| Alex Miller | 667b5f2 | 2014-02-28 15:33:39 -0800 | [diff] [blame] | 46 |  | 
 | 47 | # vim: set syntax=python : |