Skip to content

Commit

Permalink
test: add integration test for the new swap customization
Browse files Browse the repository at this point in the history
This commit adds an integration test for the new swap disk
customization that got added to the `images` library in PR
osbuild/images#1072
  • Loading branch information
mvo5 committed Dec 5, 2024
1 parent 0f4719c commit ad27709
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
7 changes: 7 additions & 0 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,9 @@ def assert_disk_customizations(image_type, test_vm):
keyfile=image_type.ssh_keyfile_private_path)
assert exit_status == 0
findmnt = json.loads(output)
exit_status, swapon_output = test_vm.run("swapon --show", user="root",
keyfile=image_type.ssh_keyfile_private_path)
assert exit_status == 0
if dc := image_type.disk_config:
if dc == "lvm":
mnts = [mnt for mnt in findmnt["filesystems"][0]["children"]
Expand All @@ -707,3 +710,7 @@ def assert_disk_customizations(image_type, test_vm):
assert "btrfs" == mnts[0]["fstype"]
# ensure sysroot comes from the "root" subvolume
assert mnts[0]["source"].endswith("[/root]")
elif dc == "swap":
# XXX: drop once this actually runs
print(swapon_output)
assert "1234" in swapon_output
31 changes: 31 additions & 0 deletions test/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,34 @@ def test_manifest_disk_customization_btrfs(tmp_path, build_container):
st = find_bootc_install_to_fs_stage_from(output)
assert st["mounts"][0]["type"] == "org.osbuild.btrfs"
assert st["mounts"][0]["target"] == "/"


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

config = {
"customizations": {
"disk": {
"partitions": [
{
"minsize": "2 GiB",
"fs_type": "swap",
}
]
}
}
}
config_path = tmp_path / "config.json"
with config_path.open("w") as config_file:
json.dump(config, config_file)

output = subprocess.check_output([
*testutil.podman_run_common,
"-v", f"{config_path}:/config.json:ro",
build_container,
"manifest", f"{container_ref}",
])
fstab_stage = find_fstab_stage_from(output)
filesystems = fstab_stage["options"]["filesystems"]
# XXX: find swap
print(filesystems)
15 changes: 6 additions & 9 deletions test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,14 @@ def gen_testcases(what): # pylint: disable=too-many-return-statements
TestCaseCentos(image="anaconda-iso"),
]
if what == "qemu-boot":
# test partition defaults with qcow2
test_cases = [
klass(image="qcow2")
for klass in (TestCaseCentos, TestCaseFedora)
# test default partitioning
TestCaseFedora(image="qcow2"),
# test with custom disk configs
TestCaseCentos(image="qcow2", disk_config="swap"),
TestCaseFedora(image="raw", disk_config="btrfs"),
TestCaseCentos(image="raw", disk_config="lvm"),
]
# and custom with raw (this is arbitrary, we could do it the
# other way around too
test_cases.append(
TestCaseCentos(image="raw", disk_config="lvm"))
test_cases.append(
TestCaseFedora(image="raw", disk_config="btrfs"))
# do a cross arch test too
if platform.machine() == "x86_64":
# TODO: re-enable once
Expand Down
13 changes: 13 additions & 0 deletions test/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ def maybe_create_disk_customizations(cfg, tc):
"minsize": "10 GiB",
"fs_type": "xfs",
"mountpoint": "/",
},
{
"minsize": "2 GiB",
"fs_type": "swap",
}
]
}
Expand All @@ -179,6 +183,15 @@ def maybe_create_disk_customizations(cfg, tc):
}
]
}
elif tc.disk_config == "swap":
cfg["customizations"]["disk"] = {
"partitions": [
{
"minsize": "1234567890",
"fs_type": "swap",
}
]
}
else:
raise ValueError(f"unsupported disk_config {tc.disk_config}")

Expand Down

0 comments on commit ad27709

Please sign in to comment.