Skip to content

Commit

Permalink
blueprint: catch obviously invalid dos PTs early
Browse files Browse the repository at this point in the history
We can't catch all cases of dos partition table with too many
partitions, but catching the obvious ones early can help.
  • Loading branch information
achilleas-k authored and supakeen committed Dec 10, 2024
1 parent b923fd8 commit bf6db02
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/blueprint/disk_customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,16 @@ func (p *DiskCustomization) Validate() error {
}

switch p.Type {
case "gpt", "dos", "":
case "gpt", "":
case "dos":
// dos/mbr only supports 4 partitions
// Unfortunately, at this stage it's unknown whether we will need extra
// partitions (bios boot, root, esp), so this check is just to catch
// obvious invalid customizations early. The final partition table is
// checked after it's created.
if len(p.Partitions) > 4 {
return fmt.Errorf("invalid partitioning customizations: \"dos\" partition table type only supports up to 4 partitions: got %d", len(p.Partitions))
}
default:
return fmt.Errorf("unknown partition table type: %s (valid: gpt, dos)", p.Type)
}
Expand Down
50 changes: 50 additions & 0 deletions pkg/blueprint/disk_customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,56 @@ func TestPartitioningValidation(t *testing.T) {
},
expectedMsg: "unknown partition table type: toucan (valid: gpt, dos)",
},
"unhappy-too-many-parts": {
partitioning: &blueprint.DiskCustomization{
Type: "dos",
Partitions: []blueprint.PartitionCustomization{
{
Type: "plain",
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
FSType: "xfs",
Mountpoint: "/1",
},
},
{
Type: "plain",
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
FSType: "xfs",
Mountpoint: "/2",
},
},
{
Type: "plain",
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
FSType: "xfs",
Mountpoint: "/3",
},
},
{
Type: "plain",
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
FSType: "ext4",
Mountpoint: "/4",
},
},
{
Type: "plain",
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
FSType: "ext4",
Mountpoint: "/5",
},
},
{
Type: "plain",
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
FSType: "ext4",
Mountpoint: "/6",
},
},
},
},
expectedMsg: `invalid partitioning customizations: "dos" partition table type only supports up to 4 partitions: got 6`,
},
}

for name := range testCases {
Expand Down

0 comments on commit bf6db02

Please sign in to comment.