Skip to content

Commit

Permalink
blueprint,disk: tiny style changes
Browse files Browse the repository at this point in the history
This commit changes some ordering and var names, very minor, test
tweaks, c.f.
* #1041 (comment)
* #1041 (comment)
* #1041 (comment)
* #1041 (comment)
* #1041 (comment)
* #1041 (comment)
* #1041 (comment)
* #1041 (comment)
  • Loading branch information
mvo5 authored and achilleas-k committed Nov 22, 2024
1 parent ec64965 commit db5eda7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
10 changes: 5 additions & 5 deletions pkg/blueprint/disk_customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@ func (p *DiskCustomization) Validate() error {
var errs []error
for _, part := range p.Partitions {
switch part.Type {
case "plain", "":
errs = append(errs, part.validatePlain(mountpoints))
case "lvm":
errs = append(errs, part.validateLVM(mountpoints, vgnames))
case "btrfs":
errs = append(errs, part.validateBtrfs(mountpoints))
case "plain", "":
errs = append(errs, part.validatePlain(mountpoints))
default:
errs = append(errs, fmt.Errorf("unknown partition type: %s", part.Type))
}
Expand Down Expand Up @@ -404,19 +404,19 @@ func (p *DiskCustomization) ValidateLayoutConstraints() error {

// Check that the fs type is valid for the mountpoint.
func validateFilesystemType(path, fstype string) error {
badfsMsg := "unsupported filesystem type for %q: %s"
badfsMsgFmt := "unsupported filesystem type for %q: %s"
switch path {
case "/boot":
switch fstype {
case "xfs", "ext4":
default:
return fmt.Errorf(badfsMsg, path, fstype)
return fmt.Errorf(badfsMsgFmt, path, fstype)
}
case "/boot/efi":
switch fstype {
case "vfat":
default:
return fmt.Errorf(badfsMsg, path, fstype)
return fmt.Errorf(badfsMsgFmt, path, fstype)
}
}
return nil
Expand Down
12 changes: 0 additions & 12 deletions pkg/blueprint/disk_customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,6 @@ func TestPartitioningLayoutConstraints(t *testing.T) {
"unhappy-btrfs+lvm": {
partitioning: &blueprint.DiskCustomization{
Partitions: []blueprint.PartitionCustomization{
{
Type: "ext4",
FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{
Mountpoint: "/data",
},
},
{
Type: "btrfs",
BtrfsVolumeCustomization: blueprint.BtrfsVolumeCustomization{
Expand Down Expand Up @@ -1278,12 +1272,6 @@ func TestPartitionCustomizationUnmarshalJSON(t *testing.T) {
"mountpoint": "/home",
"label": "home",
"fs_type": "ext4"
},
{
"name": "loglv",
"mountpoint": "/var/log",
"label": "log",
"fs_type": "xfs"
}
]
}`,
Expand Down
18 changes: 7 additions & 11 deletions pkg/disk/partition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,17 +1000,17 @@ func EnsureRootFilesystem(pt *PartitionTable, defaultFsType FSType) error {
// partition to the end of the existing partition table therefore it is best to
// call this function early to put boot near the front (as is conventional).
func AddBootPartition(pt *PartitionTable, bootFsType FSType) error {
if bootFsType == FS_NONE {
return fmt.Errorf("error creating boot partition: no filesystem type")
}

// collect all labels to avoid conflicts
labels := make(map[string]bool)
_ = pt.ForEachMountable(func(mnt Mountable, path []Entity) error {
labels[mnt.GetFSSpec().Label] = true
return nil
})

if bootFsType == FS_NONE {
return fmt.Errorf("error creating boot partition: no filesystem type")
}

bootLabel, err := genUniqueString("boot", labels)
if err != nil {
return fmt.Errorf("error creating boot partition: %w", err)
Expand Down Expand Up @@ -1158,12 +1158,8 @@ func (options *CustomPartitionTableOptions) getfstype(fstype string) (string, er
// NewCustomPartitionTable creates a partition table based almost entirely on the disk customizations from a blueprint.
func NewCustomPartitionTable(customizations *blueprint.DiskCustomization, options *CustomPartitionTableOptions, rng *rand.Rand) (*PartitionTable, error) {
if options == nil {
// init options with defaults
options = &CustomPartitionTableOptions{
PartitionTableType: PT_GPT,
}
options = &CustomPartitionTableOptions{}
}

if customizations == nil {
customizations = &blueprint.DiskCustomization{}
}
Expand Down Expand Up @@ -1255,7 +1251,7 @@ func addPlainPartition(pt *PartitionTable, partition blueprint.PartitionCustomiz
}
partType, err := getPartitionTypeIDfor(pt.Type, typeName)
if err != nil {
return fmt.Errorf("error creating root partition: %w", err)
return fmt.Errorf("error getting partition type ID for %q: %w", partition.Mountpoint, err)
}
newpart := Partition{
Type: partType,
Expand All @@ -1275,7 +1271,7 @@ func addPlainPartition(pt *PartitionTable, partition blueprint.PartitionCustomiz
func addLVMPartition(pt *PartitionTable, partition blueprint.PartitionCustomization, options *CustomPartitionTableOptions) error {
vgname := partition.Name
if vgname == "" {
// count existing volume groups and generate unique name
// get existing volume groups and generate unique name
existing := make(map[string]bool)
for _, part := range pt.Partitions {
vg, ok := part.Payload.(*LVMVolumeGroup)
Expand Down

0 comments on commit db5eda7

Please sign in to comment.