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