Skip to content

Commit

Permalink
Add builder.AddDisk()
Browse files Browse the repository at this point in the history
  • Loading branch information
c4rt0 committed Oct 23, 2023
1 parent 9376cce commit 0bc49aa
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions mantle/kola/tests/ignition/qemufailure.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,38 @@ func GetTempdir(dirname string) (string, error) {
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")
}

tempDir, err := GetTempdir("tmp")
// Config which theoretically aims to reference fakeboot disk
fakeConfig, err := conf.EmptyIgnition().Render(conf.FailWarnings)
if err != nil {
fmt.Println("Error getting temp directory:", err)
}
fmt.Println("Temp directory:", tempDir)
cmd := exec.Command(tempDir, "-c", fmt.Sprintf(`set -euo pipefail;
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)
return errors.Wrapf(err, "creating empty config")
} else {

tempDir, err := GetTempdir("tmp")
if err != nil {
fmt.Println("Error getting temp directory:", err)
}
fmt.Println("Temp directory:", tempDir)
cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf(`set -euo pipefail;
mkdir -p %s
truncate -s 1G fakeboot
mkfs.ext4 -L boot fakeboot
`, tempDir))
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,
})
Expand All @@ -172,14 +179,32 @@ func bootfsFailure(c cluster.TestCluster) error {
}
defer inst.Destroy()

builder2 := platform.NewQemuBuilder()
defer builder2.Close()
builder2.SetConfig(fakeConfig) // how to fakeboot?
err = builder2.AddDisk(&platform.Disk{
BackingFile: kola.QEMUOptions.DiskImage,
})

if err != nil {
return err
}
builder2.MemoryMiB = 1024
builder2.Firmware = kola.QEMUOptions.Firmware
inst2, err := builder2.Exec()
if err != nil {
return err
}
defer inst2.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")
err = fmt.Errorf("bootfs unexpectedly succeeded")
} else if err == platform.ErrInitramfsEmergency {
// The expected case
err = nil
Expand Down

0 comments on commit 0bc49aa

Please sign in to comment.