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

Also extends the LVM test to include swap on lvm.
  • Loading branch information
mvo5 committed Dec 5, 2024
1 parent cf444ec commit c5b1e06
Show file tree
Hide file tree
Showing 4 changed files with 120 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,16 +694,23 @@ 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"]
if mnt["target"] == "/sysroot"]
assert len(mnts) == 1
assert "/dev/mapper/vg00-rootlv" == mnts[0]["source"]
# check swap too
assert "123M" in swapon_output
elif dc == "btrfs":
mnts = [mnt for mnt in findmnt["filesystems"][0]["children"]
if mnt["target"] == "/sysroot"]
assert len(mnts) == 1
assert "btrfs" == mnts[0]["fstype"]
# ensure sysroot comes from the "root" subvolume
assert mnts[0]["source"].endswith("[/root]")
elif dc == "swap":
assert "123M" in swapon_output
94 changes: 94 additions & 0 deletions test/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,97 @@ 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 find_mkswap_stage_from(manifest_str):
manifest = json.loads(manifest_str)
for pipeline in manifest["pipelines"]:
if pipeline["name"] == "image":
for st in pipeline["stages"]:
if st["type"] == "org.osbuild.mkswap":
return st
raise ValueError(f"cannot find mkswap stage in manifest:\n{manifest_str}")


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}",
])
mkswap_stage = find_mkswap_stage_from(output)
assert mkswap_stage["options"].get("uuid")
swap_uuid = mkswap_stage["options"]["uuid"]
fstab_stage = find_fstab_stage_from(output)
filesystems = fstab_stage["options"]["filesystems"]
assert {
'uuid': swap_uuid,
"vfs_type": "swap",
"path": "none",
"options": "defaults",
} in filesystems


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

config = {
"customizations": {
"disk": {
"partitions": [
{
"type": "lvm",
"minsize": "10 GiB",
"logical_volumes": [
{
# XXX: drop once https://github.com/osbuild/images/pull/1088 is merged
"name": "swap0",
"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}",
])
mkswap_stage = find_mkswap_stage_from(output)
assert mkswap_stage["options"].get("uuid")
swap_uuid = mkswap_stage["options"]["uuid"]
fstab_stage = find_fstab_stage_from(output)
filesystems = fstab_stage["options"]["filesystems"]
assert {
'uuid': swap_uuid,
"vfs_type": "swap",
"path": "none",
"options": "defaults",
} in 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": "123 MiB",
"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": "123 MiB",
"fs_type": "swap",
}
]
}
else:
raise ValueError(f"unsupported disk_config {tc.disk_config}")

Expand Down

0 comments on commit c5b1e06

Please sign in to comment.