Home | History | Annotate | Download | only in control_segments
      1 import sys
      2 
      3 from autotest_lib.server import utils
      4 from autotest_lib.server.cros import provision
      5 
      6 try:
      7     from chromite.lib import metrics
      8 except ImportError:
      9     metrics = utils.metrics_mock
     10 
     11 
     12 DURATION_METRIC = 'chromeos/autotest/autoserv/reset_duration'
     13 
     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 
     19 
     20 def reset(machine):
     21     print 'Starting to reset host %s' % machine
     22     try:
     23         job.record('START', None, 'reset')
     24         target = hosts.create_target_machine(machine)
     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()
     30             provision.Cleanup.run_task_actions(job, target, labels_list)
     31 
     32             target.verify()
     33             provision.Verify.run_task_actions(job, target, labels_list)
     34     except Exception:
     35         logging.exception('Reset failed due to Exception.')
     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:
     41         hostname = utils.get_hostname_from_machine(machine)
     42         job.record('END GOOD', None, 'reset',
     43                    '%s reset successfully' % hostname)
     44 
     45 
     46 job.parallel_simple(reset, machines)
     47 
     48 # vim: set syntax=python :
     49