diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5a11625..f3ad691 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,13 +32,6 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/asottile/add-trailing-comma.git - rev: v3.1.0 - hooks: - - id: add-trailing-comma - args: - - --py36-plus - - repo: https://github.com/Lucas-C/pre-commit-hooks.git rev: v1.5.5 hooks: @@ -100,7 +93,7 @@ repos: hooks: - id: pydoclint # This allows automatic reduction of the baseline file when needed. - entry: sh -ec "pydoclint . && pydoclint --generate-baseline=1 ." + entry: sh -ec "pydoclint -q . && pydoclint --generate-baseline=1 ." pass_filenames: false - repo: https://github.com/pycqa/pylint.git diff --git a/pyproject.toml b/pyproject.toml index e952939..8a865a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -347,6 +347,7 @@ external = [ ] ignore = [ "COM812", # conflicts with ISC001 on format + "E501", # line-too-long / rely on black "ISC001" # conflicts with COM812 on format ] select = ["ALL"] diff --git a/tests/conftest.py b/tests/conftest.py index 008fe43..2e41700 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -25,6 +25,7 @@ import pty import re import select +import shlex import shutil import subprocess import sys @@ -310,10 +311,14 @@ def _start_container() -> None: err = f"Container engine {INFRASTRUCTURE.container_engine} not found." raise ValueError(err) - cmd = cmd.replace("\n", " ").format( - container_engine=INFRASTRUCTURE.container_engine, - container_name=INFRASTRUCTURE.container_name, - image_name=INFRASTRUCTURE.image_name, + cmd = ( + cmd.replace("\n", " ") + .format( + container_engine=INFRASTRUCTURE.container_engine, + container_name=INFRASTRUCTURE.container_name, + image_name=INFRASTRUCTURE.image_name, + ) + .replace(" ", " ") ) LOGGER.warning("Running: %s", cmd) try: @@ -395,9 +400,16 @@ def _exec_container(command: str) -> subprocess.CompletedProcess[str]: Returns: subprocess.CompletedProcess: The completed process. """ - cmd = ( - f"{INFRASTRUCTURE.container_engine} exec -t" - f" {INFRASTRUCTURE.container_name} bash -c '{command}'" + cmd = shlex.join( + [ + INFRASTRUCTURE.container_engine, + "exec", + "-t", + INFRASTRUCTURE.container_name, + "bash", + "-c", + command, + ] ) result = subprocess.run( cmd, diff --git a/tests/integration/test_container.py b/tests/integration/test_container.py index b3e5510..8a5aa51 100644 --- a/tests/integration/test_container.py +++ b/tests/integration/test_container.py @@ -1,7 +1,10 @@ """Run tests against the container.""" +# cspell: ignore cinc from __future__ import annotations +import shlex + from typing import TYPE_CHECKING import pytest @@ -48,24 +51,41 @@ def test_podman(exec_container: Callable[[str], subprocess.CompletedProcess[str] @pytest.mark.container -def test_container_in_container( +def test_cinc( + infrastructure: Infrastructure, exec_container: Callable[[str], subprocess.CompletedProcess[str]], ) -> None: """Test podman container-in-container functionality for plugin copy. Args: + infrastructure: The testing infrastructure. exec_container: The container executor. """ + # We do not want to accidentally pull here because we expected to load + # the tar image into the container. Our scope is to test the image we did + # not publish yet to any registry. podman_run_container = exec_container( - "podman run -i --rm -d -e ANSIBLE_DEV_TOOLS_CONTAINER=1" - " -e ANSIBLE_FORCE_COLOR=0 --name ghcr_io_ansible_community_ansible_dev_tools_latest" - " ghcr.io/ansible/community-ansible-dev-tools:latest bash", + "podman run --pull=never -i --rm -d -e ANSIBLE_DEV_TOOLS_CONTAINER=1" + " -e ANSIBLE_FORCE_COLOR=0 --name test_cinc" + f" {infrastructure.image_name} bash", ) assert podman_run_container.returncode == 0 test_path_access = exec_container( - "podman exec ghcr_io_ansible_community_ansible_dev_tools_latest" - " ls /usr/local/lib/python3.12/site-packages/ansible/plugins/", + shlex.join( + [ + "podman", + "exec", + "test_cinc", + "python3", + "-c", + ( + "import pathlib, sys; sys.exit(0 if" + " pathlib.Path(f'/usr/local/lib/python{sys.version_info[0]}.{sys.version_info[1]}/site-packages/ansible/plugins/').exists()" + " else 1);" + ), + ], + ), ) assert "OCI permission denied" not in test_path_access.stdout assert test_path_access.returncode == 0