Skip to content

Commit

Permalink
manifest: Add checks for the rootfs stages
Browse files Browse the repository at this point in the history
Add tests to make sure the squashfs or erofs (without squashfs) stages
are present in the manifest when the RootfsType is set.
  • Loading branch information
bcl committed Jan 10, 2025
1 parent 4c436fa commit 9cc0d18
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions pkg/manifest/anaconda_installer_iso_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"crypto/sha256"
"fmt"
"math/rand"
"slices"
"strings"
"testing"

"github.com/osbuild/images/internal/common"
Expand Down Expand Up @@ -71,6 +73,16 @@ func newTestAnacondaISOTree() *AnacondaInstallerISOTree {
return pipeline
}

// Helper to return a comma separated string of the stage names
// used to help debug failures
func dumpStages(stages []*osbuild.Stage) string {
var stageNames []string
for _, stage := range stages {
stageNames = append(stageNames, stage.Type)
}
return strings.Join(stageNames, ", ")
}

func checkISOTreeStages(stages []*osbuild.Stage, expected, exclude []string) error {
commonStages := []string{
"org.osbuild.mkdir",
Expand All @@ -83,6 +95,13 @@ func checkISOTreeStages(stages []*osbuild.Stage, expected, exclude []string) err
"org.osbuild.discinfo",
}

// Remove excluded stages from common
for _, exlStage := range exclude {
if idx := slices.Index(commonStages, exlStage); idx > -1 {
commonStages = slices.Delete(commonStages, idx, idx+1)
}
}

for _, expStage := range append(commonStages, expected...) {
if findStage(expStage, stages) == nil {
return fmt.Errorf("did not find expected stage: %s", expStage)
Expand Down Expand Up @@ -404,6 +423,31 @@ func TestAnacondaISOTreeSerializeWithOS(t *testing.T) {
pipeline.serializeStart(nil, nil, nil, nil)
assert.Panics(t, func() { pipeline.serialize() })
})

t.Run("plain+squashfs-rootfs", func(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.OSPipeline = osPayload
pipeline.RootfsType = SquashfsRootfs
pipeline.serializeStart(nil, nil, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, payloadStages,
append(variantStages, []string{"org.osbuild.kickstart", "org.osbuild.isolinux"}...)),
dumpStages(sp.Stages))
})

t.Run("plain+erofs-rootfs", func(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.OSPipeline = osPayload
pipeline.RootfsType = ErofsRootfs
pipeline.serializeStart(nil, nil, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages,
append(payloadStages, []string{"org.osbuild.erofs"}...),
append(variantStages, []string{"org.osbuild.kickstart", "org.osbuild.isolinux", "org.osbuild.squashfs"}...)),
dumpStages(sp.Stages))
})
}

func TestAnacondaISOTreeSerializeWithOSTree(t *testing.T) {
Expand Down Expand Up @@ -524,6 +568,31 @@ func TestAnacondaISOTreeSerializeWithOSTree(t *testing.T) {
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit}, nil)
assert.Panics(t, func() { pipeline.serialize() })
})

t.Run("plain+squashfs-rootfs", func(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.RootfsType = SquashfsRootfs
pipeline.Kickstart = &kickstart.Options{Path: testKsPath, OSTree: &kickstart.OSTree{}}
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit}, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, payloadStages,
append(variantStages, "org.osbuild.isolinux")),
dumpStages(sp.Stages))
})

t.Run("plain+erofs-erofs", func(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.RootfsType = ErofsRootfs
pipeline.Kickstart = &kickstart.Options{Path: testKsPath, OSTree: &kickstart.OSTree{}}
pipeline.serializeStart(nil, nil, []ostree.CommitSpec{ostreeCommit}, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages,
append(payloadStages, []string{"org.osbuild.erofs"}...),
append(variantStages, []string{"org.osbuild.isolinux", "org.osbuild.squashfs"}...)),
dumpStages(sp.Stages))
})
}

func makeFakeContainerPayload() container.Spec {
Expand Down Expand Up @@ -627,6 +696,31 @@ func TestAnacondaISOTreeSerializeWithContainer(t *testing.T) {
assert.NotNil(t, skopeoStage)
assert.Equal(t, skopeoStage.Options.(*osbuild.SkopeoStageOptions).RemoveSignatures, common.ToPtr(true))
})

t.Run("plain+squashfs-rootfs", func(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.RootfsType = SquashfsRootfs
pipeline.Kickstart = &kickstart.Options{Path: testKsPath}
pipeline.serializeStart(nil, []container.Spec{containerPayload}, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages, payloadStages,
append(variantStages, "org.osbuild.isolinux")),
dumpStages(sp.Stages))
})

t.Run("plain+erofs-rootfs", func(t *testing.T) {
pipeline := newTestAnacondaISOTree()
pipeline.RootfsType = ErofsRootfs
pipeline.Kickstart = &kickstart.Options{Path: testKsPath}
pipeline.serializeStart(nil, []container.Spec{containerPayload}, nil, nil)
sp := pipeline.serialize()
pipeline.serializeEnd()
assert.NoError(t, checkISOTreeStages(sp.Stages,
append(payloadStages, []string{"org.osbuild.erofs"}...),
append(variantStages, []string{"org.osbuild.isolinux", "org.osbuild.squashfs"}...)),
dumpStages(sp.Stages))
})
}

func TestMakeKickstartSudoersPostEmpty(t *testing.T) {
Expand Down

0 comments on commit 9cc0d18

Please sign in to comment.