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 26 try: 27 # We don't need to collect logs or crash info if we're a 28 # testbed since they're not applicable (yet). 29 if (isinstance(target, hosts.CrosHost) 30 and target.is_up_fast() 31 and target.is_up() 32 and target.is_file_system_writable()): 33 # Collect logs before the repair, as it might destroy all 34 # useful logs. 35 local_log_dir = os.path.join(job.resultdir, hostname, 36 'before_repair') 37 target.collect_logs('/var/log', 38 local_log_dir, 39 ignore_errors=True) 40 # Collect crash info. 41 crashcollect.get_crashinfo(target, None) 42 except Exception: 43 logging.exception('Crash collection failed; crashes may be ' 44 'lost. Sorry about that.') 45 46 target.repair() 47 logging.debug('Repair with labels list %s', labels_list) 48 49 try: 50 target.labels.update_labels(target, 51 task_name='repair', 52 keep_pool=True) 53 except Exception: 54 logging.exception('Exception while updating labels.') 55 except Exception: 56 logging.exception('Repair failed due to Exception.') 57 job.record('END FAIL', None, 'repair') 58 # See the provision control segment for the explanation of why we're 59 # doing this. 60 raise Exception('') 61 else: 62 job.record('END GOOD', None, 'repair', 63 '%s repaired successfully' % hostname) 64 65 66job.parallel_simple(repair, machines) 67 68# vim: set syntax=python : 69