Skip to content

Commit 2615334

Browse files
authored
Fix container-in-container testing (#505)
1 parent e1cc77d commit 2615334

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ repos:
3232
- id: end-of-file-fixer
3333
- id: trailing-whitespace
3434

35-
- repo: https://github.com/asottile/add-trailing-comma.git
36-
rev: v3.1.0
37-
hooks:
38-
- id: add-trailing-comma
39-
args:
40-
- --py36-plus
41-
4235
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
4336
rev: v1.5.5
4437
hooks:
@@ -100,7 +93,7 @@ repos:
10093
hooks:
10194
- id: pydoclint
10295
# This allows automatic reduction of the baseline file when needed.
103-
entry: sh -ec "pydoclint . && pydoclint --generate-baseline=1 ."
96+
entry: sh -ec "pydoclint -q . && pydoclint --generate-baseline=1 ."
10497
pass_filenames: false
10598

10699
- repo: https://github.com/pycqa/pylint.git

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ external = [
347347
]
348348
ignore = [
349349
"COM812", # conflicts with ISC001 on format
350+
"E501", # line-too-long / rely on black
350351
"ISC001" # conflicts with COM812 on format
351352
]
352353
select = ["ALL"]

tests/conftest.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import pty
2626
import re
2727
import select
28+
import shlex
2829
import shutil
2930
import subprocess
3031
import sys
@@ -310,10 +311,14 @@ def _start_container() -> None:
310311
err = f"Container engine {INFRASTRUCTURE.container_engine} not found."
311312
raise ValueError(err)
312313

313-
cmd = cmd.replace("\n", " ").format(
314-
container_engine=INFRASTRUCTURE.container_engine,
315-
container_name=INFRASTRUCTURE.container_name,
316-
image_name=INFRASTRUCTURE.image_name,
314+
cmd = (
315+
cmd.replace("\n", " ")
316+
.format(
317+
container_engine=INFRASTRUCTURE.container_engine,
318+
container_name=INFRASTRUCTURE.container_name,
319+
image_name=INFRASTRUCTURE.image_name,
320+
)
321+
.replace(" ", " ")
317322
)
318323
LOGGER.warning("Running: %s", cmd)
319324
try:
@@ -395,9 +400,16 @@ def _exec_container(command: str) -> subprocess.CompletedProcess[str]:
395400
Returns:
396401
subprocess.CompletedProcess: The completed process.
397402
"""
398-
cmd = (
399-
f"{INFRASTRUCTURE.container_engine} exec -t"
400-
f" {INFRASTRUCTURE.container_name} bash -c '{command}'"
403+
cmd = shlex.join(
404+
[
405+
INFRASTRUCTURE.container_engine,
406+
"exec",
407+
"-t",
408+
INFRASTRUCTURE.container_name,
409+
"bash",
410+
"-c",
411+
command,
412+
]
401413
)
402414
result = subprocess.run(
403415
cmd,

tests/integration/test_container.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""Run tests against the container."""
22

3+
# cspell: ignore cinc
34
from __future__ import annotations
45

6+
import shlex
7+
58
from typing import TYPE_CHECKING
69

710
import pytest
@@ -48,24 +51,41 @@ def test_podman(exec_container: Callable[[str], subprocess.CompletedProcess[str]
4851

4952

5053
@pytest.mark.container
51-
def test_container_in_container(
54+
def test_cinc(
55+
infrastructure: Infrastructure,
5256
exec_container: Callable[[str], subprocess.CompletedProcess[str]],
5357
) -> None:
5458
"""Test podman container-in-container functionality for plugin copy.
5559
5660
Args:
61+
infrastructure: The testing infrastructure.
5762
exec_container: The container executor.
5863
"""
64+
# We do not want to accidentally pull here because we expected to load
65+
# the tar image into the container. Our scope is to test the image we did
66+
# not publish yet to any registry.
5967
podman_run_container = exec_container(
60-
"podman run -i --rm -d -e ANSIBLE_DEV_TOOLS_CONTAINER=1"
61-
" -e ANSIBLE_FORCE_COLOR=0 --name ghcr_io_ansible_community_ansible_dev_tools_latest"
62-
" ghcr.io/ansible/community-ansible-dev-tools:latest bash",
68+
"podman run --pull=never -i --rm -d -e ANSIBLE_DEV_TOOLS_CONTAINER=1"
69+
" -e ANSIBLE_FORCE_COLOR=0 --name test_cinc"
70+
f" {infrastructure.image_name} bash",
6371
)
6472
assert podman_run_container.returncode == 0
6573

6674
test_path_access = exec_container(
67-
"podman exec ghcr_io_ansible_community_ansible_dev_tools_latest"
68-
" ls /usr/local/lib/python3.12/site-packages/ansible/plugins/",
75+
shlex.join(
76+
[
77+
"podman",
78+
"exec",
79+
"test_cinc",
80+
"python3",
81+
"-c",
82+
(
83+
"import pathlib, sys; sys.exit(0 if"
84+
" pathlib.Path(f'/usr/local/lib/python{sys.version_info[0]}.{sys.version_info[1]}/site-packages/ansible/plugins/').exists()"
85+
" else 1);"
86+
),
87+
],
88+
),
6989
)
7090
assert "OCI permission denied" not in test_path_access.stdout
7191
assert test_path_access.returncode == 0

0 commit comments

Comments
 (0)