• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import logging
2import os
3
4from autotest_lib.server import crashcollect
5from autotest_lib.server import utils
6from autotest_lib.server.cros import provision
7
8
9# A string of the form 'label1,label2:value,label3'.
10job_labels = locals().get('job_labels') or ','.join(args)
11labels_list = [l.strip() for l in job_labels.split(',') if l]
12
13
14def repair(machine):
15    try:
16        hostname = utils.get_hostname_from_machine(machine)
17        job.record('START', None, 'repair')
18        target = hosts.create_target_machine(machine,
19                                             try_lab_servo=True,
20                                             try_servo_repair=True)
21        try:
22            # We don't need to collect logs or crash info if we're an
23            # ADBHost or testbed since they're not applicable (yet).
24            if isinstance(target, hosts.CrosHost):
25                # Collect logs before the repair, as it might destroy all
26                # useful logs.
27                local_log_dir = os.path.join(job.resultdir, hostname,
28                                             'before_repair')
29                target.collect_logs('/var/log',
30                                    local_log_dir,
31                                    ignore_errors=True)
32                # Collect crash info.
33                crashcollect.get_crashinfo(target, None)
34        except Exception:
35            logging.exception('Crash collection failed; crashes may be '
36                              'lost.  Sorry about that.')
37
38        target.repair()
39        logging.debug('Repair with labels list %s', labels_list)
40        provision.run_special_task_actions(job, target, labels_list,
41                                           provision.Repair)
42    except Exception:
43        logging.exception('Repair failed due to Exception.')
44        job.record('END FAIL', None, 'repair')
45        # See the provision control segment for the explanation of why we're
46        # doing this.
47        raise Exception('')
48    else:
49        job.record('END GOOD', None, 'repair',
50                   '%s repaired successfully' % hostname)
51
52
53job.parallel_simple(repair, machines)
54
55# vim: set syntax=python :
56