blob: 5a855db3ad4a7f231efd67a51ad047e55e8aff78 [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Tests all master.cfgs to make sure they load properly."""
import collections
import optparse
import os
import subprocess
import sys
import time
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(BASE_DIR, 'scripts'))
import common.env
from common import chromium_utils
from common import master_cfg_utils
# Masters which do not currently load from the default configuration. These need
# to be fixed and removed from the list!
BLACKLIST = set(['chromium.swarm',
Cmd = collections.namedtuple('Cmd', ['name', 'path', 'env'])
def GetMasterCmds(masters, blacklist, pythonpaths):
assert blacklist <= set(m for m, _ in masters)
cmds = []
for name, path in masters:
if name in blacklist:
master_pythonpath = common.env.PythonPath.FromPaths(*(pythonpaths or []))
master_pythonpath += common.env.GetInfraPythonPath(master_dir=path)
env = os.environ.copy()
env_pythonpath = env.get('PYTHONPATH')
if env_pythonpath:
master_pythonpath += common.env.PythonPath.FromPathStr(env_pythonpath)
env['PYTHONPATH'] = master_pythonpath.pathstr
cmds.append(Cmd(name, path, env))
return cmds
def main(argv):
start_time = time.time()
parser = optparse.OptionParser()
parser.add_option('-v', '--verbose', action='store_true')
options, args = parser.parse_args(argv[1:])
if args:
parser.error('Unknown arguments: %s' % args)
num_skipped = len(BLACKLIST)
masters_list = GetMasterCmds(
build_internal = os.path.join(BASE_DIR, '..', 'build_internal')
if os.path.exists(build_internal):
internal_test_data = chromium_utils.ParsePythonCfg(
os.path.join(build_internal, 'tests', ''),
internal_cfg = internal_test_data['masters_cfg_test']
num_skipped += len(internal_cfg['blacklist'])
pythonpaths=[os.path.join(build_internal, p)
for p in internal_cfg['paths']]))
with master_cfg_utils.TemporaryMasterPasswords():
processes = [subprocess.Popen([
sys.executable, os.path.join(BASE_DIR, 'scripts', 'slave', ''),, '--test-config'], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, env=cmd.env) for cmd in masters_list]
results = [(proc.communicate()[0], proc.returncode) for proc in processes]
def GetCommandStr(cmd, cmd_output):
out = [cmd.path]
out.extend('> ' + line for line in cmd_output.splitlines())
return '\n'.join(out + [''])
if options.verbose:
for cmd, (out, code) in zip(masters_list, results):
# Failures will be printed below
if code == 0 and out:
print GetCommandStr(cmd, out)
failures = [(cmd, out) for cmd, (out, r) in zip(masters_list, results) if r]
if failures:
print '\nFAILURE The following master.cfg files did not load:\n'
for cmd, out in failures:
print GetCommandStr(cmd, out)
test_time = round(time.time() - start_time, 1)
print 'Parsed %d masters successfully, %d failed, %d skipped in %gs.' % (
len(masters_list), len(failures), num_skipped, test_time)
return bool(failures)
if __name__ == '__main__':