From 16dcb790be4b9f0aaa143e25da6a1da076eab811 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 21 Nov 2024 12:59:47 +0100 Subject: [PATCH] test: add (messy) disk-customization test --- test/test_build.py | 18 +++++++++++++---- test/testcases.py | 2 +- test/testutil.py | 49 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/test/test_build.py b/test/test_build.py index 7c94616d..e9b4da17 100644 --- a/test/test_build.py +++ b/test/test_build.py @@ -38,6 +38,7 @@ class ImageBuildResult(NamedTuple): img_arch: str container_ref: str rootfs: str + partition_mode: str username: str password: str ssh_keyfile_private_path: str @@ -327,7 +328,8 @@ def build_images(shared_tmpdir, build_container, request, force_aws_upload, gpg_ bib_output = bib_output_path.read_text(encoding="utf8") results.append(ImageBuildResult( image_type, generated_img, tc.target_arch, - container_ref, tc.rootfs, username, password, + container_ref, tc.rootfs, tc.partition_mode, + username, password, ssh_keyfile_private_path, kargs, bib_output, journal_output)) # generate new keyfile @@ -368,12 +370,15 @@ def build_images(shared_tmpdir, build_container, request, force_aws_upload, gpg_ "groups": ["wheel"], }, ], - "filesystem": testutil.create_filesystem_customizations(tc.rootfs), "kernel": { "append": kargs, }, }, } + if tc.rootfs: + cfg["customizations"]["filesystem"] = testutil.create_filesystem_customizations(tc.partition_mode, tc.rootfs) + if tc.partition_mode: + cfg["customizations"]["disk"] = testutil.create_disk_customizations(tc.partition_mode) config_json_path = output_path / "config.json" config_json_path.write_text(json.dumps(cfg), encoding="utf-8") @@ -473,7 +478,8 @@ def del_ami(): for image_type in image_types: results.append(ImageBuildResult( image_type, artifact[image_type], tc.target_arch, - container_ref, tc.rootfs, username, password, + container_ref, tc.rootfs, tc.partition_mode, + username, password, ssh_keyfile_private_path, kargs, bib_output, journal_output, metadata)) yield results @@ -545,6 +551,7 @@ def test_image_boots(image_type): mountpoint_sizes[fields[0]] = int(fields[1]) * 2 ** 10 # in bytes assert_fs_customizations(image_type, mountpoint_sizes) + # XXX: add assert_disk_customizations() @pytest.mark.parametrize("image_type", gen_testcases("ami-boot"), indirect=["image_type"]) @@ -670,7 +677,10 @@ def assert_fs_customizations(image_type, mountpoint_sizes): TODO: assert that the size of each filesystem (or partition) also matches the expected size based on the customization. """ - fs_customizations = testutil.create_filesystem_customizations(image_type.rootfs) + fs_customizations = testutil.create_filesystem_customizations(image_type.partition_mode, image_type.rootfs) + if image_type.partition_mode: + # XXX: add checks + return for fs in fs_customizations: mountpoint = fs["mountpoint"] if mountpoint == "/": diff --git a/test/testcases.py b/test/testcases.py index 0cf51e1d..0ef4af57 100644 --- a/test/testcases.py +++ b/test/testcases.py @@ -25,7 +25,7 @@ class TestCase: rootfs: str = "" # Sign the container_ref and use the new signed image instead of the original one sign: bool = False - # use special partition_mode like "lvm" + # XXX: rename/rethink, use special partition_mode like "lvm" partition_mode: str = "" def bib_rootfs_args(self): diff --git a/test/testutil.py b/test/testutil.py index b853c613..10142cfa 100644 --- a/test/testutil.py +++ b/test/testutil.py @@ -109,7 +109,11 @@ def deregister_ami(ami_id): print(f"Error {err_code}: {err_msg}") -def create_filesystem_customizations(rootfs: str): +def create_filesystem_customizations(partition_mode: str, rootfs: str): + if partition_mode: + # XXX: make this nicer, disk-customizations and fs-customizations + # cannot be combined right now + return if rootfs == "btrfs": # only minimal customizations are supported for btrfs currently return [ @@ -139,6 +143,49 @@ def create_filesystem_customizations(rootfs: str): }, ] +def create_disk_customizations(partition_mode: str): + if partition_mode == "lvm": + return { + # XXX: needed because we have no defaults in images currently + # XXX2: also string reading fails with: + # cannot unmarshal string into Go struct field DiskCustomization.customizations.disk.minsize of type uint64 + "minsize": 10000000000, + "partitions": [ + { + "type": "lvm", + "logical_volumes": [ + { + # XXX: without this we get + # .pipelines[1].stages[2].options.volumes[0].size: + # '0B' does not match '[1-9][0-9]*[bBsSkKmMgGtTpPeE]?' + "minsize": 10000000000, + "fs_type": "xfs", + "mountpoint": "/", + } + ] + } + ] + } + if partition_mode == "btrfs": + return { + # XXX: needed because we have no defaults in images currently + # XXX2: also string reading fails with: + # cannot unmarshal string into Go struct field DiskCustomization.customizations.disk.minsize of type uint64 + "minsize": 10000000000, + "partitions": [ + { + "type": "btrfs", + "subvolumes": [ + { + "name": "varlog", + "mountpoint": "/var/log", + } + ] + } + ] + } + raise ValueError(f"unsupported partition_mode {partition_mode}") + # podman_run_common has the common prefix for the podman run invocations podman_run_common = [