diff --git a/pkg/blueprint/customizations.go b/pkg/blueprint/customizations.go index d4d8746a35..9069067128 100644 --- a/pkg/blueprint/customizations.go +++ b/pkg/blueprint/customizations.go @@ -312,11 +312,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 { diff --git a/pkg/blueprint/customizations_test.go b/pkg/blueprint/customizations_test.go index e3df87d69d..d2da30d20d 100644 --- a/pkg/blueprint/customizations_test.go +++ b/pkg/blueprint/customizations_test.go @@ -378,6 +378,7 @@ func TestGetRPM(t *testing.T) { assert.EqualValues(t, expectedRPM, *retRPM) } + func TestGetRHSM(t *testing.T) { expectedRHSM := RHSMCustomization{ Config: &RHSMConfig{ @@ -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") +} diff --git a/pkg/blueprint/partitioning_customizations.go b/pkg/blueprint/disk_customizations.go similarity index 99% rename from pkg/blueprint/partitioning_customizations.go rename to pkg/blueprint/disk_customizations.go index 800063a2b9..09b92099fd 100644 --- a/pkg/blueprint/partitioning_customizations.go +++ b/pkg/blueprint/disk_customizations.go @@ -189,7 +189,7 @@ func decodePlain(v *PartitionCustomization, data []byte) error { return nil } -// descodeBtrfs decodes the data into a struct that only embeds the +// decodeBtrfs decodes the data into a struct that only embeds the // BtrfsVolumeCustomization with DisallowUnknownFields. This ensures that when // the type is btrfs, none of the fields for plain or lvm are used. func decodeBtrfs(v *PartitionCustomization, data []byte) error { diff --git a/pkg/blueprint/partitioning_customizations_test.go b/pkg/blueprint/disk_customizations_test.go similarity index 100% rename from pkg/blueprint/partitioning_customizations_test.go rename to pkg/blueprint/disk_customizations_test.go diff --git a/pkg/blueprint/filesystem_customizations_test.go b/pkg/blueprint/filesystem_customizations_test.go index cb4860c525..fbb85f0817 100644 --- a/pkg/blueprint/filesystem_customizations_test.go +++ b/pkg/blueprint/filesystem_customizations_test.go @@ -50,13 +50,13 @@ func TestFilesystemCustomizationUnmarshalTOMLUnhappy(t *testing.T) { err: `toml: line 0: TOML unmarshal: mountpoint must be string, got "42" of type int64`, }, { - name: "misize nor string nor int", + name: "minsize nor string nor int", input: `mountpoint="/" minsize = true`, err: `toml: line 0: TOML unmarshal: error decoding minsize value for mountpoint "/": failed to convert value "true" to number`, }, { - name: "misize not parseable", + name: "minsize not parseable", input: `mountpoint="/" minsize = "20 KG"`, err: `toml: line 0: TOML unmarshal: error decoding minsize value for mountpoint "/": unknown data size units in string: 20 KG`, @@ -84,12 +84,12 @@ func TestFilesystemCustomizationUnmarshalJSONUnhappy(t *testing.T) { err: `JSON unmarshal: mountpoint must be string, got "42" of type float64`, }, { - name: "misize nor string nor int", + name: "minsize nor string nor int", input: `{"mountpoint":"/", "minsize": true}`, err: `JSON unmarshal: error decoding minsize value for mountpoint "/": failed to convert value "true" to number`, }, { - name: "misize not parseable", + name: "minsize not parseable", input: `{ "mountpoint": "/", "minsize": "20 KG"}`, err: `JSON unmarshal: error decoding minsize value for mountpoint "/": unknown data size units in string: 20 KG`, }, diff --git a/pkg/distro/fedora/distro_test.go b/pkg/distro/fedora/distro_test.go index e75deea029..e7a4e65d21 100644 --- a/pkg/distro/fedora/distro_test.go +++ b/pkg/distro/fedora/distro_test.go @@ -951,6 +951,7 @@ func TestDistro_PartitioningConflict(t *testing.T) { { MinSize: 19, FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{ + FSType: "ext4", Mountpoint: "/home", }, }, diff --git a/pkg/distro/fedora/imagetype.go b/pkg/distro/fedora/imagetype.go index 60aea17cf7..720e863b81 100644 --- a/pkg/distro/fedora/imagetype.go +++ b/pkg/distro/fedora/imagetype.go @@ -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. @@ -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") } @@ -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 }