Skip to content

Commit

Permalink
fixup! tests: Regression test for #776 (package/yum/dnf module called…
Browse files Browse the repository at this point in the history
… twice)
  • Loading branch information
moreati committed Jul 6, 2022
1 parent 512ae12 commit 6bf6a46
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 30 deletions.
15 changes: 15 additions & 0 deletions .ci/ansible_tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -44,6 +45,12 @@ def pause_if_interactive():
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')
Expand All @@ -59,6 +66,14 @@ def pause_if_interactive():
for container in containers
)

for distro, containers in distros.items():
fp.write('\n[%s]\n' % distro)
fp.writelines('%s\n' % name for name in containers)

for family, containers in families.items():
fp.write('\n[%s]\n' % family)
fp.writelines('%s\n' % name for name in containers)

ci_lib.dump_file(inventory_path)

if not ci_lib.exists_in_path('sshpass'):
Expand Down
56 changes: 27 additions & 29 deletions .ci/ci_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import atexit
import errno
import os
import re
import shlex
import shutil
import sys
Expand Down Expand Up @@ -221,63 +222,60 @@ 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',
'port': 2202,
'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

Expand Down
2 changes: 2 additions & 0 deletions tests/ansible/hosts/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
pkg_mgr_python_interpreter: /usr/bin/python
2 changes: 2 additions & 0 deletions tests/ansible/hosts/group_vars/centos8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
pkg_mgr_python_interpreter: /usr/libexec/platform-python
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
tags:
- issue_776
vars:
package: coreutils # Chosen to exist in all tested distros/package managers
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
Expand Down

0 comments on commit 6bf6a46

Please sign in to comment.