Skip to content

Commit

Permalink
disk: add support for selecting partition table type
Browse files Browse the repository at this point in the history
Follow-up to the previous commit. Translates the given partition table
type from a blueprint to the actual partition table.
  • Loading branch information
ondrejbudai committed Dec 3, 2024
1 parent 5f5e728 commit a34d242
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
23 changes: 16 additions & 7 deletions pkg/disk/partition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,15 +1232,24 @@ func NewCustomPartitionTable(customizations *blueprint.DiskCustomization, option

pt := &PartitionTable{}

// TODO: Handle partition table type in customizations
switch options.PartitionTableType {
case PT_GPT, PT_DOS:
pt.Type = options.PartitionTableType
case PT_NONE:
// default to "gpt"
switch customizations.Type {
case "dos":
pt.Type = PT_DOS
case "gpt":
pt.Type = PT_GPT
case "":
// partition table type not specified, determine the default
switch options.PartitionTableType {
case PT_GPT, PT_DOS:
pt.Type = options.PartitionTableType
case PT_NONE:
// default to "gpt"
pt.Type = PT_GPT
default:
return nil, fmt.Errorf("%s invalid partition table type enum value: %d", errPrefix, options.PartitionTableType)
}
default:
return nil, fmt.Errorf("%s invalid partition table type enum value: %d", errPrefix, options.PartitionTableType)
return nil, fmt.Errorf("%s invalid partition table type: %s", errPrefix, customizations.Type)
}

// add any partition(s) that are needed for booting (like /boot/efi)
Expand Down
15 changes: 12 additions & 3 deletions pkg/disk/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,11 +1131,13 @@ func TestNewCustomPartitionTable(t *testing.T) {

testCases := map[string]testCase{
"dos-hybrid": {
customizations: nil,
customizations: &blueprint.DiskCustomization{
Type: "dos", // overrides the default option
},
options: &disk.CustomPartitionTableOptions{
DefaultFSType: disk.FS_XFS,
BootMode: platform.BOOT_HYBRID,
PartitionTableType: disk.PT_DOS,
PartitionTableType: disk.PT_GPT,
},
expected: &disk.PartitionTable{
Type: disk.PT_DOS,
Expand Down Expand Up @@ -1580,6 +1582,7 @@ func TestNewCustomPartitionTable(t *testing.T) {
},
"plain+": {
customizations: &blueprint.DiskCustomization{
Type: "gpt", // overrides the default option
Partitions: []blueprint.PartitionCustomization{
{
MinSize: 50 * datasizes.MiB,
Expand Down Expand Up @@ -1609,7 +1612,7 @@ func TestNewCustomPartitionTable(t *testing.T) {
options: &disk.CustomPartitionTableOptions{
DefaultFSType: disk.FS_EXT4,
BootMode: platform.BOOT_HYBRID,
PartitionTableType: disk.PT_GPT,
PartitionTableType: disk.PT_DOS,
RequiredMinSizes: map[string]uint64{"/": 3 * datasizes.GiB},
},
expected: &disk.PartitionTable{
Expand Down Expand Up @@ -2267,6 +2270,12 @@ func TestNewCustomPartitionTableErrors(t *testing.T) {
},
errmsg: `error generating partition table: invalid partition table type enum value: 100`,
},
"bad-pt-type-in-customizations": {
customizations: &blueprint.DiskCustomization{
Type: "toucan",
},
errmsg: `error generating partition table: unknown partition table type: toucan (valid: gpt, dos)`,
},
}

// we don't care about the rng for error tests
Expand Down
1 change: 1 addition & 0 deletions test/configs/partitioning-lvm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"blueprint": {
"customizations": {
"disk": {
"type": "dos",
"partitions": [
{
"mountpoint": "/data",
Expand Down

0 comments on commit a34d242

Please sign in to comment.