Skip to content

Commit

Permalink
osbuild: add org.osbuild.bootc.install-to-filesystem support
Browse files Browse the repository at this point in the history
This commit adds support for `org.osbuild.bootc.install-to-filesystem`
from osbuild/osbuild#1547.
  • Loading branch information
mvo5 committed Feb 13, 2024
1 parent 936db51 commit b7febee
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/osbuild/bootc_install_to_filesystem_stage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package osbuild

// NewBootcInstallToFilesystem creates a new stage for the
// org.osbuild.bootc.install-to-filesystem stage.
//
// It requires a mount setup so that bootupd can be run by bootc. I.e
// "/", "/boot" and "/boot/efi" need to be set up so that
// bootc/bootupd find and install all required bootloader bits.
//
// The mounts input should be generated with GenBootupdDevicesMounts.
func NewBootcInstallToFilesystemStage(devices map[string]Device, mounts []Mount) (*Stage, error) {
if err := validateBootupdMounts(mounts); err != nil {
return nil, err
}

return &Stage{
Type: "org.osbuild.bootc.install-to-filesystem",
Devices: devices,
Mounts: mounts,
}, nil
}
82 changes: 82 additions & 0 deletions pkg/osbuild/bootc_install_to_filesystem_stage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package osbuild_test

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/osbuild/images/pkg/osbuild"
)

func TestBootcInstallToFilesystemStageNewHappy(t *testing.T) {
devices := makeOsbuildDevices("dev-for-/", "dev-for-/boot", "dev-for-/boot/efi")
mounts := makeOsbuildMounts("/", "/boot", "/boot/efi")

expectedStage := &osbuild.Stage{
Type: "org.osbuild.bootc.install-to-filesystem",
Devices: devices,
Mounts: mounts,
}
stage, err := osbuild.NewBootcInstallToFilesystemStage(devices, mounts)
require.Nil(t, err)
assert.Equal(t, stage, expectedStage)
}

func TestBootcInstallToFilesystemStageMissingMounts(t *testing.T) {
devices := makeOsbuildDevices("dev-for-/")
mounts := makeOsbuildMounts("/")

stage, err := osbuild.NewBootcInstallToFilesystemStage(devices, mounts)
// XXX: rename error
assert.ErrorContains(t, err, "required mounts for bootupd stage [/boot /boot/efi] missing")
require.Nil(t, stage)
}

func TestBootcInstallToFilesystemStageJsonHappy(t *testing.T) {
devices := makeOsbuildDevices("disk", "dev-for-/", "dev-for-/boot", "dev-for-/boot/efi")
mounts := makeOsbuildMounts("/", "/boot", "/boot/efi")

stage, err := osbuild.NewBootcInstallToFilesystemStage(devices, mounts)
require.Nil(t, err)
stageJson, err := json.MarshalIndent(stage, "", " ")
require.Nil(t, err)
assert.Equal(t, string(stageJson), `{
"type": "org.osbuild.bootc.install-to-filesystem",
"devices": {
"dev-for-/": {
"type": "org.osbuild.loopback"
},
"dev-for-/boot": {
"type": "org.osbuild.loopback"
},
"dev-for-/boot/efi": {
"type": "org.osbuild.loopback"
},
"disk": {
"type": "org.osbuild.loopback"
}
},
"mounts": [
{
"name": "mnt-for-/",
"type": "org.osbuild.ext4",
"source": "dev-for-/",
"target": "/"
},
{
"name": "mnt-for-/boot",
"type": "org.osbuild.ext4",
"source": "dev-for-/boot",
"target": "/boot"
},
{
"name": "mnt-for-/boot/efi",
"type": "org.osbuild.ext4",
"source": "dev-for-/boot/efi",
"target": "/boot/efi"
}
]
}`)
}

0 comments on commit b7febee

Please sign in to comment.