|
|
|
|
@ -12,9 +12,8 @@ import jinja2
|
|
|
|
|
import ci_lib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEMPLATES_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible/templates')
|
|
|
|
|
TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible')
|
|
|
|
|
HOSTS_DIR = os.path.join(ci_lib.TMP, 'hosts')
|
|
|
|
|
TMP = ci_lib.TempDir(prefix='mitogen_ci_ansible')
|
|
|
|
|
TMP_HOSTS_DIR = os.path.join(TMP.path, 'hosts')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pause_if_interactive():
|
|
|
|
|
@ -40,13 +39,13 @@ with ci_lib.Fold('docker_setup'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with ci_lib.Fold('job_setup'):
|
|
|
|
|
os.chdir(TESTS_DIR)
|
|
|
|
|
os.chmod('../data/docker/mitogen__has_sudo_pubkey.key', int('0600', 8))
|
|
|
|
|
os.chmod(ci_lib.TESTS_SSH_PRIVATE_KEY_FILE, int('0600', 8))
|
|
|
|
|
os.chdir(ci_lib.ANSIBLE_TESTS_DIR)
|
|
|
|
|
|
|
|
|
|
ci_lib.run("mkdir %s", HOSTS_DIR)
|
|
|
|
|
for path in glob.glob(TESTS_DIR + '/hosts/*'):
|
|
|
|
|
os.mkdir(TMP_HOSTS_DIR)
|
|
|
|
|
for path in glob.glob(os.path.join(ci_lib.ANSIBLE_TESTS_HOSTS_DIR, '*')):
|
|
|
|
|
if not path.endswith('default.hosts'):
|
|
|
|
|
ci_lib.run("ln -s %s %s", path, HOSTS_DIR)
|
|
|
|
|
os.symlink(path, os.path.join(TMP_HOSTS_DIR, os.path.basename(path)))
|
|
|
|
|
|
|
|
|
|
distros = collections.defaultdict(list)
|
|
|
|
|
families = collections.defaultdict(list)
|
|
|
|
|
@ -55,12 +54,14 @@ with ci_lib.Fold('job_setup'):
|
|
|
|
|
families[container['family']].append(container['name'])
|
|
|
|
|
|
|
|
|
|
jinja_env = jinja2.Environment(
|
|
|
|
|
loader=jinja2.FileSystemLoader(searchpath=TEMPLATES_DIR),
|
|
|
|
|
loader=jinja2.FileSystemLoader(
|
|
|
|
|
searchpath=ci_lib.ANSIBLE_TESTS_TEMPLATES_DIR,
|
|
|
|
|
),
|
|
|
|
|
lstrip_blocks=True, # Remove spaces and tabs from before a block
|
|
|
|
|
trim_blocks=True, # Remove first newline after a block
|
|
|
|
|
)
|
|
|
|
|
inventory_template = jinja_env.get_template('test-targets.j2')
|
|
|
|
|
inventory_path = os.path.join(HOSTS_DIR, 'target')
|
|
|
|
|
inventory_path = os.path.join(TMP_HOSTS_DIR, 'test-targets.ini')
|
|
|
|
|
|
|
|
|
|
with open(inventory_path, 'w') as fp:
|
|
|
|
|
fp.write(inventory_template.render(
|
|
|
|
|
@ -71,16 +72,12 @@ with ci_lib.Fold('job_setup'):
|
|
|
|
|
|
|
|
|
|
ci_lib.dump_file(inventory_path)
|
|
|
|
|
|
|
|
|
|
if not ci_lib.exists_in_path('sshpass'):
|
|
|
|
|
ci_lib.run("sudo apt-get update")
|
|
|
|
|
ci_lib.run("sudo apt-get install -y sshpass")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with ci_lib.Fold('ansible'):
|
|
|
|
|
playbook = os.environ.get('PLAYBOOK', 'all.yml')
|
|
|
|
|
try:
|
|
|
|
|
ci_lib.run('./run_ansible_playbook.py %s -i "%s" %s',
|
|
|
|
|
playbook, HOSTS_DIR, ' '.join(sys.argv[1:]))
|
|
|
|
|
playbook, TMP_HOSTS_DIR, ' '.join(sys.argv[1:]),
|
|
|
|
|
)
|
|
|
|
|
except:
|
|
|
|
|
pause_if_interactive()
|
|
|
|
|
raise
|
|
|
|
|
|