From 0bc49aad7def77fa5228d4cb87f8c26aae71d24b Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Mon, 23 Oct 2023 17:44:26 +0100 Subject: [PATCH] Add builder.AddDisk() --- mantle/kola/tests/ignition/qemufailure.go | 55 ++++++++++++++++------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/mantle/kola/tests/ignition/qemufailure.go b/mantle/kola/tests/ignition/qemufailure.go index d829d7b5fa..feb08e7c97 100644 --- a/mantle/kola/tests/ignition/qemufailure.go +++ b/mantle/kola/tests/ignition/qemufailure.go @@ -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, }) @@ -172,6 +179,24 @@ 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() @@ -179,7 +204,7 @@ func bootfsFailure(c cluster.TestCluster) 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