tests: Regression test for #776 (package/yum/dnf module called twice)

pull/949/head
Alex Willmer 2 years ago
parent 24c845379a
commit 64819ecb5f

@ -1,6 +1,7 @@
#!/usr/bin/env python
# Run tests/ansible/all.yml under Ansible and Ansible-Mitogen
import collections
import glob
import os
import signal
@ -44,6 +45,12 @@ with ci_lib.Fold('job_setup'):
if not path.endswith('default.hosts'):
ci_lib.run("ln -s %s %s", path, HOSTS_DIR)
distros = collections.defaultdict(list)
families = collections.defaultdict(list)
for container in containers:
distros[container['distro']].append(container['name'])
families[container['family']].append(container['name'])
inventory_path = os.path.join(HOSTS_DIR, 'target')
with open(inventory_path, 'w') as fp:
fp.write('[test-targets]\n')
@ -59,6 +66,14 @@ with ci_lib.Fold('job_setup'):
for container in containers
)
for distro, hostnames in distros.items():
fp.write('\n[%s]\n' % distro)
fp.writelines('%s\n' % name for name in hostnames)
for family, hostnames in families.items():
fp.write('\n[%s]\n' % family)
fp.writelines('%s\n' % name for name in hostnames)
ci_lib.dump_file(inventory_path)
if not ci_lib.exists_in_path('sshpass'):

@ -4,6 +4,7 @@ from __future__ import print_function
import atexit
import errno
import os
import re
import shlex
import shutil
import sys
@ -221,31 +222,20 @@ def get_docker_hostname():
return parsed.netloc.partition(':')[0]
def image_for_distro(distro):
"""Return the container image name or path for a test distro name.
The returned value is suitable for use with `docker pull`.
>>> image_for_distro('centos5')
'public.ecr.aws/n5z0e8q9/centos5-test'
>>> image_for_distro('centos5-something_custom')
'public.ecr.aws/n5z0e8q9/centos5-test'
"""
return 'public.ecr.aws/n5z0e8q9/%s-test' % (distro.partition('-')[0],)
def make_containers(name_prefix='', port_offset=0):
"""
>>> import pprint
>>> BASE_PORT=2200; DISTROS=['debian', 'centos6']
>>> BASE_PORT=2200; DISTROS=['debian11', 'centos6']
>>> pprint.pprint(make_containers())
[{'distro': 'debian',
[{'distro': 'debian11',
'family': 'debian',
'hostname': 'localhost',
'image': 'public.ecr.aws/n5z0e8q9/debian-test',
'name': 'target-debian-1',
'image': 'public.ecr.aws/n5z0e8q9/debian11-test',
'name': 'target-debian11-1',
'port': 2201,
'python_path': '/usr/bin/python'},
{'distro': 'centos6',
'family': 'centos',
'hostname': 'localhost',
'image': 'public.ecr.aws/n5z0e8q9/centos6-test',
'name': 'target-centos6-2',
@ -253,31 +243,39 @@ def make_containers(name_prefix='', port_offset=0):
'python_path': '/usr/bin/python'}]
"""
docker_hostname = get_docker_hostname()
firstbit = lambda s: (s+'-').split('-')[0]
secondbit = lambda s: (s+'-').split('-')[1]
distro_pattern = re.compile(r'''
(?P<distro>(?P<family>[a-z]+)[0-9]+)
(?:-(?P<py>py3))?
(?:\*(?P<count>[0-9]+))?
''',
re.VERBOSE,
)
i = 1
lst = []
for distro in DISTROS:
distro, star, count = distro.partition('*')
if star:
d = distro_pattern.match(distro).groupdict(default=None)
distro = d['distro']
family = d['family']
image = 'public.ecr.aws/n5z0e8q9/%s-test' % (distro,)
if d['py'] == 'py3':
python_path = '/usr/bin/python3'
else:
python_path = '/usr/bin/python'
if d['count']:
count = int(count)
else:
count = 1
for x in range(count):
lst.append({
"distro": firstbit(distro),
"image": image_for_distro(distro),
"distro": distro, "family": family, "image": image,
"name": name_prefix + ("target-%s-%s" % (distro, i)),
"hostname": docker_hostname,
"port": BASE_PORT + i + port_offset,
"python_path": (
'/usr/bin/python3'
if secondbit(distro) == 'py3'
else '/usr/bin/python'
)
"python_path": python_path,
})
i += 1

@ -0,0 +1,2 @@
---
pkg_mgr_python_interpreter: /usr/bin/python

@ -0,0 +1,2 @@
---
pkg_mgr_python_interpreter: /usr/libexec/platform-python

@ -13,3 +13,4 @@
- import_playbook: issue_591__setuptools_cwd_crash.yml
- import_playbook: issue_615__streaming_transfer.yml
- import_playbook: issue_655__wait_for_connection_error.yml
- import_playbook: issue_776__load_plugins_called_twice.yml

@ -0,0 +1,46 @@
# https://github.com/mitogen-hq/mitogen/issues/776
---
- name: regression/issue_776__load_plugins_called_twice.yml
hosts: test-targets
become: "{{ ansible_facts.pkg_mgr not in ['homebrew'] }}"
gather_facts: yes
tags:
- issue_776
vars:
ansible_python_interpreter: "{{ pkg_mgr_python_interpreter }}"
package: rsync # Chosen to exist in all tested distros/package managers
tasks:
- name: Switch to centos-stream
command: dnf --assumeyes --disablerepo="*" --enablerepo=extras swap centos-linux-repos centos-stream-repos
when:
- ansible_facts.pkg_mgr in ["dnf"]
- name: Update package index
apt:
update_cache: true
when:
- ansible_facts.pkg_mgr in ["apt"]
- name: Test package module 1st call
package:
name: "{{ package }}"
state: present
- name: Test package module 2nd call
package:
name: "{{ package }}"
state: present
- name: Test dnf module 2nd call
dnf:
name: "{{ package }}"
state: present
when:
- ansible_facts.pkg_mgr == 'dnf'
- name: Test dnf module 2nd call
dnf:
name: "{{ package }}"
state: present
when:
- ansible_facts.pkg_mgr == 'dnf'
Loading…
Cancel
Save