Skip to content

Commit 64819ec

Browse files
committed
tests: Regression test for #776 (package/yum/dnf module called twice)
1 parent 24c8453 commit 64819ec

File tree

6 files changed

+93
-29
lines changed

6 files changed

+93
-29
lines changed

.ci/ansible_tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# Run tests/ansible/all.yml under Ansible and Ansible-Mitogen
33

4+
import collections
45
import glob
56
import os
67
import signal
@@ -44,6 +45,12 @@ def pause_if_interactive():
4445
if not path.endswith('default.hosts'):
4546
ci_lib.run("ln -s %s %s", path, HOSTS_DIR)
4647

48+
distros = collections.defaultdict(list)
49+
families = collections.defaultdict(list)
50+
for container in containers:
51+
distros[container['distro']].append(container['name'])
52+
families[container['family']].append(container['name'])
53+
4754
inventory_path = os.path.join(HOSTS_DIR, 'target')
4855
with open(inventory_path, 'w') as fp:
4956
fp.write('[test-targets]\n')
@@ -59,6 +66,14 @@ def pause_if_interactive():
5966
for container in containers
6067
)
6168

69+
for distro, hostnames in distros.items():
70+
fp.write('\n[%s]\n' % distro)
71+
fp.writelines('%s\n' % name for name in hostnames)
72+
73+
for family, hostnames in families.items():
74+
fp.write('\n[%s]\n' % family)
75+
fp.writelines('%s\n' % name for name in hostnames)
76+
6277
ci_lib.dump_file(inventory_path)
6378

6479
if not ci_lib.exists_in_path('sshpass'):

.ci/ci_lib.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import atexit
55
import errno
66
import os
7+
import re
78
import shlex
89
import shutil
910
import sys
@@ -221,63 +222,60 @@ def get_docker_hostname():
221222
return parsed.netloc.partition(':')[0]
222223

223224

224-
def image_for_distro(distro):
225-
"""Return the container image name or path for a test distro name.
226-
227-
The returned value is suitable for use with `docker pull`.
228-
229-
>>> image_for_distro('centos5')
230-
'public.ecr.aws/n5z0e8q9/centos5-test'
231-
>>> image_for_distro('centos5-something_custom')
232-
'public.ecr.aws/n5z0e8q9/centos5-test'
233-
"""
234-
return 'public.ecr.aws/n5z0e8q9/%s-test' % (distro.partition('-')[0],)
235-
236-
237225
def make_containers(name_prefix='', port_offset=0):
238226
"""
239227
>>> import pprint
240-
>>> BASE_PORT=2200; DISTROS=['debian', 'centos6']
228+
>>> BASE_PORT=2200; DISTROS=['debian11', 'centos6']
241229
>>> pprint.pprint(make_containers())
242-
[{'distro': 'debian',
230+
[{'distro': 'debian11',
231+
'family': 'debian',
243232
'hostname': 'localhost',
244-
'image': 'public.ecr.aws/n5z0e8q9/debian-test',
245-
'name': 'target-debian-1',
233+
'image': 'public.ecr.aws/n5z0e8q9/debian11-test',
234+
'name': 'target-debian11-1',
246235
'port': 2201,
247236
'python_path': '/usr/bin/python'},
248237
{'distro': 'centos6',
238+
'family': 'centos',
249239
'hostname': 'localhost',
250240
'image': 'public.ecr.aws/n5z0e8q9/centos6-test',
251241
'name': 'target-centos6-2',
252242
'port': 2202,
253243
'python_path': '/usr/bin/python'}]
254244
"""
255245
docker_hostname = get_docker_hostname()
256-
firstbit = lambda s: (s+'-').split('-')[0]
257-
secondbit = lambda s: (s+'-').split('-')[1]
258-
246+
distro_pattern = re.compile(r'''
247+
(?P<distro>(?P<family>[a-z]+)[0-9]+)
248+
(?:-(?P<py>py3))?
249+
(?:\*(?P<count>[0-9]+))?
250+
''',
251+
re.VERBOSE,
252+
)
259253
i = 1
260254
lst = []
261255

262256
for distro in DISTROS:
263-
distro, star, count = distro.partition('*')
264-
if star:
257+
d = distro_pattern.match(distro).groupdict(default=None)
258+
distro = d['distro']
259+
family = d['family']
260+
image = 'public.ecr.aws/n5z0e8q9/%s-test' % (distro,)
261+
262+
if d['py'] == 'py3':
263+
python_path = '/usr/bin/python3'
264+
else:
265+
python_path = '/usr/bin/python'
266+
267+
if d['count']:
265268
count = int(count)
266269
else:
267270
count = 1
268271

269272
for x in range(count):
270273
lst.append({
271-
"distro": firstbit(distro),
272-
"image": image_for_distro(distro),
274+
"distro": distro, "family": family, "image": image,
273275
"name": name_prefix + ("target-%s-%s" % (distro, i)),
274276
"hostname": docker_hostname,
275277
"port": BASE_PORT + i + port_offset,
276-
"python_path": (
277-
'/usr/bin/python3'
278-
if secondbit(distro) == 'py3'
279-
else '/usr/bin/python'
280-
)
278+
"python_path": python_path,
281279
})
282280
i += 1
283281

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
pkg_mgr_python_interpreter: /usr/bin/python
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
pkg_mgr_python_interpreter: /usr/libexec/platform-python

tests/ansible/regression/all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
- import_playbook: issue_591__setuptools_cwd_crash.yml
1414
- import_playbook: issue_615__streaming_transfer.yml
1515
- import_playbook: issue_655__wait_for_connection_error.yml
16+
- import_playbook: issue_776__load_plugins_called_twice.yml
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# https://github.com/mitogen-hq/mitogen/issues/776
2+
---
3+
- name: regression/issue_776__load_plugins_called_twice.yml
4+
hosts: test-targets
5+
become: "{{ ansible_facts.pkg_mgr not in ['homebrew'] }}"
6+
gather_facts: yes
7+
tags:
8+
- issue_776
9+
vars:
10+
ansible_python_interpreter: "{{ pkg_mgr_python_interpreter }}"
11+
package: rsync # Chosen to exist in all tested distros/package managers
12+
tasks:
13+
- name: Switch to centos-stream
14+
command: dnf --assumeyes --disablerepo="*" --enablerepo=extras swap centos-linux-repos centos-stream-repos
15+
when:
16+
- ansible_facts.pkg_mgr in ["dnf"]
17+
18+
- name: Update package index
19+
apt:
20+
update_cache: true
21+
when:
22+
- ansible_facts.pkg_mgr in ["apt"]
23+
24+
- name: Test package module 1st call
25+
package:
26+
name: "{{ package }}"
27+
state: present
28+
29+
- name: Test package module 2nd call
30+
package:
31+
name: "{{ package }}"
32+
state: present
33+
34+
- name: Test dnf module 2nd call
35+
dnf:
36+
name: "{{ package }}"
37+
state: present
38+
when:
39+
- ansible_facts.pkg_mgr == 'dnf'
40+
41+
- name: Test dnf module 2nd call
42+
dnf:
43+
name: "{{ package }}"
44+
state: present
45+
when:
46+
- ansible_facts.pkg_mgr == 'dnf'

0 commit comments

Comments
 (0)