Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for ansible-builder #377

Merged
merged 15 commits into from
Sep 20, 2024
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ endgroup
gunicorn
libera
microdnf
mknod
modifyitems
netcommon
pkgmgr
Expand Down
9 changes: 1 addition & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
"image": "ghcr.io/ansible/community-ansible-dev-tools:latest",
"containerUser": "root",
"runArgs": [
"--security-opt",
"seccomp=unconfined",
"--security-opt",
"label=disable",
"--cap-add=SYS_ADMIN",
"--cap-add=SYS_RESOURCE",
"--privileged",
"--device",
"/dev/fuse",
"--security-opt",
"apparmor=unconfined",
"--hostname=ansible-dev-container"
],
"updateRemoteUserUID": true,
Expand Down
9 changes: 1 addition & 8 deletions .devcontainer/docker/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
"image": "ghcr.io/ansible/community-ansible-dev-tools:latest",
"containerUser": "root",
"runArgs": [
"--security-opt",
"seccomp=unconfined",
"--security-opt",
"label=disable",
"--cap-add=SYS_ADMIN",
"--cap-add=SYS_RESOURCE",
"--privileged",
"--device",
"/dev/fuse",
"--security-opt",
"apparmor=unconfined",
"--hostname=ansible-dev-container"
],
"updateRemoteUserUID": true,
Expand Down
4 changes: 4 additions & 0 deletions .devcontainer/podman/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"image": "ghcr.io/ansible/community-ansible-dev-tools:latest",
"containerUser": "root",
"runArgs": [
"--cap-add=CAP_MKNOD",
"--cap-add=NET_ADMIN",
"--cap-add=SYS_ADMIN",
"--cap-add=SYS_RESOURCE",
"--device",
Expand All @@ -13,6 +15,8 @@
"label=disable",
"--security-opt",
"apparmor=unconfined",
"--security-opt",
"unmask=/sys/fs/cgroup",
"--userns=host",
"--hostname=ansible-dev-container"
],
Expand Down
17 changes: 11 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def server_in_container_url() -> str:
Returns:
str: The server URL.
"""
return "http://localhost:8001"
return "http://0.0.0.0:8001"


def pytest_sessionstart(session: pytest.Session) -> None:
Expand Down Expand Up @@ -245,24 +245,28 @@ def pytest_sessionfinish(session: pytest.Session) -> None:


BASE_CMD = """{container_engine} run -d --rm
--cap-add=SYS_ADMIN
--cap-add=SYS_RESOURCE
--device "/dev/fuse"
-e NO_COLOR=1
--hostname=ansible-dev-container
--name={container_name}
-p 8001:8001
--security-opt "apparmor=unconfined"
--security-opt "label=disable"
--security-opt "seccomp=unconfined"
-v $PWD:/workdir
"""

PODMAN_CMD = """ --user=root
--cap-add=CAP_MKNOD
--cap-add=NET_ADMIN
--cap-add=SYS_ADMIN
--cap-add=SYS_RESOURCE
--security-opt "apparmor=unconfined"
--security-opt "label=disable"
--security-opt "seccomp=unconfined"
--security-opt=unmask=/sys/fs/cgroup
--userns=host
"""

DOCKER_CMD = """ --user=root
--privileged
"""

END = """ {image_name}
Expand Down Expand Up @@ -307,6 +311,7 @@ def _start_container() -> None:
container_name=INFRASTRUCTURE.container_name,
image_name=INFRASTRUCTURE.image_name,
)
warnings.warn("Running: " + cmd, stacklevel=0)
try:
subprocess.run(cmd, check=True, capture_output=True, shell=True, text=True)
except subprocess.CalledProcessError as exc:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
version: 3

images:
base_image:
name: quay.io/fedora/fedora-minimal:40

dependencies:
ansible_runner:
package_pip: ansible-runner

ansible_core:
package_pip: ansible-core

options:
package_manager_path: /usr/bin/microdnf

additional_build_steps:
prepend_base:
- RUN $PKGMGR -y install python3-devel
18 changes: 18 additions & 0 deletions tests/integration/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,21 @@ def test_nav_collection(container_tmux: ContainerTmux, tmp_path: Path) -> None:
)
stdout = container_tmux.send_and_wait(cmd=cmd, wait_for=":help help", timeout=10)
assert any(f"{namespace}.{name}" in line for line in stdout)


@pytest.mark.container()
def test_builder(
exec_container: Callable[[str], subprocess.CompletedProcess[str]],
test_fixture_dir_container: Path,
tmp_path: Path,
) -> None:
"""Test building an execution environment with ansible-builder.
Args:
exec_container: The container executor.
test_fixture_dir_container: The test fixture directory.
tmp_path: The temporary directory.
"""
ee_file = test_fixture_dir_container / "execution-environment.yml"
result = exec_container(f"ansible-builder build -f {ee_file} -c {tmp_path}")
assert "Complete!" in result.stdout
Loading