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

Test: rebuild disks from bootable containers when the BIB container changes #405

Merged
merged 6 commits into from
Feb 10, 2024
Merged
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
59 changes: 59 additions & 0 deletions test/scripts/test_imgtestlib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import os
import subprocess as sp
import tempfile

import pytest

import imgtestlib as testlib

TEST_ARCHES = ["amd64", "arm64"]


def can_sudo_nopw() -> bool:
"""
Check if we can run sudo without a password.
"""
job = sp.run(["sudo", "-n", "true"], capture_output=True, check=False)
return job.returncode == 0


def test_runcmd():
stdout, stderr = testlib.runcmd(["/bin/echo", "hello"])
Expand Down Expand Up @@ -32,3 +46,48 @@ def test_path_generators():
"inforoot/osbuild-104-1.fc39.noarch/abc123/info.json"
assert testlib.gen_build_info_s3("fedora-39", "aarch64", "abc123") == \
testlib.S3_BUCKET + "/images/builds/fedora-39/aarch64/osbuild-104-1.fc39.noarch/abc123/"


test_container = "registry.gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/manifest-list-test"

# manifest IDs for
# registry.gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/manifest-list-test:latest
manifest_ids = {
"amd64": "sha256:601c98c8148720ec5c29b8e854a1d5d88faddbc443eca12920d76cf993d7290e",
"arm64": "sha256:1a19a94647b1379fed8c23eb7553327cb604ba546eb93f9f6c1e6d11911c8beb",
}

# image IDs for
# registry.gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/manifest-list-test:latest
image_ids = {
"amd64": "sha256:dbb63178dc9157068107961f11397df3fb62c02fa64f697d571bf84aad71cb99",
"arm64": "sha256:62d2a7b3bf9e0b4f3aba22553d6971227b5a39f7f408d46347b1ee74eb97cb20",
}


@pytest.mark.parametrize("arch", TEST_ARCHES)
def test_skopeo_inspect_id_manifest_list(arch):
transport = "docker://"
image_id = image_ids[arch]
assert testlib.skopeo_inspect_id(f"{transport}{test_container}:latest", arch) == image_id


@pytest.mark.parametrize("arch", TEST_ARCHES)
def test_skopeo_inspect_image_manifest(arch):
transport = "docker://"
manifest_id = manifest_ids[arch]
image_id = image_ids[arch]
# arch arg to skopeo_inspect_id doesn't matter here
assert testlib.skopeo_inspect_id(f"{transport}{test_container}@{manifest_id}", arch) == image_id


@pytest.mark.skipif(not can_sudo_nopw(), reason="requires passwordless sudo")
@pytest.mark.parametrize("arch", TEST_ARCHES)
def test_skopeo_inspect_localstore(arch):
transport = "containers-storage:"
image = "registry.gitlab.com/redhat/services/products/image-builder/ci/osbuild-composer/manifest-list-test:latest"
with tempfile.TemporaryDirectory() as tmpdir:
testlib.runcmd(["sudo", "podman", "pull", f"--arch={arch}", "--storage-driver=vfs", f"--root={tmpdir}", image])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--storage-driver=vfs is so we can run the test in a container, right? It might be worth leaving a small note about that here, it might not be obvious to future readers.

EDIT from future Ondrej who read all commits: So it apparently doesn't work in a container... weird...


# arch arg to skopeo_inspect_id doesn't matter here
assert testlib.skopeo_inspect_id(f"{transport}[vfs@{tmpdir}]{image}", arch) == image_ids[arch]