Skip to content

Commit

Permalink
test/test_build: test local container builds
Browse files Browse the repository at this point in the history
Add an integration tests for the local storage implementation. The
test creates a local container and then mounts the local container
store to podman as well as passing the `--local` flag.
  • Loading branch information
kingsleyzissou committed Mar 11, 2024
1 parent 20df10d commit 300908a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
35 changes: 29 additions & 6 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import os
import pathlib
import platform
import random
import re
import shutil
import subprocess
import string
import tempfile
import uuid
from contextlib import contextmanager
Expand Down Expand Up @@ -45,14 +47,19 @@ class ImageBuildResult(NamedTuple):
def parse_request_params(request):
# image_type is passed via special pytest parameter fixture
testcase_ref = request.param
if testcase_ref.count(",") == 2:
if testcase_ref.count(",") == 3:
container_ref, images, target_arch, local = testcase_ref.split(",")
local = local is not None
if testcase_ref.count(",") == 2:
container_ref, images, target_arch = testcase_ref.split(",")
local = False
elif testcase_ref.count(",") == 1:
container_ref, images = testcase_ref.split(",")
target_arch = None
local = False
else:
raise ValueError(f"cannot parse {testcase_ref.count}")
return container_ref, images, target_arch
return container_ref, images, target_arch, local


@pytest.fixture(scope='session')
Expand All @@ -66,9 +73,25 @@ def image_type_fixture(shared_tmpdir, build_container, request, force_aws_upload
"""
Build an image inside the passed build_container and return an
ImageBuildResult with the resulting image path and user/password
In the case an image is being built from a local container, the
function will build the required local container for the test.
"""
with build_images(shared_tmpdir, build_container, request, force_aws_upload) as build_results:
yield build_results[0]
container_ref, images, target_arch, local = parse_request_params(request)

if not local:
with build_images(shared_tmpdir, build_container, request, force_aws_upload) as build_results:
yield build_results[0]
else:
cont_tag = "localhost/cont-base-" + "".join(random.choices(string.digits, k=12))

# we are not cross-building local images (for now)
request.param = ",".join([cont_tag, images, "", "true"])

with testutil.make_container(shared_tmpdir, cont_tag, {
"file1": "file1 content"
}, base=container_ref):
with build_images(shared_tmpdir, build_container, request, force_aws_upload) as build_results:
yield build_results[0]


@pytest.fixture(name="images", scope="session")
Expand All @@ -89,9 +112,9 @@ def build_images(shared_tmpdir, build_container, request, force_aws_upload):
Will return cached results of previous build requests.
:request.parm: has the form "container_url,img_type1+img_type2,arch"
:request.param: has the form "container_url,img_type1+img_type2,arch,local"
"""
container_ref, images, target_arch = parse_request_params(request)
container_ref, images, target_arch, local = parse_request_params(request)

# images might be multiple --type args
# split and check each one
Expand Down
3 changes: 3 additions & 0 deletions test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ def gen_testcases(what):
CONTAINERS_TO_TEST["fedora"] + "," + DIRECT_BOOT_IMAGE_TYPES[2],
CONTAINERS_TO_TEST["centos"] + "," + DIRECT_BOOT_IMAGE_TYPES[2],
CONTAINERS_TO_TEST["fedora"] + "," + DIRECT_BOOT_IMAGE_TYPES[0],
CONTAINERS_TO_TEST["centos"] + "," + DIRECT_BOOT_IMAGE_TYPES[0] + ",,true",
CONTAINERS_TO_TEST["fedora"] + "," + DIRECT_BOOT_IMAGE_TYPES[2] + ",,true",
]
# do a cross arch test too
if platform.machine() == "x86_64":
print()
# todo: add fedora:eln
test_cases.append(
f'{CONTAINERS_TO_TEST["centos"]},raw,arm64')
Expand Down

0 comments on commit 300908a

Please sign in to comment.