2019-07-30 21:11:04 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Run tests/ansible/all.yml under Ansible and Ansible-Mitogen
|
|
|
|
|
|
|
|
import glob
|
|
|
|
import os
|
2019-07-30 23:13:50 +00:00
|
|
|
import shutil
|
2019-07-30 21:11:04 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import ci_lib
|
|
|
|
from ci_lib import run
|
|
|
|
|
|
|
|
|
|
|
|
TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible')
|
|
|
|
IMAGE_PREP_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/image_prep')
|
|
|
|
HOSTS_DIR = os.path.join(TESTS_DIR, 'hosts')
|
2019-07-30 23:13:50 +00:00
|
|
|
KEY_PATH = os.path.join(TESTS_DIR, '../data/docker/mitogen__has_sudo_pubkey.key')
|
2019-07-30 21:11:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
with ci_lib.Fold('unit_tests'):
|
|
|
|
os.environ['SKIP_MITOGEN'] = '1'
|
|
|
|
ci_lib.run('./run_tests -v')
|
|
|
|
|
|
|
|
|
|
|
|
with ci_lib.Fold('job_setup'):
|
|
|
|
# Don't set -U as that will upgrade Paramiko to a non-2.6 compatible version.
|
2019-07-31 00:03:23 +00:00
|
|
|
run("pip install -q virtualenv ansible==%s", ci_lib.ANSIBLE_VERSION)
|
2019-07-30 21:11:04 +00:00
|
|
|
|
2019-07-30 23:13:50 +00:00
|
|
|
os.chmod(KEY_PATH, int('0600', 8))
|
2019-07-30 21:11:04 +00:00
|
|
|
if not ci_lib.exists_in_path('sshpass'):
|
2019-07-30 21:52:26 +00:00
|
|
|
run("brew install http://git.io/sshpass.rb")
|
2019-07-30 21:11:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
with ci_lib.Fold('machine_prep'):
|
2019-07-30 23:22:59 +00:00
|
|
|
ssh_dir = os.path.expanduser('~/.ssh')
|
|
|
|
if not os.path.exists(ssh_dir):
|
|
|
|
os.makedirs(ssh_dir, int('0700', 8))
|
|
|
|
|
2019-07-30 21:52:26 +00:00
|
|
|
key_path = os.path.expanduser('~/.ssh/id_rsa')
|
2019-07-30 23:13:50 +00:00
|
|
|
shutil.copy(KEY_PATH, key_path)
|
2019-07-30 21:52:26 +00:00
|
|
|
|
|
|
|
auth_path = os.path.expanduser('~/.ssh/authorized_keys')
|
2019-07-30 23:13:50 +00:00
|
|
|
os.system('ssh-keygen -y -f %s >> %s' % (key_path, auth_path))
|
2019-07-30 21:52:26 +00:00
|
|
|
os.chmod(auth_path, int('0600', 8))
|
|
|
|
|
|
|
|
if os.path.expanduser('~mitogen__user1') == '~mitogen__user1':
|
2019-07-30 21:11:04 +00:00
|
|
|
os.chdir(IMAGE_PREP_DIR)
|
2019-07-30 23:50:22 +00:00
|
|
|
run("ansible-playbook -c local -i localhost, _user_accounts.yml")
|
2019-07-30 21:11:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
with ci_lib.Fold('ansible'):
|
|
|
|
os.chdir(TESTS_DIR)
|
|
|
|
playbook = os.environ.get('PLAYBOOK', 'all.yml')
|
|
|
|
run('./run_ansible_playbook.py %s -l target %s',
|
2019-07-30 21:52:26 +00:00
|
|
|
playbook, ' '.join(sys.argv[1:]))
|