Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blueprint: rename partitioning_customizations, tweak validation, typos #1054

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/blueprint/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/blueprint/filesystem_customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -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`,
},
Expand Down
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
Loading