diff --git a/.azure-pipelines/ansible-integration-test.yml b/.azure-pipelines/ansible-integration-test.yml index 9c8550966..678c5bbd7 100644 --- a/.azure-pipelines/ansible-integration-test.yml +++ b/.azure-pipelines/ansible-integration-test.yml @@ -23,7 +23,8 @@ steps: echo "##vso[task.prependpath]$HOME/.local/bin" displayName: Export path - script: | - python3 -m pip install .[test] + set -e + 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 ee71e4956..a61ea35da 100644 --- a/.azure-pipelines/cpu-unit-test.yml +++ b/.azure-pipelines/cpu-unit-test.yml @@ -26,10 +26,11 @@ 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] make postinstall displayName: Install dependencies - script: | diff --git a/.azure-pipelines/cuda-unit-test.yml b/.azure-pipelines/cuda-unit-test.yml index be06491e8..8807206d1 100644 --- a/.azure-pipelines/cuda-unit-test.yml +++ b/.azure-pipelines/cuda-unit-test.yml @@ -27,7 +27,7 @@ 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] make postinstall displayName: Install dependencies - script: | diff --git a/Makefile b/Makefile index a7b8f05d1..d29046dcc 100644 --- a/Makefile +++ b/Makefile @@ -21,8 +21,18 @@ 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; } + @profile=$$(python3 -c 'import sys; print("legacy" if sys.version_info < (3, 11) else "modern")') || exit $$?; \ + if [ "$$profile" = legacy ]; then \ + collections="ansible.posix:1.5.4 ansible.utils:2.12.0 community.crypto:2.16.0"; \ + else \ + collections="ansible.posix:2.2.2 ansible.utils:6.1.1 community.crypto:3.5.1"; \ + fi; \ + for attempt in 1 2 3; do \ + timeout 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..423c164d3 100644 --- a/dockerfile/cuda11.1.1.dockerfile +++ b/dockerfile/cuda11.1.1.dockerfile @@ -62,6 +62,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /opt/cmake-3.14.6-Linux-x86_64 +ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \ + ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections +COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt +COPY Makefile /opt/sb-ansible/Makefile +RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \ + make -C /opt/sb-ansible postinstall + ARG NUM_MAKE_JOBS= # Install Docker @@ -168,5 +175,4 @@ ADD . . RUN python3 -m pip install --upgrade setuptools==65.7 importlib_metadata==6.8.0 && \ python3 -m pip install --no-cache-dir .[nvworker] && \ make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/cuda12.9.dockerfile b/dockerfile/cuda12.9.dockerfile index 3c2c92000..2c15347fa 100644 --- a/dockerfile/cuda12.9.dockerfile +++ b/dockerfile/cuda12.9.dockerfile @@ -62,6 +62,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* +ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \ + ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections +COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt +COPY Makefile /opt/sb-ansible/Makefile +RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \ + make -C /opt/sb-ansible postinstall + # Install CMake 3.30.4 for nvbench compatibility RUN apt-get update && \ apt-get remove -y cmake cmake-data && \ @@ -191,5 +198,4 @@ ADD . . RUN python3 -m pip install --upgrade setuptools==78.1.0 && \ python3 -m pip install --no-cache-dir .[nvworker] && \ make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/cuda13.0.dockerfile b/dockerfile/cuda13.0.dockerfile index 520920afa..1f81b6025 100644 --- a/dockerfile/cuda13.0.dockerfile +++ b/dockerfile/cuda13.0.dockerfile @@ -62,6 +62,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* +ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \ + ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections +COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt +COPY Makefile /opt/sb-ansible/Makefile +RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \ + make -C /opt/sb-ansible postinstall + ARG NUM_MAKE_JOBS= ARG TARGETPLATFORM ARG TARGETARCH @@ -158,5 +165,4 @@ ADD . . RUN python3 -m pip install --upgrade setuptools==78.1.0 && \ python3 -m pip install --no-cache-dir .[nvworker] && \ make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/cuda13.4.dockerfile b/dockerfile/cuda13.4.dockerfile index 09d85889c..429ff6e00 100644 --- a/dockerfile/cuda13.4.dockerfile +++ b/dockerfile/cuda13.4.dockerfile @@ -116,6 +116,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* +ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \ + ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections +COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt +COPY Makefile /opt/sb-ansible/Makefile +RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \ + make -C /opt/sb-ansible postinstall + # Number of parallel jobs for the NVBench build. Override with --build-arg NUM_MAKE_JOBS=... ARG NUM_MAKE_JOBS=64 @@ -202,5 +209,4 @@ ADD . . RUN python3 -m pip install --upgrade setuptools==78.1.0 && \ python3 -m pip install --no-cache-dir .[nvworker] && \ make cppbuild && \ - make postinstall && \ rm -rf .git diff --git a/dockerfile/rocm6.3.x.dockerfile b/dockerfile/rocm6.3.x.dockerfile index a03c53bff..8723f1a10 100644 --- a/dockerfile/rocm6.3.x.dockerfile +++ b/dockerfile/rocm6.3.x.dockerfile @@ -66,6 +66,13 @@ RUN apt-get update && \ && \ rm -rf /tmp/* +ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \ + ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections +COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt +COPY Makefile /opt/sb-ansible/Makefile +RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \ + make -C /opt/sb-ansible postinstall + # Install Docker ENV DOCKER_VERSION=27.5.1 RUN cd /tmp && \ @@ -145,5 +152,4 @@ ENV USE_HIP_DATATYPE=1 ENV USE_HIPBLAS_COMPUTETYPE=1 RUN python3 -m pip install --no-build-isolation .[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..5e4e2d9d8 100644 --- a/dockerfile/rocm6.4.x.dockerfile +++ b/dockerfile/rocm6.4.x.dockerfile @@ -66,6 +66,13 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /tmp/* +ENV PIP_CONSTRAINT=/opt/sb-ansible/requirements/ansible.txt \ + ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections +COPY requirements/ansible.txt /opt/sb-ansible/requirements/ansible.txt +COPY Makefile /opt/sb-ansible/Makefile +RUN python3 -m pip install --no-cache-dir -r "$PIP_CONSTRAINT" && \ + make -C /opt/sb-ansible postinstall + ARG NUM_MAKE_JOBS=64 # Check if CMake is installed and its version @@ -247,7 +254,6 @@ ENV USE_HIP_DATATYPE=1 ENV USE_HIPBLAS_COMPUTETYPE=1 RUN python3 -m pip install .[amdworker] && \ CXX=/opt/rocm/bin/hipcc make cppbuild && \ - make postinstall && \ rm -rf .git # Fix stale hypothesis plugin from base image (imports removed pkg_resources) diff --git a/docs/developer-guides/development.md b/docs/developer-guides/development.md index e6b749485..1d32a91b6 100644 --- a/docs/developer-guides/development.md +++ b/docs/developer-guides/development.md @@ -19,9 +19,38 @@ 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](../../requirements/ansible.txt) pins the engine, +runner and Jinja2 for each supported Python family. Other transitive dependencies +remain managed by pip; this is not a complete environment lock. +[Makefile](../../Makefile) pins the three collections, using a legacy set for +Python 3.7-3.10 and a modern set for Python 3.11+. The legacy Ansible 2.10 engine +is end-of-life and remains a compatibility bridge, not a long-term support promise. + +`make postinstall` installs collections with at most three attempts, a +300-second timeout per attempt, and 10- and 20-second waits. Exhaustion fails +the build. Pip retains its own retry handling. + +The main GPU image stage installs these dependencies before copying application +source or building benchmarks; CUDA 13.4's separate STREAM stage is unchanged. +The images reuse normal Docker layer caching and retain `PIP_CONSTRAINT` for +later pip commands. A cold build still needs the network; the existing Build +Image workflow is unchanged. + +To update versions, edit the requirements file and Makefile together. Run +`python3 -m pytest -q tests/runner/test_ansible.py`, the existing Ansible +integration tests, and the affected image builds before merging. Check both +legacy and modern runtimes; local runner tests alone do not qualify GPU images +or remote deployment. + ## Lint and Test Format code using yapf. diff --git a/requirements/ansible.txt b/requirements/ansible.txt new file mode 100644 index 000000000..8a920f18a --- /dev/null +++ b/requirements/ansible.txt @@ -0,0 +1,12 @@ +# 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-core==2.21.6; python_version == "3.12" +ansible-core==2.22.0; python_version >= "3.13" +ansible-runner==2.3.1; python_version < "3.11" +ansible-runner==2.4.3; python_version >= "3.11" +# Ansible 2.10 uses filter imports removed in Jinja2 3.1. +Jinja2==3.0.3; python_version < "3.11" +Jinja2==3.1.6; python_version >= "3.11" diff --git a/setup.py b/setup.py index 114f6590a..4dfb7862d 100644 --- a/setup.py +++ b/setup.py @@ -165,10 +165,12 @@ 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-core>=2.19,<2.20;os_name=="posix" and python_version=="3.11"', + 'ansible-core>=2.21,<2.22;os_name=="posix" and python_version=="3.12"', + 'ansible-core>=2.22,<2.23;os_name=="posix" and python_version>="3.13"', + 'ansible_base>=2.10.17,<2.11;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_runner>=2.4.3,<2.5;python_version>"3.10"', '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..8766ce38a 100644 --- a/tests/runner/test_ansible.py +++ b/tests/runner/test_ansible.py @@ -4,6 +4,8 @@ """SuperBench Ansible Client test.""" import os +import subprocess +import sys import unittest import tempfile from pathlib import Path @@ -15,6 +17,61 @@ AnsibleClient = LazyImport('superbench.runner.ansible', 'AnsibleClient') +class AnsiblePostinstallTestCase(unittest.TestCase): + """Test the shared Makefile entry point without contacting Galaxy.""" + def test_bounded_collection_retries(self): + """Stop on success and propagate exhausted installation failures.""" + for codes in [[0], [1, 0], [1, 1, 0], [17, 17, 17], [124, 124, 124]]: + with self.subTest(codes=codes), tempfile.TemporaryDirectory() as directory: + root = Path(directory) + attempts = root / 'attempts' + waits = root / 'waits' + status_codes = root / 'codes' + status_codes.write_text('\n'.join(map(str, codes)) + '\n') + waits.touch() + scripts = { + 'ansible-galaxy': ( + 'printf "%s\\n" "$*" >> "$INSTALL_ATTEMPTS"\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) + env = dict( + os.environ, + PATH=str(root) + os.pathsep + os.environ['PATH'], + 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, + ) + self.assertEqual(result.returncode == 0, codes[-1] == 0, result.stdout) + commands = attempts.read_text().splitlines() + self.assertEqual(len(commands), len(codes), result.stdout) + self.assertEqual(commands, [commands[0]] * len(codes)) + self.assertRegex( + commands[0], + r'^collection install ansible\.posix:\d+\.\d+\.\d+ ' + r'ansible\.utils:\d+\.\d+\.\d+ community\.crypto:\d+\.\d+\.\d+$', + ) + self.assertEqual(waits.read_text().splitlines(), ['10', '20'][:len(codes) - 1]) + if codes[-1]: + self.assertIn('attempt 3/3 failed (exit {}).'.format(codes[-1]), result.stdout) + + class AnsibleClientTestCase(unittest.TestCase): """A class for ansible client test cases.""" def setUp(self): @@ -158,3 +215,17 @@ def test_get_playbook_config(self): 'playbook': str(self.ansible_client._playbook_path / 'play'), } ) + + 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: + 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'] = { + 'ANSIBLE_LOCAL_TEMP': str(Path(directory) / 'local'), + 'ANSIBLE_REMOTE_TEMP': str(Path(directory) / 'remote'), + } + self.assertEqual(client.run(config), expected) + self.assertEqual(client.failure_count, 1)