2018-08-12 13:01:04 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Run tests/ansible/all.yml under Ansible and Ansible-Mitogen
|
|
|
|
|
2022-07-04 21:25:51 +00:00
|
|
|
import collections
|
2019-01-22 00:24:43 +00:00
|
|
|
import glob
|
2018-08-12 13:01:04 +00:00
|
|
|
import os
|
2019-05-26 11:06:14 +00:00
|
|
|
import signal
|
2018-08-12 13:01:04 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import ci_lib
|
|
|
|
|
|
|
|
|
|
|
|
TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible')
|
|
|
|
HOSTS_DIR = os.path.join(ci_lib.TMP, 'hosts')
|
|
|
|
|
|
|
|
|
2019-05-26 11:06:14 +00:00
|
|
|
def pause_if_interactive():
|
|
|
|
if os.path.exists('/tmp/interactive'):
|
|
|
|
while True:
|
|
|
|
signal.pause()
|
|
|
|
|
|
|
|
|
2019-08-09 19:19:16 +00:00
|
|
|
interesting = ci_lib.get_interesting_procs()
|
|
|
|
|
|
|
|
|
2018-11-06 13:47:09 +00:00
|
|
|
with ci_lib.Fold('unit_tests'):
|
|
|
|
os.environ['SKIP_MITOGEN'] = '1'
|
|
|
|
ci_lib.run('./run_tests -v')
|
|
|
|
|
|
|
|
|
2019-08-09 19:19:16 +00:00
|
|
|
ci_lib.check_stray_processes(interesting)
|
|
|
|
|
|
|
|
|
2018-08-12 13:01:04 +00:00
|
|
|
with ci_lib.Fold('docker_setup'):
|
2018-11-06 13:47:09 +00:00
|
|
|
containers = ci_lib.make_containers()
|
|
|
|
ci_lib.start_containers(containers)
|
2018-08-12 13:01:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
with ci_lib.Fold('job_setup'):
|
2018-11-06 13:47:09 +00:00
|
|
|
os.chdir(TESTS_DIR)
|
|
|
|
os.chmod('../data/docker/mitogen__has_sudo_pubkey.key', int('0600', 7))
|
|
|
|
|
2022-04-23 07:31:14 +00:00
|
|
|
ci_lib.run("mkdir %s", HOSTS_DIR)
|
2019-01-22 00:24:43 +00:00
|
|
|
for path in glob.glob(TESTS_DIR + '/hosts/*'):
|
|
|
|
if not path.endswith('default.hosts'):
|
2022-04-23 07:31:14 +00:00
|
|
|
ci_lib.run("ln -s %s %s", path, HOSTS_DIR)
|
2018-08-12 13:01:04 +00:00
|
|
|
|
2022-07-04 21:25:51 +00:00
|
|
|
distros = collections.defaultdict(list)
|
|
|
|
families = collections.defaultdict(list)
|
|
|
|
for container in containers:
|
|
|
|
distros[container['distro']].append(container['name'])
|
|
|
|
families[container['family']].append(container['name'])
|
|
|
|
|
2018-11-07 00:52:20 +00:00
|
|
|
inventory_path = os.path.join(HOSTS_DIR, 'target')
|
|
|
|
with open(inventory_path, 'w') as fp:
|
2018-08-12 13:01:04 +00:00
|
|
|
fp.write('[test-targets]\n')
|
2018-11-06 13:47:09 +00:00
|
|
|
fp.writelines(
|
|
|
|
"%(name)s "
|
|
|
|
"ansible_host=%(hostname)s "
|
|
|
|
"ansible_port=%(port)s "
|
2018-11-07 00:52:20 +00:00
|
|
|
"ansible_python_interpreter=%(python_path)s "
|
2018-11-06 13:47:09 +00:00
|
|
|
"ansible_user=mitogen__has_sudo_nopw "
|
|
|
|
"ansible_password=has_sudo_nopw_password"
|
|
|
|
"\n"
|
|
|
|
% container
|
|
|
|
for container in containers
|
|
|
|
)
|
2018-08-12 13:01:04 +00:00
|
|
|
|
2022-09-12 18:20:58 +00:00
|
|
|
for distro, hostnames in sorted(distros.items(), key=lambda t: t[0]):
|
2022-07-04 21:25:51 +00:00
|
|
|
fp.write('\n[%s]\n' % distro)
|
|
|
|
fp.writelines('%s\n' % name for name in hostnames)
|
|
|
|
|
2022-09-12 18:20:58 +00:00
|
|
|
for family, hostnames in sorted(families.items(), key=lambda t: t[0]):
|
2022-07-04 21:25:51 +00:00
|
|
|
fp.write('\n[%s]\n' % family)
|
|
|
|
fp.writelines('%s\n' % name for name in hostnames)
|
|
|
|
|
2022-09-12 18:20:58 +00:00
|
|
|
fp.write('\n[linux:children]\ntest-targets\n')
|
|
|
|
|
2018-11-07 00:40:37 +00:00
|
|
|
ci_lib.dump_file(inventory_path)
|
|
|
|
|
2018-08-12 13:01:04 +00:00
|
|
|
if not ci_lib.exists_in_path('sshpass'):
|
2022-04-23 07:31:14 +00:00
|
|
|
ci_lib.run("sudo apt-get update")
|
|
|
|
ci_lib.run("sudo apt-get install -y sshpass")
|
2018-08-12 13:01:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
with ci_lib.Fold('ansible'):
|
2018-11-05 19:04:09 +00:00
|
|
|
playbook = os.environ.get('PLAYBOOK', 'all.yml')
|
2019-05-26 11:06:14 +00:00
|
|
|
try:
|
2022-04-23 07:31:14 +00:00
|
|
|
ci_lib.run('./run_ansible_playbook.py %s -i "%s" %s',
|
2019-05-26 11:06:14 +00:00
|
|
|
playbook, HOSTS_DIR, ' '.join(sys.argv[1:]))
|
|
|
|
except:
|
|
|
|
pause_if_interactive()
|
|
|
|
raise
|
|
|
|
|
2019-08-09 19:19:16 +00:00
|
|
|
|
|
|
|
ci_lib.check_stray_processes(interesting, containers)
|
|
|
|
|
2019-05-26 11:06:14 +00:00
|
|
|
pause_if_interactive()
|