]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
collect logs when the test fails
authorVasu Kulkarni <vasu@redhat.com>
Thu, 22 Jun 2017 22:36:11 +0000 (15:36 -0700)
committerVasu Kulkarni <vasu@redhat.com>
Thu, 22 Jun 2017 22:36:11 +0000 (15:36 -0700)
Signed-off-by: Vasu Kulkarni <vasu@redhat.com>
teuthology/task/ceph_ansible.py

index 272ebce028de8ef669114065596cd34c9816eedc..084e436ccdd3e4d3bfa2438753d058a33b9e571c 100644 (file)
@@ -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: