1 import logging 2 import os 3 4 from autotest_lib.server import crashcollect 5 from autotest_lib.server import utils 6 from autotest_lib.server.cros import provision 7 8 9 # A string of the form 'label1,label2:value,label3'. 10 job_labels = locals().get('job_labels') or ','.join(args) 11 labels_list = [l.strip() for l in job_labels.split(',') if l] 12 13 14 def 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, initialize=False, 19 auto_monitor=False, 20 try_lab_servo=True) 21 # We don't need to collect logs or crash info if we're an ADBHost or 22 # testbed since they're not applicable (yet). 23 if isinstance(target, hosts.CrosHost): 24 # Collect logs before the repair, as it might destroy all 25 # useful logs. 26 local_log_dir = os.path.join(job.resultdir, hostname, 27 'before_repair') 28 target.collect_logs('/var/log', local_log_dir, ignore_errors=True) 29 # Collect crash info. 30 crashcollect.get_crashinfo(target, None) 31 32 target.repair() 33 logging.debug('Repair with labels list %s', labels_list) 34 provision.run_special_task_actions(job, target, labels_list, 35 provision.Repair) 36 except Exception as e: 37 logging.exception(e) 38 job.record('END FAIL', None, 'repair') 39 # See the provision control segment for the explanation of why we're 40 # doing this. 41 raise Exception('') 42 else: 43 job.record('END GOOD', None, 'repair', 44 '%s repaired successfully' % machine) 45 46 47 job.parallel_simple(repair, machines) 48 49 # vim: set syntax=python : 50