1# Copyright (c) 2008 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import logging 6import os 7 8from autotest_lib.server import crashcollect 9from autotest_lib.server import utils 10from autotest_lib.server.cros import provision 11 12 13# A string of the form 'label1,label2:value,label3'. 14job_labels = locals().get('job_labels') or ','.join(args) 15labels_list = [l.strip() for l in job_labels.split(',') if l] 16 17 18def repair(machine): 19 try: 20 hostname = utils.get_hostname_from_machine(machine) 21 job.record('START', None, 'repair') 22 target = hosts.create_target_machine(machine, 23 try_lab_servo=True, 24 try_servo_repair=True) 25 try: 26 # We don't need to collect logs or crash info if we're a 27 # testbed since they're not applicable (yet). 28 if isinstance(target, hosts.CrosHost): 29 # Collect logs before the repair, as it might destroy all 30 # useful logs. 31 local_log_dir = os.path.join(job.resultdir, hostname, 32 'before_repair') 33 target.collect_logs('/var/log', 34 local_log_dir, 35 ignore_errors=True) 36 # Collect crash info. 37 crashcollect.get_crashinfo(target, None) 38 except Exception: 39 logging.exception('Crash collection failed; crashes may be ' 40 'lost. Sorry about that.') 41 42 target.repair() 43 logging.debug('Repair with labels list %s', labels_list) 44 45 try: 46 target.labels.update_labels(target, 47 task_name='repair', 48 keep_pool=True) 49 except Exception: 50 logging.exception('Exception while updating labels.') 51 except Exception: 52 logging.exception('Repair failed due to Exception.') 53 job.record('END FAIL', None, 'repair') 54 # See the provision control segment for the explanation of why we're 55 # doing this. 56 raise Exception('') 57 else: 58 job.record('END GOOD', None, 'repair', 59 '%s repaired successfully' % hostname) 60 61 62job.parallel_simple(repair, machines) 63 64# vim: set syntax=python : 65