blob: 9e57a6080e8d72d0826bd625aeeef88dfcfe8be7 [file] [log] [blame]
import logging
import os
from autotest_lib.client.common_lib import error
from autotest_lib.server import utils
from autotest_lib.server.cros import provision
from chromite.lib import metrics
except ImportError:
metrics = utils.metrics_mock
DURATION_METRIC = 'chromeos/autotest/autoserv/cleanup_duration'
# A string of the form 'label1,label2:value,label3'.
job_labels = locals().get('job_labels') or ','.join(args)
labels_list = [l.strip() for l in job_labels.split(',') if l]
def cleanup(machine):
hostname = utils.get_hostname_from_machine(machine)
job.record('START', None, 'cleanup')
host = hosts.create_host(machine, try_lab_servo=True)
with metrics.SecondsTimer(DURATION_METRIC,
fields={'dut_host_name': hostname}):
# Try to save /var/log files. If the dut is not sshable, try to
# restart with servo, to collect logs for test failed with dut
# not returning from reboot.
# TODO: This is a temp fix and should no longer be necessary
# Depended on, fixed in 2015
except error.AutoservSshPingHostError:
# Try to restart dut with servo.
local_log_dir = os.path.join(job.resultdir, hostname)
host.collect_logs('/var/log', local_log_dir, ignore_errors=True)
provision.Cleanup.run_task_actions(job, host, labels_list)
except Exception:
logging.exception('Cleanup failed due to Exception.')
job.record('END FAIL', None, 'cleanup')
# See the provision control segment for the explanation of why we're
# doing this.
raise Exception('')
job.record('END GOOD', None, 'cleanup',
'%s cleaned successfully' % hostname)
job.parallel_simple(cleanup, machines, log=False)
# vim: set syntax=python :