Skip to content

Commit

Permalink
pkg/osbuild: clean up genMountsForBootupd
Browse files Browse the repository at this point in the history
Instead of the if statement, I switched to switch (pun absolutely
intended). Also, I fixed the error message, previously it always
printed type <nil>, because mnt is set to nil, if ok == false.
  • Loading branch information
ondrejbudai authored and achilleas-k committed May 14, 2024
1 parent 9316652 commit 8373145
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/osbuild/bootupd_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"sort"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/disk"
)

Expand Down Expand Up @@ -85,19 +86,19 @@ func genMountsForBootupd(source string, pt *disk.PartitionTable) ([]Mount, error
if part.Payload == nil {
continue
}
// TODO: support things like LVM here via supporting "disk.Container"
mnt, ok := part.Payload.(disk.Mountable)
if !ok {
return nil, fmt.Errorf("type %v not supported by bootupd handling yet", mnt)
}

partNum := idx + 1
mount, err := genOsbuildMount(source, mnt)
if err != nil {
return nil, err
// TODO: support things like LVM here via supporting "disk.Container"
switch payload := part.Payload.(type) {
case disk.Mountable:
mount, err := genOsbuildMount(source, payload)
if err != nil {
return nil, err
}
mount.Partition = common.ToPtr(idx + 1)
mounts = append(mounts, *mount)
default:
return nil, fmt.Errorf("type %T not supported by bootupd handling yet", part.Payload)
}
mount.Partition = &partNum
mounts = append(mounts, *mount)
}
// this must be sorted in so that mounts do not shadow each other
sort.Slice(mounts, func(i, j int) bool {
Expand Down
13 changes: 13 additions & 0 deletions pkg/osbuild/bootupd_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ func TestGenBootupdDevicesMountsMissingRoot(t *testing.T) {
assert.EqualError(t, err, "required mounts for bootupd stage [/ /boot /boot/efi] missing")
}

func TestGenBootupdDevicesMountsUnexpectedEntity(t *testing.T) {
filename := "fake-disk.img"
pt := &disk.PartitionTable{
Partitions: []disk.Partition{
{
Payload: &disk.LVMVolumeGroup{},
},
},
}
_, _, err := osbuild.GenBootupdDevicesMounts(filename, pt)
assert.EqualError(t, err, "type *disk.LVMVolumeGroup not supported by bootupd handling yet")
}

var fakePt = &disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Expand Down

0 comments on commit 8373145

Please sign in to comment.