From ff1da8718174a82f23e07c2766efb8ca3bf01610 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Mon, 11 Mar 2024 15:53:05 +0000 Subject: [PATCH] test/test_build: test local container builds 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. --- test/test_build.py | 35 +++++++++++++++++++++++++++++------ test/testcases.py | 2 ++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/test/test_build.py b/test/test_build.py index b066f0924..7b3554dd8 100644 --- a/test/test_build.py +++ b/test/test_build.py @@ -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 @@ -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 + elif 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') @@ -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") @@ -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 diff --git a/test/testcases.py b/test/testcases.py index 86869805b..923c716d7 100644 --- a/test/testcases.py +++ b/test/testcases.py @@ -45,6 +45,8 @@ 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":