From a21dba795372fe513ede57a806e873a6f741c5a0 Mon Sep 17 00:00:00 2001 From: Guoxin Sui Date: Wed, 2 Dec 2026 15:56:10 -0700 Subject: [PATCH] CI/CD - Pin Ansible dependencies and reuse build layers Pin two direct Ansible profiles (legacy Python <3.11 on ansible-base 2.10.17 / ansible-runner 2.3.1, modern Python >=3.11 on ansible-core 2.19.15 / ansible-runner 2.4.3, with Jinja2 3.1.6 across all runtimes) in requirements/ansible.txt, and select matching legacy/modern collection pins from ansible-galaxy --version with bounded 3x 300s retries in Makefile. Install the Ansible layer immediately before copying repository source across all seven active Dockerfiles (nine image variants, including CUDA 13.5), constrain subsequent pip installs, and align CI and devcontainer setup scripts. Add offline retry/timeout/mixed-PATH tests and real local collection smoke tests (SSH key generation idempotency, ansible.utils.index_of, and fetch_results.yaml) in tests/runner/test_ansible.py. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .azure-pipelines/ansible-integration-test.yml | 4 +- .azure-pipelines/cpu-unit-test.yml | 4 +- .azure-pipelines/cuda-unit-test.yml | 3 +- .devcontainer/post-create-command.sh | 3 +- Makefile | 22 +- dockerfile/cuda11.1.1.dockerfile | 8 +- dockerfile/cuda12.9.dockerfile | 8 +- dockerfile/cuda13.0.dockerfile | 8 +- dockerfile/cuda13.4.dockerfile | 8 +- dockerfile/cuda13.5.dockerfile | 8 +- dockerfile/rocm6.3.x.dockerfile | 8 +- dockerfile/rocm6.4.x.dockerfile | 10 +- docs/developer-guides/development.md | 17 +- docs/getting-started/installation.mdx | 2 +- requirements/ansible.txt | 8 + setup.py | 8 +- tests/runner/test_ansible.py | 197 ++++++++++++++++++ 17 files changed, 294 insertions(+), 32 deletions(-) create mode 100644 requirements/ansible.txt diff --git a/.azure-pipelines/ansible-integration-test.yml b/.azure-pipelines/ansible-integration-test.yml index 004684a0e..764f7ce9c 100644 --- a/.azure-pipelines/ansible-integration-test.yml +++ b/.azure-pipelines/ansible-integration-test.yml @@ -31,7 +31,9 @@ steps: echo "##vso[task.prependpath]$HOME/.local/bin" displayName: Export path - script: | - python3 -m pip install .[test] + set -e + python3 -m pip install --upgrade setuptools==65.7 + python3 -m pip install -c requirements/ansible.txt .[test] make postinstall displayName: Install Ansible dependencies - script: | diff --git a/.azure-pipelines/cpu-unit-test.yml b/.azure-pipelines/cpu-unit-test.yml index b68dbdb61..88501e585 100644 --- a/.azure-pipelines/cpu-unit-test.yml +++ b/.azure-pipelines/cpu-unit-test.yml @@ -34,15 +34,15 @@ steps: echo "##vso[task.prependpath]$HOME/.local/bin" displayName: Export path - script: | + set -e if python3 -c "import sys; exit(0 if sys.version_info < (3, 11) else 1)"; then python3 -m pip install --upgrade setuptools==65.7 fi - python3 -m pip install --no-cache-dir .[test,cpuworker] + python3 -m pip install --no-cache-dir -c requirements/ansible.txt .[test,cpuworker] displayName: Install dependencies - script: | make postinstall displayName: Install Ansible collections - retryCountOnTaskFailure: 2 - script: | python3 setup.py lint displayName: Run code lint diff --git a/.azure-pipelines/cuda-unit-test.yml b/.azure-pipelines/cuda-unit-test.yml index 4f36ba8ab..947553471 100644 --- a/.azure-pipelines/cuda-unit-test.yml +++ b/.azure-pipelines/cuda-unit-test.yml @@ -35,12 +35,11 @@ steps: apt-get install -y -q \ ffmpeg libavcodec-dev libavformat-dev libavutil-dev libboost-program-options-dev libswresample-dev" python3 -m pip install --upgrade setuptools==65.7 - python3 -m pip install .[test,nvworker] + python3 -m pip install -c requirements/ansible.txt .[test,nvworker] displayName: Install dependencies - script: | make postinstall displayName: Install Ansible collections - retryCountOnTaskFailure: 2 - script: | python3 setup.py lint displayName: Run code lint diff --git a/.devcontainer/post-create-command.sh b/.devcontainer/post-create-command.sh index e719a3575..bc59520ac 100644 --- a/.devcontainer/post-create-command.sh +++ b/.devcontainer/post-create-command.sh @@ -4,7 +4,8 @@ set -e export PATH=${HOME}/.local/bin:${PATH} # install python packages -pip install .[develop,cpuworker] --user --no-cache-dir --progress-bar=off --use-feature=in-tree-build +pip install -c requirements/ansible.txt .[develop,cpuworker] --user --no-cache-dir --progress-bar=off --use-feature=in-tree-build +make postinstall pre-commit install --install-hooks # install nodejs packages diff --git a/Makefile b/Makefile index a7b8f05d1..1d31221a4 100644 --- a/Makefile +++ b/Makefile @@ -21,8 +21,20 @@ thirdparty: cd ./third_party/ && make all postinstall: -ifeq ($(shell which ansible-galaxy),) - $(error 'Cannot find ansible-galaxy') -else - ansible-galaxy collection install ansible.posix ansible.utils community.crypto -endif + @command -v ansible-galaxy >/dev/null || { echo "Cannot find ansible-galaxy" >&2; exit 1; } + @version=$$(ansible-galaxy --version 2>/dev/null | sed -n '1p') || exit $$?; \ + case "$$version" in \ + "") echo "Cannot determine ansible-galaxy version" >&2; exit 1 ;; \ + *" 2.9."* | *" 2.10."* | *"[core 2.1"[1-5]"."*) \ + collections="ansible.posix:1.5.4 ansible.utils:2.12.0 community.crypto:2.16.0" ;; \ + *) \ + collections="ansible.posix:2.2.2 ansible.utils:6.1.1 community.crypto:3.5.1" ;; \ + esac; \ + for attempt in 1 2 3; do \ + timeout -k 30 300 ansible-galaxy collection install $$collections && exit 0; \ + status=$$?; \ + echo "Ansible collections: attempt $$attempt/3 failed (exit $$status)." >&2; \ + if [ $$attempt -eq 3 ]; then exit $$status; fi; \ + echo "Retrying in $$((attempt * 10)) seconds." >&2; \ + sleep $$((attempt * 10)) || exit $$?; \ + done diff --git a/dockerfile/cuda11.1.1.dockerfile b/dockerfile/cuda11.1.1.dockerfile index 8518533ce..9919bf29a 100644 --- a/dockerfile/cuda11.1.1.dockerfile +++ b/dockerfile/cuda11.1.1.dockerfile @@ -164,9 +164,13 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ rustup self uninstall -y && \ rm -rf /root/.cargo /root/.rustup +COPY requirements/ansible.txt requirements/ansible.txt +COPY Makefile ./ +RUN python3 -m pip install --no-cache-dir -r requirements/ansible.txt && \ + make postinstall + ADD . . RUN python3 -m pip install --upgrade setuptools==65.7 importlib_metadata==6.8.0 && \ - python3 -m pip install --no-cache-dir .[nvworker] && \ + python3 -m pip install --no-cache-dir -c requirements/ansible.txt .[nvworker] && \ make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/cuda12.9.dockerfile b/dockerfile/cuda12.9.dockerfile index 3c2c92000..fbc43542b 100644 --- a/dockerfile/cuda12.9.dockerfile +++ b/dockerfile/cuda12.9.dockerfile @@ -187,9 +187,13 @@ WORKDIR ${SB_HOME} ADD third_party third_party RUN make -C third_party cuda_with_msccl +COPY requirements/ansible.txt requirements/ansible.txt +COPY Makefile ./ +RUN python3 -m pip install --no-cache-dir -r requirements/ansible.txt && \ + make postinstall + ADD . . RUN python3 -m pip install --upgrade setuptools==78.1.0 && \ - python3 -m pip install --no-cache-dir .[nvworker] && \ + python3 -m pip install --no-cache-dir -c requirements/ansible.txt .[nvworker] && \ make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/cuda13.0.dockerfile b/dockerfile/cuda13.0.dockerfile index 520920afa..25c3c7911 100644 --- a/dockerfile/cuda13.0.dockerfile +++ b/dockerfile/cuda13.0.dockerfile @@ -154,9 +154,13 @@ WORKDIR ${SB_HOME} ADD third_party third_party RUN make -C third_party cuda +COPY requirements/ansible.txt requirements/ansible.txt +COPY Makefile ./ +RUN python3 -m pip install --no-cache-dir -r requirements/ansible.txt && \ + make postinstall + ADD . . RUN python3 -m pip install --upgrade setuptools==78.1.0 && \ - python3 -m pip install --no-cache-dir .[nvworker] && \ + python3 -m pip install --no-cache-dir -c requirements/ansible.txt .[nvworker] && \ make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/cuda13.4.dockerfile b/dockerfile/cuda13.4.dockerfile index 09d85889c..1c76b413f 100644 --- a/dockerfile/cuda13.4.dockerfile +++ b/dockerfile/cuda13.4.dockerfile @@ -198,9 +198,13 @@ RUN f=${SB_MICRO_PATH}/bin/streamOlympus; \ if printf '%s\n' "$output" | grep -Eq 'not found|undefined symbol'; then exit 1; fi; \ fi +COPY requirements/ansible.txt requirements/ansible.txt +COPY Makefile ./ +RUN python3 -m pip install --no-cache-dir -r requirements/ansible.txt && \ + make postinstall + ADD . . RUN python3 -m pip install --upgrade setuptools==78.1.0 && \ - python3 -m pip install --no-cache-dir .[nvworker] && \ + python3 -m pip install --no-cache-dir -c requirements/ansible.txt .[nvworker] && \ make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/cuda13.5.dockerfile b/dockerfile/cuda13.5.dockerfile index 646f36f38..77b78b8f8 100644 --- a/dockerfile/cuda13.5.dockerfile +++ b/dockerfile/cuda13.5.dockerfile @@ -187,6 +187,11 @@ ADD dockerfile/etc /opt/microsoft/ WORKDIR ${SB_HOME} +COPY requirements/ansible.txt requirements/ansible.txt +COPY Makefile ./ +RUN python3 -m pip install --no-cache-dir -r requirements/ansible.txt && \ + make postinstall + # Copy everything before release clones so legacy submodules cannot overlay them later. ADD . . # Build the CUDA targets (the `cuda` aggregate; MSCCL is not included). mpicc comes from the @@ -206,7 +211,6 @@ RUN f=${SB_MICRO_PATH}/bin/streamOlympus; \ # Keep the base image's setuptools version for NVIDIA ModelOpt compatibility. RUN python3 -m pip install --upgrade setuptools==81.0.0 && \ - python3 -m pip install --no-cache-dir .[nvworker] && \ + python3 -m pip install --no-cache-dir -c requirements/ansible.txt .[nvworker] && \ make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/rocm6.3.x.dockerfile b/dockerfile/rocm6.3.x.dockerfile index a03c53bff..1e4471291 100644 --- a/dockerfile/rocm6.3.x.dockerfile +++ b/dockerfile/rocm6.3.x.dockerfile @@ -140,10 +140,14 @@ ADD third_party third_party RUN make RCCL_HOME=/opt/rocm ROCBLAS_BRANCH=release-staging/rocm-rel-6.3 HIPBLASLT_BRANCH=release-staging/rocm-rel-6.3 ROCM_VER=rocm-5.5.0 -C third_party rocm -o cpu_hpl -o cpu_stream -o megatron_lm -o rocm_megatron_lm +COPY requirements/ansible.txt requirements/ansible.txt +COPY Makefile ./ +RUN python3 -m pip install --no-cache-dir -r requirements/ansible.txt && \ + make postinstall + ADD . . ENV USE_HIP_DATATYPE=1 ENV USE_HIPBLAS_COMPUTETYPE=1 -RUN python3 -m pip install --no-build-isolation .[amdworker] && \ +RUN python3 -m pip install --no-build-isolation -c requirements/ansible.txt .[amdworker] && \ CXX=/opt/rocm/bin/hipcc make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/rocm6.4.x.dockerfile b/dockerfile/rocm6.4.x.dockerfile index cd7670e9a..4924f4ec5 100644 --- a/dockerfile/rocm6.4.x.dockerfile +++ b/dockerfile/rocm6.4.x.dockerfile @@ -242,14 +242,18 @@ RUN transformer_engine_architectures=$(printf '%s' "${AMDGPU_TARGETS}" | tr -s ' python3 setup.py install RUN python3 -c "import transformer_engine.pytorch; print('TE installed successfully')" +COPY requirements/ansible.txt requirements/ansible.txt +COPY Makefile ./ +RUN python3 -m pip install --no-cache-dir -r requirements/ansible.txt && \ + make postinstall + ADD . . ENV USE_HIP_DATATYPE=1 ENV USE_HIPBLAS_COMPUTETYPE=1 -RUN python3 -m pip install .[amdworker] && \ +RUN python3 -m pip install -c requirements/ansible.txt .[amdworker] && \ CXX=/opt/rocm/bin/hipcc make cppbuild && \ - make postinstall && \ rm -rf .git # Fix stale hypothesis plugin from base image (imports removed pkg_resources) # and add test dependencies missing from the base image. -RUN python3 -m pip install --upgrade hypothesis setuptools pytest-timeout vcrpy +RUN python3 -m pip install -c requirements/ansible.txt --upgrade hypothesis setuptools pytest-timeout vcrpy diff --git a/docs/developer-guides/development.md b/docs/developer-guides/development.md index e6b749485..a4cd44ae7 100644 --- a/docs/developer-guides/development.md +++ b/docs/developer-guides/development.md @@ -19,9 +19,24 @@ Follow [System Requirements](../getting-started/installation.mdx). git clone --recurse-submodules -j8 https://github.com/microsoft/superbenchmark cd superbenchmark -python3 -m pip install -e .[develop] +python3 -m pip install -c requirements/ansible.txt -e .[develop] +make postinstall ``` +Use a clean Python environment without the bundled `ansible` distribution. +The Linux control environment needs GNU `timeout`, `openssh-client` and `rsync`. + +### Ansible Dependencies + +`requirements/ansible.txt` pins the Ansible engine, `ansible-runner`, and +`Jinja2` for each supported Python runtime, while `Makefile` (`make postinstall`) +selects the matching legacy or modern collection pins from the active +`ansible-galaxy` runtime with bounded retries. Active GPU Dockerfiles install +this layer before copying the repository so source-only edits reuse the cached +layer. When updating versions, keep `requirements/ansible.txt`, `setup.py`, and +`Makefile` aligned and run `python3 -m pytest -q tests/runner/test_ansible.py` +across legacy and modern Python runtimes. + ## Lint and Test Format code using yapf. diff --git a/docs/getting-started/installation.mdx b/docs/getting-started/installation.mdx index a3f2f7c47..1e7ea25b6 100644 --- a/docs/getting-started/installation.mdx +++ b/docs/getting-started/installation.mdx @@ -68,7 +68,7 @@ You should checkout corresponding tag to use release version, for example, git clone https://github.com/microsoft/superbenchmark cd superbenchmark -python3 -m pip install . +python3 -m pip install -c requirements/ansible.txt . make postinstall ``` diff --git a/requirements/ansible.txt b/requirements/ansible.txt new file mode 100644 index 000000000..2d988f3fe --- /dev/null +++ b/requirements/ansible.txt @@ -0,0 +1,8 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +ansible-base==2.10.17; python_version < "3.11" +ansible-core==2.19.15; python_version >= "3.11" +ansible-runner==2.3.1; python_version < "3.11" +ansible-runner==2.4.3; python_version >= "3.11" +Jinja2==3.1.6 diff --git a/setup.py b/setup.py index 114f6590a..235ec46ed 100644 --- a/setup.py +++ b/setup.py @@ -165,10 +165,10 @@ def run(self): 'vcs_versioning; python_version>="3.10"', ], install_requires=[ - 'ansible;os_name=="posix" and python_version>"3.10"', - 'ansible_base>=2.10.9;os_name=="posix" and python_version<="3.10"', - 'ansible_runner>=2.0.0rc1, <2.3.2;python_version<="3.10"', - 'ansible_runner;python_version>"3.10"', + 'ansible-core>=2.19,<2.23;os_name=="posix" and python_version>="3.11"', + 'ansible_base>=2.10.17,<2.11;os_name=="posix" and python_version<"3.11"', + 'ansible_runner>=2.0.0rc1, <2.3.2;python_version<"3.11"', + 'ansible_runner>=2.4.3,<2.5;python_version>="3.11"', 'colorlog>=6.7.0', 'importlib_metadata', 'jinja2>=2.10.1', diff --git a/tests/runner/test_ansible.py b/tests/runner/test_ansible.py index 550762c43..ec8f6563f 100644 --- a/tests/runner/test_ansible.py +++ b/tests/runner/test_ansible.py @@ -3,7 +3,11 @@ """SuperBench Ansible Client test.""" +import json import os +import shutil +import subprocess +import sys import unittest import tempfile from pathlib import Path @@ -15,6 +19,93 @@ AnsibleClient = LazyImport('superbench.runner.ansible', 'AnsibleClient') +@unittest.skipUnless(os.name == 'posix', 'Makefile postinstall requires POSIX.') +class AnsiblePostinstallTestCase(unittest.TestCase): + """Test the shared Makefile entry point without contacting Galaxy.""" + @staticmethod + def _run_postinstall(root, codes, galaxy_version, python_minor='12'): + """Run make postinstall against local CLI stubs.""" + attempts = root / 'attempts' + waits = root / 'waits' + status_codes = root / 'codes' + status_codes.write_text('\n'.join(map(str, codes)) + '\n') + waits.touch() + scripts = { + 'python3': + 'printf "3.{}\\n"\n'.format(python_minor), + 'timeout': ( + 'printf "%s\\n" "$*" >> "$INSTALL_ATTEMPTS"\n' + 'while [ "$#" -gt 0 ] && [ "$1" != ansible-galaxy ]; do shift; done\n' + 'exec "$@"\n' + ), + 'ansible-galaxy': ( + 'if [ "${1:-}" = --version ]; then\n' + ' printf "%s\\n" "$GALAXY_VERSION"\n' + ' exit 0\n' + 'fi\n' + 'attempt=$(wc -l < "$INSTALL_ATTEMPTS")\n' + 'exit "$(sed -n "${attempt}p" "$INSTALL_CODES")"\n' + ), + 'sleep': + 'printf "%s\\n" "$1" >> "$INSTALL_WAITS"\n', + } + for name, body in scripts.items(): + script = root / name + script.write_text('#!/bin/sh\nset -eu\n' + body) + script.chmod(0o755) + py_bin = os.path.dirname(os.path.abspath(sys.executable)) + env = dict( + os.environ, + PATH=os.pathsep.join([str(root), py_bin, os.environ.get('PATH', '')]), + GALAXY_VERSION=galaxy_version, + INSTALL_ATTEMPTS=str(attempts), + INSTALL_WAITS=str(waits), + INSTALL_CODES=str(status_codes), + ) + result = subprocess.run( + ['make', '--no-print-directory', 'postinstall'], + cwd=Path(__file__).resolve().parents[2], + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + timeout=30, + ) + return result, attempts.read_text().splitlines(), waits.read_text().splitlines() + + def test_bounded_collection_retries(self): + """Bound installation attempts and timeout, stopping on success.""" + for codes in [[0], [1, 0], [1, 1, 0], [17, 17, 17]]: + with self.subTest(codes=codes), tempfile.TemporaryDirectory() as directory: + result, commands, waits = self._run_postinstall(Path(directory), codes, 'ansible-galaxy [core 2.19.15]') + self.assertEqual(result.returncode == 0, codes[-1] == 0, result.stdout) + self.assertEqual(len(commands), len(codes), result.stdout) + self.assertEqual(commands, [commands[0]] * len(codes)) + self.assertEqual( + commands[0], + '-k 30 300 ansible-galaxy collection install ' + 'ansible.posix:2.2.2 ansible.utils:6.1.1 community.crypto:3.5.1', + ) + self.assertEqual(waits, ['10', '20'][:len(codes) - 1]) + if codes[-1]: + self.assertIn('attempt 3/3 failed (exit {}).'.format(codes[-1]), result.stdout) + + def test_profile_follows_galaxy_runtime(self): + """Select collection pins from ansible-galaxy even when PATH python3 differs.""" + cases = [ + ('ansible-galaxy 2.10.17', '12', 'ansible.posix:1.5.4 ansible.utils:2.12.0 community.crypto:2.16.0'), + ('ansible-galaxy [core 2.19.15]', '8', 'ansible.posix:2.2.2 ansible.utils:6.1.1 community.crypto:3.5.1'), + ] + for galaxy_version, py_minor, expected_collections in cases: + with self.subTest(galaxy_version=galaxy_version), tempfile.TemporaryDirectory() as directory: + result, commands, _ = self._run_postinstall(Path(directory), [0], galaxy_version, py_minor) + self.assertEqual(result.returncode, 0, result.stdout) + self.assertEqual( + commands, + ['-k 30 300 ansible-galaxy collection install ' + expected_collections], + ) + + class AnsibleClientTestCase(unittest.TestCase): """A class for ansible client test cases.""" def setUp(self): @@ -158,3 +249,109 @@ def test_get_playbook_config(self): 'playbook': str(self.ansible_client._playbook_path / 'play'), } ) + + @unittest.skipUnless(os.name == 'posix', 'Ansible runner execution requires POSIX.') + def test_local_execution_and_failure_count(self): + """Exercise the real runner and preserve nonzero command failures.""" + client = AnsibleClient(OmegaConf.create({'host_list': 'localhost'})) + with tempfile.TemporaryDirectory(prefix='sb-ansible-client-') as directory: + py_bin = os.path.dirname(os.path.abspath(sys.executable)) + env = { + 'ANSIBLE_LOCAL_TEMP': str(Path(directory) / 'local'), + 'ANSIBLE_REMOTE_TEMP': str(Path(directory) / 'remote'), + 'PATH': py_bin + os.pathsep + os.environ.get('PATH', ''), + } + for command, expected in [('printf sb-ansible-smoke', 0), ('exit 7', 2)]: + config = client.get_shell_config(command) + config['extravars'] = {'ansible_python_interpreter': sys.executable} + config['envvars'] = env + self.assertEqual(client.run(config), expected) + self.assertEqual(client.failure_count, 1) + + @staticmethod + def _collection_env(root): + """Build isolated Ansible environment, adding a minimal rsync fallback if absent.""" + bin_path = os.path.dirname(os.path.abspath(sys.executable)) + os.pathsep + os.environ.get('PATH', '') + env = { + 'ANSIBLE_LOCAL_TEMP': str(root / 'local'), + 'ANSIBLE_REMOTE_TEMP': str(root / 'remote'), + 'PATH': bin_path, + } + if shutil.which('rsync', path=bin_path) is None: + shim_dir = root / 'bin' + shim_dir.mkdir() + shim = shim_dir / 'rsync' + shim.write_text( + '#!{}\nimport os, shutil, sys\n' + 'src, dst = sys.argv[-2], sys.argv[-1]\n' + 'os.makedirs(dst, exist_ok=True)\n' + 'for name in os.listdir(src):\n' + ' if "--exclude=" + name not in sys.argv:\n' + ' shutil.copy2(os.path.join(src, name), os.path.join(dst, name))\n'.format(sys.executable) + ) + shim.chmod(0o755) + env['PATH'] = str(shim_dir) + os.pathsep + env['PATH'] + return env + + @unittest.skipUnless(os.name == 'posix', 'Ansible collections require POSIX.') + def test_local_collection_operations(self): + """Exercise key generation idempotency, index_of, and fetch_results.yaml.""" + client = AnsibleClient(OmegaConf.create({'host_list': 'localhost'})) + with tempfile.TemporaryDirectory(prefix='sb-ansible-collections-') as directory: + root = Path(directory) + (root / 'source' / 'nodes').mkdir(parents=True) + (root / 'received' / 'nodes').mkdir(parents=True) + (root / 'source' / 'results.json').write_text('{"result": 42}') + (root / 'source' / 'nodes' / 'excluded').write_text('excluded') + env = self._collection_env(root) + + playbook = root / 'collection_smoke.yaml' + playbook.write_text( + '- hosts: all\n' + ' gather_facts: false\n' + ' tasks:\n' + ' - community.crypto.openssh_keypair:\n' + ' path: "{{ key_path }}"\n' + ' type: ed25519\n' + ' comment: superbench\n' + ' force: false\n' + ' register: first_key\n' + ' no_log: true\n' + ' - community.crypto.openssh_keypair:\n' + ' path: "{{ key_path }}"\n' + ' type: ed25519\n' + ' comment: superbench\n' + ' force: false\n' + ' register: second_key\n' + ' no_log: true\n' + ' - assert:\n' + ' that:\n' + ' - first_key is changed\n' + ' - second_key is not changed\n' + ' - first_key.public_key == second_key.public_key\n' + " - lookup('ansible.utils.index_of', ['n2', 'n0', 'n1'] | sort, 'eq', 'n1') | int == 1\n" + ) + smoke_cfg = client.get_playbook_config( + str(playbook), { + 'ansible_python_interpreter': sys.executable, + 'key_path': str(root / 'id_ed25519'), + } + ) + smoke_cfg['playbook'] = str(playbook) + smoke_cfg['envvars'] = env + self.assertEqual(client.run(smoke_cfg), 0) + + fetch_cfg = client.get_playbook_config( + 'fetch_results.yaml', { + 'ansible_python_interpreter': sys.executable, + 'sb_output_dir': str(root / 'source'), + 'absolute_output_dir': str(root / 'received'), + } + ) + fetch_cfg['envvars'] = env + self.assertEqual(client.run(fetch_cfg), 0) + + fetched = list((root / 'received' / 'nodes').glob('*/results.json')) + self.assertEqual(len(fetched), 1) + self.assertEqual(json.loads(fetched[0].read_text()), {'result': 42}) + self.assertFalse((fetched[0].parent / 'nodes').exists())