Skip to content

Commit

Permalink
blueprint: when doing GetPartitioning() also validate
Browse files Browse the repository at this point in the history
This commit follows the pattern of `GetRepositories()` to do
validation early as part of getting the customization.
  • Loading branch information
mvo5 committed Nov 22, 2024
1 parent 1bb8671 commit 1621f4d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
10 changes: 7 additions & 3 deletions pkg/blueprint/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,15 @@ func (c *Customizations) GetFilesystemsMinSize() uint64 {
return agg
}

func (c *Customizations) GetPartitioning() *DiskCustomization {
func (c *Customizations) GetPartitioning() (*DiskCustomization, error) {
if c == nil {
return nil
return nil, nil
}
return c.Disk
if err := c.Disk.Validate(); err != nil {
return nil, err
}

return c.Disk, nil
}

func (c *Customizations) GetInstallationDevice() string {
Expand Down
42 changes: 42 additions & 0 deletions pkg/blueprint/customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func TestGetRPM(t *testing.T) {
assert.EqualValues(t, expectedRPM, *retRPM)

}

func TestGetRHSM(t *testing.T) {
expectedRHSM := RHSMCustomization{
Config: &RHSMConfig{
Expand Down Expand Up @@ -493,3 +494,44 @@ func TestGetInstallerErrors(t *testing.T) {
})
}
}

func TestGetPartitioningTrivial(t *testing.T) {
expected := DiskCustomization{
Partitions: []PartitionCustomization{
{
MinSize: 19,
FilesystemTypedCustomization: FilesystemTypedCustomization{
FSType: "ext4",
Mountpoint: "/home",
},
},
},
}

TestCustomizations := Customizations{
Disk: &expected,
}

ret, err := TestCustomizations.GetPartitioning()
assert.NoError(t, err)
assert.EqualValues(t, expected, *ret)
}

func TestGetPartitioningUnhappy(t *testing.T) {
expected := DiskCustomization{
Partitions: []PartitionCustomization{
{
FilesystemTypedCustomization: FilesystemTypedCustomization{
FSType: "ext4",
},
},
},
}

TestCustomizations := Customizations{
Disk: &expected,
}

_, err := TestCustomizations.GetPartitioning()
assert.ErrorContains(t, err, "mountpoint is empty")
}
1 change: 1 addition & 0 deletions pkg/distro/fedora/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ func TestDistro_PartitioningConflict(t *testing.T) {
{
MinSize: 19,
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
FSType: "ext4",
Mountpoint: "/home",
},
},
Expand Down
12 changes: 9 additions & 3 deletions pkg/distro/fedora/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ func (t *imageType) getPartitionTable(
}

imageSize := t.Size(options.Size)
partitioning := customizations.GetPartitioning()
partitioning, err := customizations.GetPartitioning()
if err != nil {
return nil, err
}
if partitioning != nil {
// Use the new custom partition table to create a PT fully based on the user's customizations.
// This overrides FilesystemCustomizations, but we should never have both defined.
Expand Down Expand Up @@ -374,7 +377,10 @@ func (t *imageType) checkOptions(bp *blueprint.Blueprint, options distro.ImageOp
}

mountpoints := customizations.GetFilesystems()
partitioning := customizations.GetPartitioning()
partitioning, err := customizations.GetPartitioning()
if err != nil {
return nil, err
}
if (len(mountpoints) > 0 || partitioning != nil) && t.rpmOstree {
return nil, fmt.Errorf("Custom mountpoints and partitioning are not supported for ostree types")
}
Expand Down Expand Up @@ -406,7 +412,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 1621f4d

Please sign in to comment.