summaryrefslogtreecommitdiff
path: root/mobmonitor/util/collect_logs.py
diff options
context:
space:
mode:
Diffstat (limited to 'mobmonitor/util/collect_logs.py')
-rw-r--r--mobmonitor/util/collect_logs.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/mobmonitor/util/collect_logs.py b/mobmonitor/util/collect_logs.py
new file mode 100644
index 000000000..503fbdf69
--- /dev/null
+++ b/mobmonitor/util/collect_logs.py
@@ -0,0 +1,40 @@
+# Copyright 2015 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Simple log collection script for Mob* Monitor"""
+
+from __future__ import print_function
+
+import os
+import tempfile
+import shutil
+
+from chromite.lib import cros_build_lib
+
+
+TMPDIR_PREFIX = 'moblab_logs_'
+LOG_DIRS = {
+ 'system_logs': '/var/log',
+ 'autotest_logs': '/usr/local/autotest/logs'
+}
+
+
+def collect_logs():
+ tempdir = tempfile.mkdtemp(prefix=TMPDIR_PREFIX)
+ os.chmod(tempdir, 0o777)
+
+ for name, path in LOG_DIRS.iteritems():
+ if not os.path.exists(path):
+ continue
+ shutil.copytree(path, os.path.join(tempdir, name))
+
+ cmd = ['mobmoncli', 'GetStatus']
+ cros_build_lib.RunCommand(
+ cmd,
+ log_stdout_to_file=os.path.join(tempdir, 'mobmonitor_getstatus')
+ )
+
+ tarball = '%s.tgz' % tempdir
+ cros_build_lib.CreateTarball(tarball, tempdir)
+ return tarball