Skip to content

Commit

Permalink
tests: update all tests to pull the container
Browse files Browse the repository at this point in the history
This commit ensures all tests pull the container into local
storage before.
  • Loading branch information
ondrejbudai authored and achilleas-k committed Jan 30, 2025
1 parent 9099ac0 commit 4f86598
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
5 changes: 4 additions & 1 deletion test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ def build_images(shared_tmpdir, build_container, request, force_aws_upload, gpg_
]
cmd.extend(signed_image_args)

# Pull the signed image
testutil.pull_container(container_ref, tls_verify=False)

cmd.extend([
*creds_args,
build_container,
Expand All @@ -424,8 +427,8 @@ def build_images(shared_tmpdir, build_container, request, force_aws_upload, gpg_
*upload_args,
*target_arch_args,
*tc.bib_rootfs_args(),
"--tls-verify=false" if tc.sign else "--tls-verify=true",
f"--use-librepo={tc.use_librepo}",
*tc.bib_rootfs_args()
])

# print the build command for easier tracing
Expand Down
17 changes: 14 additions & 3 deletions test/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import textwrap

import pytest
import testutil

import testutil
from containerbuild import build_container_fixture # pylint: disable=unused-import
from containerbuild import make_container
from testcases import gen_testcases
Expand Down Expand Up @@ -69,6 +69,8 @@ def test_iso_manifest_smoke(build_container, tc):

@pytest.mark.parametrize("tc", gen_testcases("manifest"))
def test_manifest_disksize(tmp_path, build_container, tc):
testutil.pull_container(tc.container_ref, tc.target_arch)

# create derrived container with 6G silly file to ensure that
# bib doubles the size to 12G+
cntf_path = tmp_path / "Containerfile"
Expand Down Expand Up @@ -114,6 +116,8 @@ def test_manifest_local_checks_containers_storage_errors(build_container):

@pytest.mark.parametrize("tc", gen_testcases("manifest"))
def test_manifest_local_checks_containers_storage_works(tmp_path, build_container, tc):
testutil.pull_container(tc.container_ref, tc.target_arch)

cntf_path = tmp_path / "Containerfile"
cntf_path.write_text(textwrap.dedent(f"""\n
FROM {tc.container_ref}
Expand Down Expand Up @@ -360,6 +364,8 @@ def find_image_anaconda_stage(manifest_str):

@pytest.mark.parametrize("tc", gen_testcases("anaconda-iso"))
def test_manifest_anaconda_module_customizations(tmpdir_factory, build_container, tc):
testutil.pull_container(tc.container_ref, tc.target_arch)

cfg = {
"customizations": {
"installer": {
Expand All @@ -384,8 +390,6 @@ def test_manifest_anaconda_module_customizations(tmpdir_factory, build_container
config_json_path = output_path / "config.json"
config_json_path.write_text(json.dumps(cfg), encoding="utf-8")

testutil.pull_container(tc.container_ref, tc.target_arch)

output = subprocess.check_output([
*testutil.podman_run_common,
"-v", f"{output_path}:/output",
Expand Down Expand Up @@ -548,6 +552,7 @@ def find_grub2_iso_stage_from(manifest_str):

def test_manifest_fips_customization(tmp_path, build_container):
container_ref = "quay.io/centos-bootc/centos-bootc:stream9"
testutil.pull_container(container_ref)

config = {
"customizations": {
Expand Down Expand Up @@ -582,6 +587,7 @@ def find_bootc_install_to_fs_stage_from(manifest_str):

def test_manifest_disk_customization_lvm(tmp_path, build_container):
container_ref = "quay.io/centos-bootc/centos-bootc:stream9"
testutil.pull_container(container_ref)

config = {
"customizations": {
Expand All @@ -606,6 +612,7 @@ def test_manifest_disk_customization_lvm(tmp_path, build_container):
with config_path.open("w") as config_file:
json.dump(config, config_file)

testutil.pull_container(container_ref)
output = subprocess.check_output([
*testutil.podman_run_common,
"-v", f"{config_path}:/config.json:ro",
Expand Down Expand Up @@ -641,6 +648,7 @@ def test_manifest_disk_customization_btrfs(tmp_path, build_container):
with config_path.open("w") as config_file:
json.dump(config, config_file)

testutil.pull_container(container_ref)
output = subprocess.check_output([
*testutil.podman_run_common,
"-v", f"{config_path}:/config.json:ro",
Expand Down Expand Up @@ -681,6 +689,7 @@ def test_manifest_disk_customization_swap(tmp_path, build_container):
with config_path.open("w") as config_file:
json.dump(config, config_file)

testutil.pull_container(container_ref)
output = subprocess.check_output([
*testutil.podman_run_common,
"-v", f"{config_path}:/config.json:ro",
Expand Down Expand Up @@ -725,6 +734,7 @@ def test_manifest_disk_customization_lvm_swap(tmp_path, build_container):
with config_path.open("w") as config_file:
json.dump(config, config_file)

testutil.pull_container(container_ref)
output = subprocess.check_output([
*testutil.podman_run_common,
"-v", f"{config_path}:/config.json:ro",
Expand Down Expand Up @@ -754,6 +764,7 @@ def test_manifest_disk_customization_lvm_swap(tmp_path, build_container):
def test_iso_manifest_use_librepo(build_container, use_librepo):
# no need to parameterize this test, --use-librepo behaves same for all containers
container_ref = "quay.io/centos-bootc/centos-bootc:stream9"
testutil.pull_container(container_ref)

output = subprocess.check_output([
*testutil.podman_run_common,
Expand Down
15 changes: 8 additions & 7 deletions test/test_progress.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess

import testutil
# pylint: disable=unused-import,duplicate-code
from test_opts import container_storage_fixture
from containerbuild import build_container_fixture, build_fake_container_fixture
Expand All @@ -10,8 +11,7 @@ def test_progress_debug(tmp_path, build_fake_container):
output_path.mkdir(exist_ok=True)

cmdline = [
"podman", "run", "--rm",
"--privileged",
*testutil.podman_run_common,
build_fake_container,
"build",
"--progress=debug",
Expand All @@ -27,19 +27,21 @@ def test_progress_debug(tmp_path, build_fake_container):


def test_progress_term_works_without_tty(tmp_path, build_fake_container):
container_ref = "quay.io/centos-bootc/centos-bootc:stream9"
testutil.pull_container(container_ref)

output_path = tmp_path / "output"
output_path.mkdir(exist_ok=True)

cmdline = [
"podman", "run", "--rm",
*testutil.podman_run_common,
# note that "-t" is missing here
"--privileged",
build_fake_container,
"build",
# explicitly selecting term progress works even when there is no tty
# (i.e. we just need ansi terminal support)
"--progress=term",
"quay.io/centos-bootc/centos-bootc:stream9",
container_ref,
]
res = subprocess.run(cmdline, capture_output=True, text=True, check=False)
assert res.returncode == 0
Expand All @@ -51,10 +53,9 @@ def test_progress_term_autoselect(tmp_path, build_fake_container):
output_path.mkdir(exist_ok=True)

cmdline = [
"podman", "run", "--rm",
*testutil.podman_run_common,
# we have a terminal
"-t",
"--privileged",
build_fake_container,
"build",
# note that we do not select a --progress here so auto-select is used
Expand Down
3 changes: 2 additions & 1 deletion test/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def get_ip_from_default_route():
return default_route.split()[8]


def pull_container(container_ref, target_arch=""):
def pull_container(container_ref, target_arch="", tls_verify=True):
if target_arch == "":
target_arch = platform.machine()

Expand All @@ -225,5 +225,6 @@ def pull_container(container_ref, target_arch=""):
subprocess.run([
"podman", "pull",
"--arch", target_arch,
"--tls-verify" if tls_verify else "--tls-verify=false",
container_ref,
], check=True)

0 comments on commit 4f86598

Please sign in to comment.