1import logging 2import os 3 4from autotest_lib.client.common_lib import error 5from autotest_lib.client.common_lib.cros.graphite import autotest_stats 6from autotest_lib.server import utils 7from autotest_lib.server.cros import provision 8 9 10# A string of the form 'label1,label2:value,label3'. 11job_labels = locals().get('job_labels') or ','.join(args) 12labels_list = [l.strip() for l in job_labels.split(',') if l] 13 14 15def cleanup(machine): 16 timer = None 17 try: 18 hostname = utils.get_hostname_from_machine(machine) 19 job.record('START', None, 'cleanup') 20 host = hosts.create_host(machine, initialize=False, auto_monitor=False, 21 try_lab_servo=True) 22 timer = autotest_stats.Timer('cleanup_time') 23 timer.start() 24 25 # Try to save /var/log files. If the dut is not sshable, try to restart 26 # with servo. This is a temp fix to collect log for test failed with dut 27 # not returning from reboot. 28 # TODO(dshi): This temp fix should be removed after crash collect work 29 # is completed, crbug.com/336985 30 try: 31 host.ssh_ping() 32 except error.AutoservSshPingHostError: 33 # Try to restart dut with servo. 34 host._servo_repair_power() 35 local_log_dir = os.path.join(job.resultdir, hostname) 36 host.collect_logs('/var/log', local_log_dir, ignore_errors=True) 37 38 host.cleanup() 39 provision.run_special_task_actions(job, host, labels_list, 40 provision.Cleanup) 41 except Exception as e: 42 logging.exception(e) 43 job.record('END FAIL', None, 'cleanup') 44 # See the provision control segment for the explanation of why we're 45 # doing this. 46 raise Exception('') 47 else: 48 job.record('END GOOD', None, 'cleanup', 49 '%s cleaned successfully' % machine) 50 finally: 51 if timer: 52 timer.stop() 53 54 55 56job.parallel_simple(cleanup, machines, log=False) 57 58# vim: set syntax=python : 59