disk: add new GenImageKernelOptions helper
This creates the needed kernel options for an image, if any, based on the partition table. Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
This commit is contained in:
parent
54a4616a7d
commit
2c6e726c94
2 changed files with 56 additions and 0 deletions
|
|
@ -63,3 +63,19 @@ func GenImagePrepareStages(pt *disk.PartitionTable, filename string) []*Stage {
|
|||
func GenImageFinishStages(pt *disk.PartitionTable, filename string) []*Stage {
|
||||
return GenDeviceFinishStages(pt, filename)
|
||||
}
|
||||
|
||||
func GenImageKernelOptions(pt *disk.PartitionTable) []string {
|
||||
cmdline := make([]string, 0)
|
||||
|
||||
genOptions := func(e disk.Entity, path []disk.Entity) error {
|
||||
switch ent := e.(type) {
|
||||
case *disk.LUKSContainer:
|
||||
karg := "luks.uuid=" + ent.UUID
|
||||
cmdline = append(cmdline, karg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
_ = pt.ForEachEntity(genOptions)
|
||||
return cmdline
|
||||
}
|
||||
|
|
|
|||
40
internal/osbuild2/disk_test.go
Normal file
40
internal/osbuild2/disk_test.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package osbuild2
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGenImageKernelOptions(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
// math/rand is good enough in this case
|
||||
/* #nosec G404 */
|
||||
rng := rand.New(rand.NewSource(13))
|
||||
|
||||
luks_lvm := testPartitionTables["luks+lvm"]
|
||||
|
||||
pt, err := disk.NewPartitionTable(&luks_lvm, []blueprint.FilesystemCustomization{}, 0, rng)
|
||||
assert.NoError(err)
|
||||
|
||||
var uuid string
|
||||
|
||||
findLuksUUID := func(e disk.Entity, path []disk.Entity) error {
|
||||
switch ent := e.(type) {
|
||||
case *disk.LUKSContainer:
|
||||
uuid = ent.UUID
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
_ = pt.ForEachEntity(findLuksUUID)
|
||||
|
||||
assert.NotEmpty(uuid, "Could not find LUKS container")
|
||||
cmdline := GenImageKernelOptions(pt)
|
||||
|
||||
assert.Subset(cmdline, []string{"luks.uuid=" + uuid})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue