Skip to content

Commit

Permalink
tests/ignition: Modify qemufailure to include bootfs test
Browse files Browse the repository at this point in the history
See: #2953
  • Loading branch information
c4rt0 committed Oct 18, 2023
1 parent 9b0e7e8 commit 16d6714
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion mantle/kola/tests/ignition/qemufailure.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package ignition
import (
"context"
"fmt"
"os"
"os/exec"
"time"

"github.com/pkg/errors"
Expand All @@ -32,19 +34,30 @@ func init() {
register.RegisterTest(&register.Test{
Name: "coreos.ignition.failure",
Description: "Verify ignition will fail with unsupported action.",
Run: runIgnitionFailure,
Run: runIgnitionTestGroup,
ClusterSize: 0,
Platforms: []string{"qemu"},
Tags: []string{"ignition"},
})
}

func runIgnitionTestGroup(c cluster.TestCluster) {
c.Run("ignition", runIgnitionFailure)
c.Run("bootfs", runBootfsFailure)
}

func runIgnitionFailure(c cluster.TestCluster) {
if err := ignitionFailure(c); err != nil {
c.Fatal(err.Error())
}
}

func runBootfsFailure(c cluster.TestCluster) {
if err := bootfsFailure(c); err != nil {
c.Fatal(err.Error())
}
}

func ignitionFailure(c cluster.TestCluster) error {
// We can't create files in / due to the immutable bit OSTree creates, so
// this is a convenient way to test Ignition failure.
Expand Down Expand Up @@ -101,3 +114,69 @@ func ignitionFailure(c cluster.TestCluster) error {
return nil
}
}

func bootfsFailure(c cluster.TestCluster) error {
// We can't create files in / due to the immutable bit OSTree creates, so
// this is a convenient way to test Ignition failure.
failConfig, err := conf.EmptyIgnition().Render(conf.FailWarnings)
if err != nil {
return errors.Wrapf(err, "creating empty config")
}
cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf(`set -euo pipefail;

Check failure on line 125 in mantle/kola/tests/ignition/qemufailure.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
truncate -s 1G fakeboot
mkfs.ext4 -L boot fakeboot
`))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
c.Fatal(err)
}
// failConfig.AddFile("/notwritable.txt", "Hello world", 0644)

builder := platform.NewQemuBuilder()
defer builder.Close()
builder.SetConfig(failConfig)
err = builder.AddBootDisk(&platform.Disk{
BackingFile: kola.QEMUOptions.DiskImage,
})
if err != nil {
return err
}
builder.MemoryMiB = 1024
builder.Firmware = kola.QEMUOptions.Firmware
inst, err := builder.Exec()
if err != nil {
return err
}
defer inst.Destroy()

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

errchan := make(chan error)
go func() {
err := inst.WaitAll(ctx)
if err == nil {
err = fmt.Errorf("Bootfs unexpectedly succeeded")
} else if err == platform.ErrInitramfsEmergency {
// The expected case
err = nil
} else {
err = errors.Wrapf(err, "expected initramfs emergency.target error")
}
errchan <- err
}()

select {
case <-ctx.Done():
if err := inst.Kill(); err != nil {
return errors.Wrapf(err, "failed to kill the vm instance")
}
return errors.Wrapf(ctx.Err(), "timed out waiting for initramfs error")
case err := <-errchan:
if err != nil {
return err
}
return nil
}
}

0 comments on commit 16d6714

Please sign in to comment.