blueprint: Add partitioning_mode customization
This commit is contained in:
parent
d0877e68dc
commit
2729f6ac54
2 changed files with 55 additions and 0 deletions
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/osbuild/images/pkg/disk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Customizations struct {
|
type Customizations struct {
|
||||||
|
|
@ -18,6 +20,7 @@ type Customizations struct {
|
||||||
Services *ServicesCustomization `json:"services,omitempty" toml:"services,omitempty"`
|
Services *ServicesCustomization `json:"services,omitempty" toml:"services,omitempty"`
|
||||||
Filesystem []FilesystemCustomization `json:"filesystem,omitempty" toml:"filesystem,omitempty"`
|
Filesystem []FilesystemCustomization `json:"filesystem,omitempty" toml:"filesystem,omitempty"`
|
||||||
InstallationDevice string `json:"installation_device,omitempty" toml:"installation_device,omitempty"`
|
InstallationDevice string `json:"installation_device,omitempty" toml:"installation_device,omitempty"`
|
||||||
|
PartitioningMode string `json:"partitioning_mode,omitempty" toml:"partitioning_mode,omitempty"`
|
||||||
FDO *FDOCustomization `json:"fdo,omitempty" toml:"fdo,omitempty"`
|
FDO *FDOCustomization `json:"fdo,omitempty" toml:"fdo,omitempty"`
|
||||||
OpenSCAP *OpenSCAPCustomization `json:"openscap,omitempty" toml:"openscap,omitempty"`
|
OpenSCAP *OpenSCAPCustomization `json:"openscap,omitempty" toml:"openscap,omitempty"`
|
||||||
Ignition *IgnitionCustomization `json:"ignition,omitempty" toml:"ignition,omitempty"`
|
Ignition *IgnitionCustomization `json:"ignition,omitempty" toml:"ignition,omitempty"`
|
||||||
|
|
@ -300,6 +303,26 @@ func (c *Customizations) GetFilesystemsMinSize() uint64 {
|
||||||
return agg
|
return agg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPartitioningMode converts the string to a disk.PartitioningMode type
|
||||||
|
func (c *Customizations) GetPartitioningMode() (disk.PartitioningMode, error) {
|
||||||
|
if c == nil {
|
||||||
|
return disk.DefaultPartitioningMode, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch c.PartitioningMode {
|
||||||
|
case "raw":
|
||||||
|
return disk.RawPartitioningMode, nil
|
||||||
|
case "lvm":
|
||||||
|
return disk.LVMPartitioningMode, nil
|
||||||
|
case "auto-lvm":
|
||||||
|
return disk.AutoLVMPartitioningMode, nil
|
||||||
|
case "":
|
||||||
|
return disk.DefaultPartitioningMode, nil
|
||||||
|
default:
|
||||||
|
return disk.DefaultPartitioningMode, fmt.Errorf("invalid partitioning mode '%s'", c.PartitioningMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Customizations) GetInstallationDevice() string {
|
func (c *Customizations) GetInstallationDevice() string {
|
||||||
if c == nil || c.InstallationDevice == "" {
|
if c == nil || c.InstallationDevice == "" {
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package blueprint
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/osbuild/images/pkg/disk"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -387,3 +388,34 @@ func TestGetOpenSCAPConfig(t *testing.T) {
|
||||||
|
|
||||||
assert.EqualValues(t, expectedOscap, *retOpenSCAPCustomiztions)
|
assert.EqualValues(t, expectedOscap, *retOpenSCAPCustomiztions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetPartitioningMode(t *testing.T) {
|
||||||
|
// No customizations returns Default which is actually AutoLVM,
|
||||||
|
// but that is handled by the images code
|
||||||
|
var c *Customizations
|
||||||
|
pm, err := c.GetPartitioningMode()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, disk.DefaultPartitioningMode, pm)
|
||||||
|
|
||||||
|
// Empty defaults to Default which is actually AutoLVM,
|
||||||
|
// but that is handled by the images code
|
||||||
|
c = &Customizations{}
|
||||||
|
_, err = c.GetPartitioningMode()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, disk.DefaultPartitioningMode, pm)
|
||||||
|
|
||||||
|
// Unknown mode returns an error
|
||||||
|
c = &Customizations{
|
||||||
|
PartitioningMode: "all-of-them",
|
||||||
|
}
|
||||||
|
_, err = c.GetPartitioningMode()
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
// And a known mode returns the correct type
|
||||||
|
c = &Customizations{
|
||||||
|
PartitioningMode: "lvm",
|
||||||
|
}
|
||||||
|
pm, err = c.GetPartitioningMode()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, disk.LVMPartitioningMode, pm)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue