Skip to content

Commit

Permalink
Merge pull request #316 from SUSE/kernel-module-container-tests
Browse files Browse the repository at this point in the history
Add simple smoke test building drbd using the kernel-module-container
  • Loading branch information
dirkmueller authored Jan 2, 2024
2 parents 5509c7b + af16403 commit c218d92
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 8 deletions.
22 changes: 16 additions & 6 deletions bci_tester/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def create_BCI(
of the :py:class:`~pytest_container.DerivedContainer`
"""
build_tag_base = build_tag.rpartition("/")[2]
marks = [pytest.mark.__getattr__(build_tag_base.replace(":", "_"))]
marks = []
if extra_marks:
for m in extra_marks:
marks.append(m)
Expand All @@ -293,15 +293,18 @@ def create_BCI(
raise ValueError(
f"Invalid os version for a language or application stack container: {ver}"
)
marks.append(create_container_version_mark(available_versions))
else:
marks.append(
create_container_version_mark(_DEFAULT_NONBASE_OS_VERSIONS)
)
available_versions = list(_DEFAULT_NONBASE_OS_VERSIONS)

elif available_versions is not None:
if available_versions:
marks.append(create_container_version_mark(available_versions))

# only try to grab the mark from the build tag for containers that are
# available for this os version, otherwise we get bogus errors for missing
# marks
if OS_VERSION in (available_versions or []):
marks.append(pytest.mark.__getattr__(build_tag_base.replace(":", "_")))

if OS_VERSION == "tumbleweed":
if bci_type == ImageType.APPLICATION:
baseurl = (
Expand Down Expand Up @@ -608,6 +611,12 @@ def create_BCI(
forwarded_ports=[PortForwarding(container_port=80)],
)

KERNEL_MODULE_CONTAINER = create_BCI(
build_tag=f"{BCI_CONTAINER_PREFIX}/bci-sle15-kernel-module-devel:{OS_CONTAINER_TAG}",
available_versions=["15.5", "15.6"],
bci_type=ImageType.OS,
)

DOTNET_CONTAINERS = [
DOTNET_SDK_6_0_CONTAINER,
DOTNET_SDK_7_0_CONTAINER,
Expand All @@ -627,6 +636,7 @@ def create_BCI(
PHP_8_APACHE,
PHP_8_CLI,
PHP_8_FPM,
KERNEL_MODULE_CONTAINER,
]
+ LTSS_BASE_CONTAINERS
+ LTSS_BASE_FIPS_CONTAINERS
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ markers = [
'rust_oldstable',
'rust_stable',
'tumbleweed_latest',
'bci-sle15-kernel-module-devel_15.5',
'bci-sle15-kernel-module-devel_15.6',
]

[tool.black]
Expand Down
15 changes: 14 additions & 1 deletion tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from bci_tester.data import CONTAINERS_WITH_ZYPPER
from bci_tester.data import DISTRIBUTION_CONTAINER
from bci_tester.data import INIT_CONTAINER
from bci_tester.data import KERNEL_MODULE_CONTAINER
from bci_tester.data import OS_PRETTY_NAME
from bci_tester.data import OS_VERSION
from bci_tester.data import OS_VERSION_ID
Expand Down Expand Up @@ -291,7 +292,19 @@ def test_zypper_verify_passes(container_per_test: ContainerData) -> None:
[
c
for c in ALL_CONTAINERS
if (c not in [INIT_CONTAINER, PCP_CONTAINER] + POSTGRESQL_CONTAINERS)
if (
c
not in (
[
INIT_CONTAINER,
PCP_CONTAINER,
# kernel-module-container contains systemd due to pesign,
# fixes are pending
KERNEL_MODULE_CONTAINER,
]
+ POSTGRESQL_CONTAINERS
)
)
],
indirect=True,
)
Expand Down
59 changes: 59 additions & 0 deletions tests/test_kernel_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Tests for the SLE15 kernel-module container."""
import pytest
from pytest_container import container_from_pytest_param
from pytest_container import DerivedContainer
from pytest_container.container import ContainerData

from bci_tester.data import KERNEL_MODULE_CONTAINER
from bci_tester.data import OS_VERSION

pytestmark = pytest.mark.skipif(
OS_VERSION in ("tumbleweed", "basalt"),
reason="no kernel-module containers for Tumbleweed and Basalt",
)

_DRBD_VERSION = "9.2.5"


DRBD_CONTAINER = DerivedContainer(
base=container_from_pytest_param(KERNEL_MODULE_CONTAINER),
containerfile=rf"""WORKDIR /src/
RUN zypper -n in coccinelle tar
RUN set -euxo pipefail; \
curl -Lsf -o - https://pkg.linbit.com//downloads/drbd/9/drbd-{_DRBD_VERSION}.tar.gz | tar xzf - ; \
cd drbd-{_DRBD_VERSION}; \
make -C /usr/src/linux-obj/$(uname -m)/default modules M="$(pwd)/drbd" SPAAS=false
""",
)


_DPDK_VERSION = "23.07"

DPDK_CONTAINER = DerivedContainer(
base=container_from_pytest_param(KERNEL_MODULE_CONTAINER),
containerfile=rf"""WORKDIR /src/
RUN zypper -n in meson python3-pip libnuma-devel && pip install pyelftools
RUN set -euxo pipefail; \
curl -Lsf -o - https://fast.dpdk.org/rel/dpdk-{_DPDK_VERSION}.tar.gz | tar xzf - ; cd dpdk-{_DPDK_VERSION}; \
meson --prefix=/usr --includedir=/usr/include/ -Ddefault_library=shared -Denable_docs=false -Db_lto=false -Dplatform="$(uname -m)" -Dcpu_instruction_set=generic -Denable_kmods=true -Dkernel_dir="/usr/src/linux-obj/$(uname -m)/default" build; \
meson compile -C build
""",
)


@pytest.mark.parametrize("container", [DRBD_CONTAINER], indirect=True)
def test_drbd_builds(container: ContainerData) -> None:
"""Test that the DRBD kernel module builds."""
assert container.connection.file(
f"/src/drbd-{_DRBD_VERSION}/drbd/drbd.ko"
).exists


@pytest.mark.parametrize("container", [DPDK_CONTAINER], indirect=True)
def test_dpdk_builds(container: ContainerData) -> None:
"""Test that the DPDK kernel module builds."""
assert container.connection.file(
f"/src/dpdk-{_DPDK_VERSION}/build/kernel/linux/kni/rte_kni.ko"
).exists
2 changes: 2 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from bci_tester.data import HELM_CONTAINER
from bci_tester.data import ImageType
from bci_tester.data import INIT_CONTAINER
from bci_tester.data import KERNEL_MODULE_CONTAINER
from bci_tester.data import L3_CONTAINERS
from bci_tester.data import LTSS_BASE_CONTAINERS
from bci_tester.data import LTSS_BASE_FIPS_CONTAINERS
Expand Down Expand Up @@ -110,6 +111,7 @@ def _get_container_label_prefix(
(MINIMAL_CONTAINER, "minimal", ImageType.OS),
(MICRO_CONTAINER, "micro", ImageType.OS),
(BUSYBOX_CONTAINER, "busybox", ImageType.OS),
(KERNEL_MODULE_CONTAINER, "sle15-kernel-module-devel", ImageType.OS),
(OPENJDK_11_CONTAINER, "openjdk", ImageType.LANGUAGE_STACK),
(
OPENJDK_DEVEL_11_CONTAINER,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = {py36,py39,py310,py311,py312}-unit, build, all, base, fips, init, dotnet, python, ruby, node, go, openjdk, openjdk_devel, rust, php, busybox, 389ds, metadata, minimal, multistage, repository, doc, lint, get_urls, pcp, distribution, postgres, git, helm, nginx
envlist = {py36,py39,py310,py311,py312}-unit, build, all, base, fips, init, dotnet, python, ruby, node, go, openjdk, openjdk_devel, rust, php, busybox, 389ds, metadata, minimal, multistage, repository, doc, lint, get_urls, pcp, distribution, postgres, git, helm, nginx, kernel_module
isolated_build = True
skip_missing_interpreters = True

Expand Down

0 comments on commit c218d92

Please sign in to comment.