diff --git a/pkg/disk/partition_table.go b/pkg/disk/partition_table.go index 1fc4199afb..57bdaa010e 100644 --- a/pkg/disk/partition_table.go +++ b/pkg/disk/partition_table.go @@ -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) diff --git a/pkg/disk/partition_table_test.go b/pkg/disk/partition_table_test.go index 7377bf5cac..9ec20ddc38 100644 --- a/pkg/disk/partition_table_test.go +++ b/pkg/disk/partition_table_test.go @@ -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, @@ -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, @@ -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{ @@ -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 diff --git a/test/configs/partitioning-lvm.json b/test/configs/partitioning-lvm.json index 22e525be7d..487a0f2371 100644 --- a/test/configs/partitioning-lvm.json +++ b/test/configs/partitioning-lvm.json @@ -3,6 +3,7 @@ "blueprint": { "customizations": { "disk": { + "type": "dos", "partitions": [ { "mountpoint": "/data",