Skip to content

Commit

Permalink
distro/fedora: check partitioning customizations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
achilleas-k committed Nov 15, 2024
1 parent 2f81245 commit a72afb6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
51 changes: 48 additions & 3 deletions pkg/distro/fedora/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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" {
Expand All @@ -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
Expand Down
17 changes: 11 additions & 6 deletions pkg/distro/fedora/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down

0 comments on commit a72afb6

Please sign in to comment.