Home | History | Annotate | Download | only in control_segments
      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,
     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 
     41         try:
     42             target.labels.update_labels(target, keep_pool=True)
     43         except Exception:
     44             logging.exception('Exception while updating labels.')
     45     except Exception:
     46         logging.exception('Repair failed due to Exception.')
     47         job.record('END FAIL', None, 'repair')
     48         # See the provision control segment for the explanation of why we're
     49         # doing this.
     50         raise Exception('')
     51     else:
     52         job.record('END GOOD', None, 'repair',
     53                    '%s repaired successfully' % hostname)
     54 
     55 
     56 job.parallel_simple(repair, machines)
     57 
     58 # vim: set syntax=python :
     59