• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import sys
2
3from autotest_lib.server import utils
4from autotest_lib.server.cros import provision
5
6try:
7    from chromite.lib import metrics
8except ImportError:
9    metrics = utils.metrics_mock
10
11
12DURATION_METRIC = 'chromeos/autotest/autoserv/reset_duration'
13
14
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
19
20def 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.run_special_task_actions(job, target, labels_list,
31                                               provision.Cleanup)
32
33            target.verify()
34            provision.run_special_task_actions(job, target, labels_list,
35                                               provision.Verify)
36    except Exception:
37        logging.exception('Reset failed due to Exception.')
38        job.record('END FAIL', None, 'reset')
39        # See the provision control segment for the explanation of why we're
40        # doing this.
41        raise Exception('')
42    else:
43        hostname = utils.get_hostname_from_machine(machine)
44        job.record('END GOOD', None, 'reset',
45                   '%s reset successfully' % hostname)
46
47
48job.parallel_simple(reset, machines)
49
50# vim: set syntax=python :
51