Skip to content

Commit b7825c9

Browse files
cidrblockBrad Thornton
andauthored
Add test for ansible-builder (#377)
Change the server in container url to 0.0.0.0, which should be safer long-term and resolve some odd errors found with podman related to pasta. Log the container run command for easier troubleshooting locally outside the test suite. Add an execution environment build test Note the failure in this test run: opening file /sys/fs/cgroup/cgroup.subtree_control for writing: Read-only file system https://github.com/ansible/ansible-dev-tools/actions/runs/10930266208/job/30342982168?pr=377 This is why unmask=/sys/fs/cgroup is added after the initial addition of the EE test which works for podman. For docker based on: moby/moby#42275 (comment) --privileged was added (not ideal, but few options) On macOS/intel/podman desktop the following errors were found: Error: crun: mknod /dev/null: Operation not permitted: OCI permission denied the following was added to resolve this error: --cap-add=mknod (docker gets this by default) this allowed all tests to pass on macOS/intel/podman desktop 277.32s call tests/integration/test_container.py::test_builder 6.21s call tests/integration/test_container.py::test_nav_playbook 4.99s call tests/integration/test_container.py::test_nav_collections 3.56s call tests/integration/test_container.py::test_navigator_simple_c_in_c 3.18s call tests/integration/test_container.py::test_nav_collection 2.77s call tests/integration/test_container.py::test_navigator_simple 2.58s call tests/integration/test_container.py::test_podman 1.23s call tests/integration/test_container.py::test_nav_images 1.15s setup tests/integration/test_container.py::test_nav_collections 0.78s setup tests/integration/test_container.py::test_nav_playbook ======================================= 34 passed, 1 warning in 310.65s (0:05:10) ======================================= Additional changes necessary for Windows user include the addition of "--cap-add=NET_ADMIN", to avoid bpf query: Operation failed errors when building an EE --------- Co-authored-by: Brad Thornton <[email protected]>
1 parent be6cb74 commit b7825c9

File tree

7 files changed

+56
-22
lines changed

7 files changed

+56
-22
lines changed

.config/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ endgroup
1818
gunicorn
1919
libera
2020
microdnf
21+
mknod
2122
modifyitems
2223
netcommon
2324
pkgmgr

.devcontainer/devcontainer.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33
"image": "ghcr.io/ansible/community-ansible-dev-tools:latest",
44
"containerUser": "root",
55
"runArgs": [
6-
"--security-opt",
7-
"seccomp=unconfined",
8-
"--security-opt",
9-
"label=disable",
10-
"--cap-add=SYS_ADMIN",
11-
"--cap-add=SYS_RESOURCE",
6+
"--privileged",
127
"--device",
138
"/dev/fuse",
14-
"--security-opt",
15-
"apparmor=unconfined",
169
"--hostname=ansible-dev-container"
1710
],
1811
"updateRemoteUserUID": true,

.devcontainer/docker/devcontainer.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33
"image": "ghcr.io/ansible/community-ansible-dev-tools:latest",
44
"containerUser": "root",
55
"runArgs": [
6-
"--security-opt",
7-
"seccomp=unconfined",
8-
"--security-opt",
9-
"label=disable",
10-
"--cap-add=SYS_ADMIN",
11-
"--cap-add=SYS_RESOURCE",
6+
"--privileged",
127
"--device",
138
"/dev/fuse",
14-
"--security-opt",
15-
"apparmor=unconfined",
169
"--hostname=ansible-dev-container"
1710
],
1811
"updateRemoteUserUID": true,

.devcontainer/podman/devcontainer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"image": "ghcr.io/ansible/community-ansible-dev-tools:latest",
44
"containerUser": "root",
55
"runArgs": [
6+
"--cap-add=CAP_MKNOD",
7+
"--cap-add=NET_ADMIN",
68
"--cap-add=SYS_ADMIN",
79
"--cap-add=SYS_RESOURCE",
810
"--device",
@@ -13,6 +15,8 @@
1315
"label=disable",
1416
"--security-opt",
1517
"apparmor=unconfined",
18+
"--security-opt",
19+
"unmask=/sys/fs/cgroup",
1620
"--userns=host",
1721
"--hostname=ansible-dev-container"
1822
],

tests/conftest.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def server_in_container_url() -> str:
202202
Returns:
203203
str: The server URL.
204204
"""
205-
return "http://localhost:8001"
205+
return "http://0.0.0.0:8001"
206206

207207

208208
def pytest_sessionstart(session: pytest.Session) -> None:
@@ -245,24 +245,28 @@ def pytest_sessionfinish(session: pytest.Session) -> None:
245245

246246

247247
BASE_CMD = """{container_engine} run -d --rm
248-
--cap-add=SYS_ADMIN
249-
--cap-add=SYS_RESOURCE
250248
--device "/dev/fuse"
251249
-e NO_COLOR=1
252250
--hostname=ansible-dev-container
253251
--name={container_name}
254252
-p 8001:8001
255-
--security-opt "apparmor=unconfined"
256-
--security-opt "label=disable"
257-
--security-opt "seccomp=unconfined"
258253
-v $PWD:/workdir
259254
"""
260255

261256
PODMAN_CMD = """ --user=root
257+
--cap-add=CAP_MKNOD
258+
--cap-add=NET_ADMIN
259+
--cap-add=SYS_ADMIN
260+
--cap-add=SYS_RESOURCE
261+
--security-opt "apparmor=unconfined"
262+
--security-opt "label=disable"
263+
--security-opt "seccomp=unconfined"
264+
--security-opt=unmask=/sys/fs/cgroup
262265
--userns=host
263266
"""
264267

265268
DOCKER_CMD = """ --user=root
269+
--privileged
266270
"""
267271

268272
END = """ {image_name}
@@ -307,6 +311,7 @@ def _start_container() -> None:
307311
container_name=INFRASTRUCTURE.container_name,
308312
image_name=INFRASTRUCTURE.image_name,
309313
)
314+
warnings.warn("Running: " + cmd, stacklevel=0)
310315
try:
311316
subprocess.run(cmd, check=True, capture_output=True, shell=True, text=True)
312317
except subprocess.CalledProcessError as exc:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
version: 3
3+
4+
images:
5+
base_image:
6+
name: quay.io/fedora/fedora-minimal:40
7+
8+
dependencies:
9+
ansible_runner:
10+
package_pip: ansible-runner
11+
12+
ansible_core:
13+
package_pip: ansible-core
14+
15+
options:
16+
package_manager_path: /usr/bin/microdnf
17+
18+
additional_build_steps:
19+
prepend_base:
20+
- RUN $PKGMGR -y install python3-devel

tests/integration/test_container.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,21 @@ def test_nav_collection(container_tmux: ContainerTmux, tmp_path: Path) -> None:
279279
)
280280
stdout = container_tmux.send_and_wait(cmd=cmd, wait_for=":help help", timeout=10)
281281
assert any(f"{namespace}.{name}" in line for line in stdout)
282+
283+
284+
@pytest.mark.container()
285+
def test_builder(
286+
exec_container: Callable[[str], subprocess.CompletedProcess[str]],
287+
test_fixture_dir_container: Path,
288+
tmp_path: Path,
289+
) -> None:
290+
"""Test building an execution environment with ansible-builder.
291+
292+
Args:
293+
exec_container: The container executor.
294+
test_fixture_dir_container: The test fixture directory.
295+
tmp_path: The temporary directory.
296+
"""
297+
ee_file = test_fixture_dir_container / "execution-environment.yml"
298+
result = exec_container(f"ansible-builder build -f {ee_file} -c {tmp_path}")
299+
assert "Complete!" in result.stdout

0 commit comments

Comments
 (0)