tests: rationalize matrix and rewrite ansible_tests
Now all distros run in parallel.pull/350/head
parent
da391f0542
commit
06ae59702c
@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python
|
||||
# Run tests/ansible/all.yml under Ansible and Ansible-Mitogen
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import ci_lib
|
||||
from ci_lib import run
|
||||
|
||||
|
||||
BASE_PORT = 2201
|
||||
TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible')
|
||||
HOSTS_DIR = os.path.join(ci_lib.TMP, 'hosts')
|
||||
|
||||
|
||||
with ci_lib.Fold('docker_setup'):
|
||||
for i, distro in enumerate(ci_lib.DISTROS):
|
||||
try:
|
||||
run("docker rm -f target-%s", distro)
|
||||
except: pass
|
||||
|
||||
run("""
|
||||
docker run
|
||||
--rm
|
||||
--detach
|
||||
--publish 0.0.0.0:%s:22/tcp
|
||||
--name=target-%s
|
||||
mitogen/%s-test
|
||||
""", BASE_PORT + i, distro, distro,)
|
||||
|
||||
|
||||
with ci_lib.Fold('job_setup'):
|
||||
os.chdir(TESTS_DIR)
|
||||
os.chmod('../data/docker/mitogen__has_sudo_pubkey.key', int('0600', 7))
|
||||
|
||||
# Don't set -U as that will upgrade Paramiko to a non-2.6 compatible version.
|
||||
run("pip install -q ansible==%s", ci_lib.ANSIBLE_VERSION)
|
||||
|
||||
run("mkdir %s", HOSTS_DIR)
|
||||
run("ln -s %s/common-hosts %s", TESTS_DIR, HOSTS_DIR)
|
||||
|
||||
with open(os.path.join(HOSTS_DIR, 'target'), 'w') as fp:
|
||||
fp.write('[test-targets]\n')
|
||||
for i, distro in enumerate(ci_lib.DISTROS):
|
||||
fp.write("target-%s "
|
||||
"ansible_host=%s "
|
||||
"ansible_port=%s "
|
||||
"ansible_user=mitogen__has_sudo_nopw "
|
||||
"ansible_password=has_sudo_nopw_password"
|
||||
"\n" % (
|
||||
distro,
|
||||
ci_lib.DOCKER_HOSTNAME,
|
||||
BASE_PORT + i,
|
||||
))
|
||||
|
||||
# Build the binaries.
|
||||
run("make -C %s", TESTS_DIR)
|
||||
if not ci_lib.exists_in_path('sshpass'):
|
||||
run("sudo apt-get update")
|
||||
run("sudo apt-get install -y sshpass")
|
||||
|
||||
|
||||
with ci_lib.Fold('ansible'):
|
||||
run('/usr/bin/time ./run_ansible_playbook.sh all.yml -i "%s" %s',
|
||||
HOSTS_DIR, ' '.join(sys.argv[1:]))
|
@ -1,66 +0,0 @@
|
||||
#!/bin/bash -ex
|
||||
# Run tests/ansible/all.yml under Ansible and Ansible-Mitogen
|
||||
|
||||
TRAVIS_BUILD_DIR="${TRAVIS_BUILD_DIR:-`pwd`}"
|
||||
TMPDIR="/tmp/ansible-tests-$$"
|
||||
ANSIBLE_VERSION="${VER:-2.6.1}"
|
||||
export ANSIBLE_STRATEGY="${STRATEGY:-mitogen_linear}"
|
||||
DISTRO="${DISTRO:-debian}"
|
||||
|
||||
export PYTHONPATH="${PYTHONPATH}:${TRAVIS_BUILD_DIR}"
|
||||
|
||||
# SSH passes these through to the container when run interactively, causing
|
||||
# stdout to get messed up with libc warnings.
|
||||
unset LANG LC_ALL
|
||||
|
||||
function on_exit()
|
||||
{
|
||||
rm -rf "$TMPDIR"
|
||||
docker kill target || true
|
||||
}
|
||||
|
||||
trap on_exit EXIT
|
||||
mkdir "$TMPDIR"
|
||||
|
||||
|
||||
echo travis_fold:start:docker_setup
|
||||
DOCKER_HOSTNAME="$(python ${TRAVIS_BUILD_DIR}/tests/show_docker_hostname.py)"
|
||||
|
||||
docker run \
|
||||
--rm \
|
||||
--detach \
|
||||
--publish 0.0.0.0:2201:22/tcp \
|
||||
--name=target \
|
||||
mitogen/${DISTRO}-test
|
||||
echo travis_fold:end:docker_setup
|
||||
|
||||
|
||||
echo travis_fold:start:job_setup
|
||||
pip install ansible=="${ANSIBLE_VERSION}"
|
||||
cd ${TRAVIS_BUILD_DIR}/tests/ansible
|
||||
|
||||
chmod go= ${TRAVIS_BUILD_DIR}/tests/data/docker/mitogen__has_sudo_pubkey.key
|
||||
mkdir ${TMPDIR}/hosts
|
||||
ln -s ${TRAVIS_BUILD_DIR}/tests/ansible/common-hosts ${TMPDIR}/hosts/common-hosts
|
||||
echo '[test-targets]' > ${TMPDIR}/hosts/target
|
||||
echo \
|
||||
target \
|
||||
ansible_host=$DOCKER_HOSTNAME \
|
||||
ansible_port=2201 \
|
||||
ansible_user=mitogen__has_sudo_nopw \
|
||||
ansible_password=has_sudo_nopw_password \
|
||||
>> ${TMPDIR}/hosts/target
|
||||
|
||||
# Build the binaries.
|
||||
make -C ${TRAVIS_BUILD_DIR}/tests/ansible
|
||||
|
||||
[ ! "$(type -p sshpass)" ] && sudo apt install -y sshpass
|
||||
|
||||
echo travis_fold:end:job_setup
|
||||
|
||||
|
||||
echo travis_fold:start:ansible
|
||||
/usr/bin/time ./run_ansible_playbook.sh \
|
||||
all.yml \
|
||||
-i "${TMPDIR}/hosts" "$@"
|
||||
echo travis_fold:end:ansible
|
@ -0,0 +1,100 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import atexit
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import shlex
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
|
||||
#
|
||||
# check_output() monkeypatch cutpasted from testlib.py
|
||||
#
|
||||
|
||||
def subprocess__check_output(*popenargs, **kwargs):
|
||||
# Missing from 2.6.
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, _ = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
raise subprocess.CalledProcessError(retcode, cmd)
|
||||
return output
|
||||
|
||||
if not hasattr(subprocess, 'check_output'):
|
||||
subprocess.check_output = subprocess__check_output
|
||||
|
||||
# -----------------
|
||||
|
||||
def _argv(s, *args):
|
||||
if args:
|
||||
s %= args
|
||||
return shlex.split(s)
|
||||
|
||||
|
||||
def run(s, *args, **kwargs):
|
||||
argv = _argv(s, *args)
|
||||
print('Running: %s' % (argv,))
|
||||
return subprocess.check_call(argv, **kwargs)
|
||||
|
||||
|
||||
def get_output(s, *args, **kwargs):
|
||||
argv = _argv(s, *args)
|
||||
print('Running: %s' % (argv,))
|
||||
return subprocess.check_output(argv, **kwargs)
|
||||
|
||||
|
||||
def exists_in_path(progname):
|
||||
return any(os.path.exists(os.path.join(dirname, progname))
|
||||
for dirname in os.environ['PATH'].split(os.pathsep))
|
||||
|
||||
|
||||
class TempDir(object):
|
||||
def __init__(self):
|
||||
self.path = tempfile.mkdtemp(prefix='mitogen_ci_lib')
|
||||
atexit.register(self.destroy)
|
||||
|
||||
def destroy(self, rmtree=shutil.rmtree):
|
||||
rmtree(self.path)
|
||||
|
||||
|
||||
class Fold(object):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def __enter__(self):
|
||||
print('travis_fold:start:%s' % (self.name))
|
||||
|
||||
def __exit__(self, _1, _2, _3):
|
||||
print('')
|
||||
print('travis_fold:end:%s' % (self.name))
|
||||
|
||||
|
||||
os.environ.setdefault('ANSIBLE_STRATEGY',
|
||||
os.environ.get('STRATEGY', 'mitogen_linear'))
|
||||
ANSIBLE_VERSION = os.environ.get('VER', '2.6.2')
|
||||
GIT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
DISTROS = os.environ.get('DISTROS', 'debian centos6 centos7').split()
|
||||
TMP = TempDir().path
|
||||
|
||||
os.environ['PYTHONDONTWRITEBYTECODE'] = 'x'
|
||||
os.environ['PYTHONPATH'] = '%s:%s' % (
|
||||
os.environ.get('PYTHONPATH', ''),
|
||||
GIT_ROOT
|
||||
)
|
||||
|
||||
DOCKER_HOSTNAME = subprocess.check_output([
|
||||
sys.executable,
|
||||
os.path.join(GIT_ROOT, 'tests/show_docker_hostname.py'),
|
||||
]).decode().strip()
|
||||
|
||||
# SSH passes these through to the container when run interactively, causing
|
||||
# stdout to get messed up with libc warnings.
|
||||
os.environ.pop('LANG', None)
|
||||
os.environ.pop('LC_ALL', None)
|
Loading…
Reference in New Issue