From 64819ecb5f1e394c034181b6b9f82241b1191583 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 4 Jul 2022 22:25:51 +0100 Subject: [PATCH] tests: Regression test for #776 (package/yum/dnf module called twice) --- .ci/ansible_tests.py | 15 +++++ .ci/ci_lib.py | 56 +++++++++---------- tests/ansible/hosts/group_vars/all.yml | 2 + tests/ansible/hosts/group_vars/centos8.yml | 2 + tests/ansible/regression/all.yml | 1 + .../issue_776__load_plugins_called_twice.yml | 46 +++++++++++++++ 6 files changed, 93 insertions(+), 29 deletions(-) create mode 100644 tests/ansible/hosts/group_vars/all.yml create mode 100644 tests/ansible/hosts/group_vars/centos8.yml create mode 100755 tests/ansible/regression/issue_776__load_plugins_called_twice.yml diff --git a/.ci/ansible_tests.py b/.ci/ansible_tests.py index 3c3684f4..fd0714a7 100755 --- a/.ci/ansible_tests.py +++ b/.ci/ansible_tests.py @@ -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'): diff --git a/.ci/ci_lib.py b/.ci/ci_lib.py index 2587e859..31bee804 100644 --- a/.ci/ci_lib.py +++ b/.ci/ci_lib.py @@ -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(?P[a-z]+)[0-9]+) + (?:-(?Ppy3))? + (?:\*(?P[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 diff --git a/tests/ansible/hosts/group_vars/all.yml b/tests/ansible/hosts/group_vars/all.yml new file mode 100644 index 00000000..08c4495d --- /dev/null +++ b/tests/ansible/hosts/group_vars/all.yml @@ -0,0 +1,2 @@ +--- +pkg_mgr_python_interpreter: /usr/bin/python diff --git a/tests/ansible/hosts/group_vars/centos8.yml b/tests/ansible/hosts/group_vars/centos8.yml new file mode 100644 index 00000000..7b9e34f6 --- /dev/null +++ b/tests/ansible/hosts/group_vars/centos8.yml @@ -0,0 +1,2 @@ +--- +pkg_mgr_python_interpreter: /usr/libexec/platform-python diff --git a/tests/ansible/regression/all.yml b/tests/ansible/regression/all.yml index 48fa8557..0e599476 100644 --- a/tests/ansible/regression/all.yml +++ b/tests/ansible/regression/all.yml @@ -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 diff --git a/tests/ansible/regression/issue_776__load_plugins_called_twice.yml b/tests/ansible/regression/issue_776__load_plugins_called_twice.yml new file mode 100755 index 00000000..bd57fe12 --- /dev/null +++ b/tests/ansible/regression/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'