Skip to content

Commit

Permalink
test: add (messy/failing) disk-customization test
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Nov 21, 2024
1 parent 7517803 commit 7be1324
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
18 changes: 14 additions & 4 deletions test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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
pass
for fs in fs_customizations:
mountpoint = fs["mountpoint"]
if mountpoint == "/":
Expand Down
2 changes: 1 addition & 1 deletion test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
49 changes: 48 additions & 1 deletion test/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 7be1324

Please sign in to comment.