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