|
| 1 | +#!/usr/bin/env python |
| 2 | +# Run tests/ansible/all.yml under Ansible and Ansible-Mitogen |
| 3 | + |
| 4 | +import glob |
| 5 | +import os |
| 6 | +import shutil |
| 7 | +import sys |
| 8 | + |
| 9 | +import ci_lib |
| 10 | +from ci_lib import run |
| 11 | + |
| 12 | + |
| 13 | +TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible') |
| 14 | +IMAGE_PREP_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/image_prep') |
| 15 | +HOSTS_DIR = os.path.join(TESTS_DIR, 'hosts') |
| 16 | +KEY_PATH = os.path.join(TESTS_DIR, '../data/docker/mitogen__has_sudo_pubkey.key') |
| 17 | + |
| 18 | + |
| 19 | +with ci_lib.Fold('unit_tests'): |
| 20 | + os.environ['SKIP_MITOGEN'] = '1' |
| 21 | + ci_lib.run('./run_tests -v') |
| 22 | + |
| 23 | + |
| 24 | +with ci_lib.Fold('job_setup'): |
| 25 | + # Don't set -U as that will upgrade Paramiko to a non-2.6 compatible version. |
| 26 | + run("pip install -q virtualenv ansible==%s", ci_lib.ANSIBLE_VERSION) |
| 27 | + |
| 28 | + os.chmod(KEY_PATH, int('0600', 8)) |
| 29 | + if not ci_lib.exists_in_path('sshpass'): |
| 30 | + run("brew install http://git.io/sshpass.rb") |
| 31 | + |
| 32 | + |
| 33 | +with ci_lib.Fold('machine_prep'): |
| 34 | + ssh_dir = os.path.expanduser('~/.ssh') |
| 35 | + if not os.path.exists(ssh_dir): |
| 36 | + os.makedirs(ssh_dir, int('0700', 8)) |
| 37 | + |
| 38 | + key_path = os.path.expanduser('~/.ssh/id_rsa') |
| 39 | + shutil.copy(KEY_PATH, key_path) |
| 40 | + |
| 41 | + auth_path = os.path.expanduser('~/.ssh/authorized_keys') |
| 42 | + os.system('ssh-keygen -y -f %s >> %s' % (key_path, auth_path)) |
| 43 | + os.chmod(auth_path, int('0600', 8)) |
| 44 | + |
| 45 | + if os.path.expanduser('~mitogen__user1') == '~mitogen__user1': |
| 46 | + os.chdir(IMAGE_PREP_DIR) |
| 47 | + run("ansible-playbook -c local -i localhost, _user_accounts.yml") |
| 48 | + |
| 49 | + |
| 50 | +with ci_lib.Fold('ansible'): |
| 51 | + os.chdir(TESTS_DIR) |
| 52 | + playbook = os.environ.get('PLAYBOOK', 'all.yml') |
| 53 | + run('./run_ansible_playbook.py %s -l target %s', |
| 54 | + playbook, ' '.join(sys.argv[1:])) |
0 commit comments