From: Vasu Kulkarni Date: Thu, 22 Jun 2017 22:36:11 +0000 (-0700) Subject: collect logs when the test fails X-Git-Tag: 1.1.0~406^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=54b6a0da2937cc1863ec4fb241693fec726b7bc6;p=teuthology.git collect logs when the test fails Signed-off-by: Vasu Kulkarni --- diff --git a/teuthology/task/ceph_ansible.py b/teuthology/task/ceph_ansible.py index 272ebce028..084e436ccd 100644 --- a/teuthology/task/ceph_ansible.py +++ b/teuthology/task/ceph_ansible.py @@ -20,7 +20,7 @@ class CephAnsible(Task): name = 'ceph_ansible' # TODO: Eventually, we should drop _default_playbook in favor of site.yml.sample from ceph-ansible.git _default_playbook = [ - # Run gather facts at the top as required by mgr-role + # Run gather facts at the top as required by mgr-role dict( hosts='all', become=True, @@ -224,6 +224,8 @@ class CephAnsible(Task): os.remove(self.inventory) os.remove(self.playbook_file) os.remove(self.extra_vars_file) + # collect logs + self.collect_logs() # run purge-cluster that teardowns the cluster args = [ 'ANSIBLE_STDOUT_CALLBACK=debug', @@ -253,6 +255,43 @@ class CephAnsible(Task): ] ) + def collect_logs(self): + ctx = self.ctx + if ctx.archive is not None and \ + not (ctx.config.get('archive-on-error') and ctx.summary['success']): + # collect logs + log.info('Compressing logs...') + run.wait( + ctx.cluster.run( + args=[ + 'sudo', + 'find', + '/var/log/ceph', + '-name', + '*.log', + '-print0', + run.Raw('|'), + 'sudo', + 'xargs', + '-0', + '--no-run-if-empty', + '--', + 'gzip', + '--', + ], + check_status=False, + ), + ) + + log.info('Archiving logs...') + path = os.path.join(ctx.archive, 'remote') + os.makedirs(path) + for remote in ctx.cluster.remotes.iterkeys(): + sub = os.path.join(path, remote.shortname) + os.makedirs(sub) + misc.pull_directory(remote, '/var/log/ceph', + os.path.join(sub, 'log')) + def wait_for_ceph_health(self): with contextutil.safe_while(sleep=15, tries=6, action='check health') as proceed: