From a72afb6f26ca2b5cdcd6d222cda52c4098793048 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 11 Sep 2024 18:48:57 +0200 Subject: [PATCH] distro/fedora: check partitioning customizations Add checks for Partitioning customizations in Fedora's checkOptions() function. The function now returns an error if: - Partitioning is defined at the same time as Filesystem - Partitioning is defined for ostree image types (commit and container). - The mountpoints in Partitioning violate the mountpoint policies for the image type. --- pkg/distro/fedora/distro_test.go | 51 ++++++++++++++++++++++++++++++-- pkg/distro/fedora/imagetype.go | 17 +++++++---- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/pkg/distro/fedora/distro_test.go b/pkg/distro/fedora/distro_test.go index cd50693408..e75deea029 100644 --- a/pkg/distro/fedora/distro_test.go +++ b/pkg/distro/fedora/distro_test.go @@ -740,7 +740,7 @@ func TestDistro_CustomFileSystemManifestError(t *testing.T) { imgType, _ := arch.GetImageType(imgTypeName) _, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0) if imgTypeName == "iot-commit" || imgTypeName == "iot-container" || imgTypeName == "iot-bootable-container" { - assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types") + assert.EqualError(t, err, "Custom mountpoints and partitioning are not supported for ostree types") } else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" { assert.EqualError(t, err, fmt.Sprintf(distro.UnsupportedCustomizationError, imgTypeName, "User, Group, Directories, Files, Services, FIPS")) } else if imgTypeName == "iot-installer" || imgTypeName == "iot-simplified-installer" || imgTypeName == "image-installer" { @@ -774,7 +774,7 @@ func TestDistro_TestRootMountPoint(t *testing.T) { imgType, _ := arch.GetImageType(imgTypeName) _, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0) if imgTypeName == "iot-commit" || imgTypeName == "iot-container" || imgTypeName == "iot-bootable-container" { - assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types") + assert.EqualError(t, err, "Custom mountpoints and partitioning are not supported for ostree types") } else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" { assert.EqualError(t, err, fmt.Sprintf(distro.UnsupportedCustomizationError, imgTypeName, "User, Group, Directories, Files, Services, FIPS")) } else if imgTypeName == "iot-installer" || imgTypeName == "iot-simplified-installer" || imgTypeName == "image-installer" { @@ -922,7 +922,7 @@ func TestDistro_CustomUsrPartitionNotLargeEnough(t *testing.T) { imgType, _ := arch.GetImageType(imgTypeName) _, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0) if imgTypeName == "iot-commit" || imgTypeName == "iot-container" || imgTypeName == "iot-bootable-container" { - assert.EqualError(t, err, "Custom mountpoints are not supported for ostree types") + assert.EqualError(t, err, "Custom mountpoints and partitioning are not supported for ostree types") } else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" { assert.EqualError(t, err, fmt.Sprintf(distro.UnsupportedCustomizationError, imgTypeName, "User, Group, Directories, Files, Services, FIPS")) } else if imgTypeName == "iot-installer" || imgTypeName == "iot-simplified-installer" || imgTypeName == "image-installer" { @@ -937,6 +937,51 @@ func TestDistro_CustomUsrPartitionNotLargeEnough(t *testing.T) { } } +func TestDistro_PartitioningConflict(t *testing.T) { + bp := blueprint.Blueprint{ + Customizations: &blueprint.Customizations{ + Filesystem: []blueprint.FilesystemCustomization{ + { + MinSize: 1024, + Mountpoint: "/", + }, + }, + Disk: &blueprint.DiskCustomization{ + Partitions: []blueprint.PartitionCustomization{ + { + MinSize: 19, + FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{ + Mountpoint: "/home", + }, + }, + }, + }, + }, + } + for _, dist := range fedoraFamilyDistros { + fedoraDistro := dist.distro + for _, archName := range fedoraDistro.ListArches() { + arch, _ := fedoraDistro.GetArch(archName) + for _, imgTypeName := range arch.ListImageTypes() { + imgType, _ := arch.GetImageType(imgTypeName) + _, _, err := imgType.Manifest(&bp, distro.ImageOptions{}, nil, 0) + if imgTypeName == "iot-commit" || imgTypeName == "iot-container" || imgTypeName == "iot-bootable-container" { + assert.EqualError(t, err, "Custom mountpoints and partitioning are not supported for ostree types") + } else if imgTypeName == "iot-raw-image" || imgTypeName == "iot-qcow2-image" { + assert.EqualError(t, err, fmt.Sprintf(distro.UnsupportedCustomizationError, imgTypeName, "User, Group, Directories, Files, Services, FIPS")) + } else if imgTypeName == "iot-installer" || imgTypeName == "iot-simplified-installer" || imgTypeName == "image-installer" { + continue + } else if imgTypeName == "live-installer" { + assert.EqualError(t, err, fmt.Sprintf(distro.NoCustomizationsAllowedError, imgTypeName)) + } else { + assert.EqualError(t, err, "partitioning customizations cannot be used with custom filesystems (mountpoints)") + } + } + } + } + +} + func TestDistroFactory(t *testing.T) { type testCase struct { strID string diff --git a/pkg/distro/fedora/imagetype.go b/pkg/distro/fedora/imagetype.go index 1abddad678..60aea17cf7 100644 --- a/pkg/distro/fedora/imagetype.go +++ b/pkg/distro/fedora/imagetype.go @@ -374,13 +374,18 @@ func (t *imageType) checkOptions(bp *blueprint.Blueprint, options distro.ImageOp } mountpoints := customizations.GetFilesystems() - - if mountpoints != nil && t.rpmOstree { - return nil, fmt.Errorf("Custom mountpoints are not supported for ostree types") + partitioning := customizations.GetPartitioning() + if (len(mountpoints) > 0 || partitioning != nil) && t.rpmOstree { + return nil, fmt.Errorf("Custom mountpoints and partitioning are not supported for ostree types") + } + if len(mountpoints) > 0 && partitioning != nil { + return nil, fmt.Errorf("partitioning customizations cannot be used with custom filesystems (mountpoints)") } - err := blueprint.CheckMountpointsPolicy(mountpoints, policies.MountpointPolicies) - if err != nil { + if err := blueprint.CheckMountpointsPolicy(mountpoints, policies.MountpointPolicies); err != nil { + return nil, err + } + if err := blueprint.CheckDiskMountpointsPolicy(partitioning, policies.MountpointPolicies); err != nil { return nil, err } @@ -401,7 +406,7 @@ func (t *imageType) checkOptions(bp *blueprint.Blueprint, options distro.ImageOp dc := customizations.GetDirectories() fc := customizations.GetFiles() - err = blueprint.ValidateDirFileCustomizations(dc, fc) + err := blueprint.ValidateDirFileCustomizations(dc, fc) if err != nil { return nil, err }