Skip to content

add: container test plugin for pytest#17372

Open
realsdx wants to merge 3 commits into
4.0from
sudipta/4.0/add-container-runtime-test-system
Open

add: container test plugin for pytest#17372
realsdx wants to merge 3 commits into
4.0from
sudipta/4.0/add-container-runtime-test-system

Conversation

@realsdx
Copy link
Copy Markdown
Contributor

@realsdx realsdx commented May 20, 2026

Add a pytest based validation framework AzureLinux's OCI container images, integrated with azldev image test

Test it locally by (make sure to install and start podman first):

azldev image build container-base && azldev image test container-base

images with a given capability.
- **Image-specific:** add `cases/<image-family>/test_<topic>.py`. Tests
in such subdirectories are **automatically** restricted to that
- **Image-specific static:** add `cases/static/<image-family>/test_<topic>.py`.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have odd feeling about these directory-based tests discovery, markers might be more useful. As you add more and more tests, directories and subdirectories just for categorization might become too complex.

@pytest.mark.dockerfile()
def test_nginx_config_valid(container_exec) -> None:
"""nginx configuration must pass validation."""
result = container_exec("nginx -t 2>&1")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 2>&1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume agent did this, cause by default nginx -t outputs to stderr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment thread base/images/tests/README.md Outdated
COPY nginx.conf /etc/nginx/nginx.conf
```

Mark tests with `@pytest.mark.dockerfile()` to trigger the build. The
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this!

@realsdx realsdx changed the title [WIP] add: container test plugin for pytest add: container test plugin for pytest May 26, 2026
@realsdx realsdx marked this pull request as ready for review May 26, 2026 08:37
Copilot AI review requested due to automatic review settings May 26, 2026 08:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends Azure Linux’s image-test framework to support runtime validation of OCI container images (in addition to existing static/offline filesystem checks) and wires the new runtime suite into azldev image test.

Changes:

  • Added --image-ref support (mutually exclusive with --image-path) and new pytest markers for runtime/container and Dockerfile-based tests.
  • Introduced a python-on-whales/Podman-based container runtime helper plus session/function fixtures to run podman exec-style tests.
  • Restructured test layout into cases/static/ vs cases/runtime/ and added an images.toml runtime test-suite for container-base variants.

Reviewed changes

Copilot reviewed 10 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
base/images/tests/utils/pytest_plugin.py Adds --image-ref, new markers, and collection-time auto-marking for runtime/static test layout.
base/images/tests/utils/container_runtime.py New Podman/python-on-whales orchestration helpers (load/pull/build/run/exec/cleanup).
base/images/tests/conftest.py Adds runtime container fixtures (podman_client, running_container, container_exec, etc.) and supports --image-ref.
base/images/tests/README.md Updates documentation to reflect static vs runtime suites and new CLI options/fixtures.
base/images/tests/pyproject.toml Adds python-on-whales dependency for runtime container orchestration.
base/images/tests/cases/static/test_os_release.py New shared static validation for /etc/os-release.
base/images/tests/cases/static/test_packages.py New shared static RPM/package presence/absence checks (capability-gated).
base/images/tests/cases/static/vm-base/test_kernel.py Adds VM kernel/modules checks and Fedora 43 CONFIG_LSM assertion.
base/images/tests/cases/static/vm-base/test_partitions.py Adds VM partition layout checks (root + EFI).
base/images/tests/cases/static/container-base/test_container.py Adds container static validation (no kernel modules).
base/images/tests/cases/runtime/container-base/test_basic.py Adds basic runtime exec tests (shell + DNS).
base/images/tests/cases/runtime/container-base/test_nginx/* Adds Dockerfile-based runtime example for nginx validation.
base/images/images.toml Wires runtime-container-tests into container-base images and splits suite test-paths into cases/static/ and cases/runtime/.
Comments suppressed due to low confidence (1)

base/images/tests/utils/pytest_plugin.py:156

  • pytest_configure derives image_type from --image-type, --capabilities, or --image-path, but it doesn’t consider --image-ref. When running with --image-ref and no --capabilities/--image-type, image_type stays None and check_tools(when=None) ends up requiring all tools (VM + container), which breaks the intended registry-ref workflow. Treat --image-ref as implying image_type="container" during this early preflight derivation.
    image_type = config.getoption("--image-type", default=None)
    if image_type is None:
        caps = parse_capabilities(config.getoption("--capabilities", default=None))
        if caps:
            image_type = derive_image_type_from_capabilities(caps)

Comment on lines +14 to +21
from typing import NamedTuple

from python_on_whales import DockerClient
from python_on_whales.components.container.cli_wrapper import Container
from python_on_whales.exceptions import DockerException, NoSuchContainer, NoSuchImage

from .tools import NativeTool

Comment on lines +199 to +203
image_ref,
command=["sleep", "infinity"],
name=container_name,
detach=True,
)
Comment on lines +99 to +103
# Load from archive file.
assert image_path is not None
logger.info("Loading image archive: %s", image_path)
image_refs = client.image.load(image_path)

@@ -0,0 +1,5 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
RUN dnf install -y nginx && dnf clean all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants