Skip to content

Commit

Permalink
test: add a test to verify libosinfo detection
Browse files Browse the repository at this point in the history
Add a test to verify the anaconda ISO label is
properly detected by libosinfo.

Signed-off-by: Miguel Martín <[email protected]>
  • Loading branch information
mmartinv authored and ondrejbudai committed Oct 10, 2024
1 parent dba4431 commit 1ccd370
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Install test dependencies
run: |
sudo apt update
sudo apt install -y podman python3-pytest python3-paramiko python3-boto3 flake8 qemu-system-x86 qemu-efi-aarch64 qemu-system-arm qemu-user-static pylint
sudo apt install -y podman python3-pytest python3-paramiko python3-boto3 flake8 qemu-system-x86 qemu-efi-aarch64 qemu-system-arm qemu-user-static pylint libosinfo-bin
- name: Diskspace (before)
run: |
df -h
Expand Down
1 change: 1 addition & 0 deletions plans/all.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ prepare:
- qemu-kvm
- qemu-system-aarch64
- qemu-user-static
- libosinfo
execute:
how: tmt
script: |
Expand Down
30 changes: 24 additions & 6 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ImageBuildResult(NamedTuple):
img_type: str
img_path: str
img_arch: str
osinfo_template: str
container_ref: str
rootfs: str
username: str
Expand Down Expand Up @@ -162,9 +163,9 @@ def build_images(shared_tmpdir, build_container, request, force_aws_upload):
journal_output = journal_log_path.read_text(encoding="utf8")
bib_output = bib_output_path.read_text(encoding="utf8")
results.append(ImageBuildResult(
image_type, generated_img, tc.target_arch, tc.container_ref, tc.rootfs,
username, password, ssh_keyfile_private_path,
kargs, bib_output, journal_output))
image_type, generated_img, tc.target_arch, tc.osinfo_template,
tc.container_ref, tc.rootfs, username, password,
ssh_keyfile_private_path, kargs, bib_output, journal_output))

# generate new keyfile
if not ssh_keyfile_private_path.exists():
Expand Down Expand Up @@ -297,9 +298,9 @@ def del_ami():
results = []
for image_type in image_types:
results.append(ImageBuildResult(
image_type, artifact[image_type], tc.target_arch, tc.container_ref, tc.rootfs,
username, password, ssh_keyfile_private_path,
kargs, bib_output, journal_output, metadata))
image_type, artifact[image_type], tc.target_arch, tc.osinfo_template,
tc.container_ref, tc.rootfs, username, password,
ssh_keyfile_private_path, kargs, bib_output, journal_output, metadata))
yield results

# Try to cache as much as possible
Expand Down Expand Up @@ -452,6 +453,23 @@ def test_iso_installs(image_type):
assert_kernel_args(vm, image_type)


@pytest.mark.skipif(platform.system() != "Linux", reason="osinfo detect test only runs on linux right now")
@pytest.mark.parametrize("image_type", gen_testcases("anaconda-iso"), indirect=["image_type"])
def test_iso_os_detection(image_type):
installer_iso_path = image_type.img_path
arch = image_type.img_arch
if not arch:
arch = platform.machine()
osinfo = image_type.osinfo_template.format(arch=arch)
result = subprocess.run([
"osinfo-detect",
installer_iso_path,
], capture_output=True, text=True, check=True)
osinfo_output = result.stdout
expected_output = f"Media is bootable.\nMedia is an installer for OS '{osinfo}'\n"
assert osinfo_output == expected_output


@pytest.mark.parametrize("images", gen_testcases("multidisk"), indirect=["images"])
def test_multi_build_request(images):
artifacts = set()
Expand Down
3 changes: 3 additions & 0 deletions test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ def __str__(self):
class TestCaseFedora(TestCase):
container_ref: str = "quay.io/fedora/fedora-bootc:40"
rootfs: str = "btrfs"
osinfo_template: str = "Fedora Server 40 ({arch})"


@dataclasses.dataclass
class TestCaseFedora42(TestCase):
container_ref: str = "quay.io/fedora/fedora-bootc:42"
rootfs: str = "btrfs"
osinfo_template: str = "Fedora Server 42 ({arch})"


@dataclasses.dataclass
class TestCaseCentos(TestCase):
container_ref: str = os.getenv(
"BIB_TEST_BOOTC_CONTAINER_TAG",
"quay.io/centos-bootc/centos-bootc:stream9")
osinfo_template: str = "CentOS Stream 9 ({arch})"


def gen_testcases(what): # pylint: disable=too-many-return-statements
Expand Down

0 comments on commit 1ccd370

Please sign in to comment.