summaryrefslogtreecommitdiff
path: root/mobmonitor/util/collect_logs.py
blob: 503fbdf69d717ff64ac8d0b7d72fa27185c86e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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