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: add integration test for the new swap customization #745

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion bib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/cheggaaa/pb/v3 v3.1.5
github.com/google/uuid v1.6.0
github.com/hashicorp/go-version v1.7.0
github.com/osbuild/images v0.103.0
github.com/osbuild/images v0.104.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions bib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE
github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU=
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
github.com/osbuild/images v0.103.0 h1:GePI65RK/DPUEjoNqTqvZTdWJtrj+s2NyiLzdNoQYnM=
github.com/osbuild/images v0.103.0/go.mod h1:4bNmMQOVadIKVC1q8zsLO8tdEQFH90zIp+MQBQUnCiE=
github.com/osbuild/images v0.104.0 h1:EXEykPxQE5VNuLH/QM3NTYjgtIWlltPhiEQEg+DBCnI=
github.com/osbuild/images v0.104.0/go.mod h1:4bNmMQOVadIKVC1q8zsLO8tdEQFH90zIp+MQBQUnCiE=
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f h1:/UDgs8FGMqwnHagNDPGOlts35QkhAZ8by3DR7nMih7M=
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f/go.mod h1:J6OG6YJVEWopen4avK3VNQSnALmmjvniMmni/YFYAwc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
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 "7G" 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
92 changes: 92 additions & 0 deletions test/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,95 @@ 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": [
{
"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": "7 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": "123 MiB",
"fs_type": "swap",
}
]
}
else:
raise ValueError(f"unsupported disk_config {tc.disk_config}")

Expand Down
Loading