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

main: enable containers-storage (HMS-3235) #120

Merged
merged 7 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 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):
kingsleyzissou marked this conversation as resolved.
Show resolved Hide resolved
# 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')
Expand All @@ -66,9 +73,29 @@ 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:
kingsleyzissou marked this conversation as resolved.
Show resolved Hide resolved
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"])

# copy the container into containers-storage
subprocess.check_call([
"skopeo", "copy",
f"docker://{container_ref}",
f"containers-storage:[overlay@/var/lib/containers/storage+/run/containers/storage]{cont_tag}"
])

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 +116,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
2 changes: 2 additions & 0 deletions test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Loading