From fca48b0b269eb423fedbc2dd0b1bbafd84bb3156 Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Wed, 25 Oct 2023 23:38:23 +0100 Subject: [PATCH] Move truncate to native golang --- mantle/kola/tests/ignition/qemufailure.go | 97 +++++++++-------------- 1 file changed, 39 insertions(+), 58 deletions(-) diff --git a/mantle/kola/tests/ignition/qemufailure.go b/mantle/kola/tests/ignition/qemufailure.go index feb08e7c97..8646db97d4 100644 --- a/mantle/kola/tests/ignition/qemufailure.go +++ b/mantle/kola/tests/ignition/qemufailure.go @@ -41,12 +41,9 @@ func init() { Tags: []string{"ignition"}, }) register.RegisterTest(®ister.Test{ - Name: "coreos.ignition.uniquebootfs", - Description: "Verify there is only one bootfs.", + Name: "coreos.unique.boot.failure", + Description: "Verify boot fails if there are multiple boot filesystems.", Run: runBootfsFailure, - ClusterSize: 0, - Platforms: []string{"qemu"}, - Tags: []string{"ignition"}, }) } @@ -119,51 +116,53 @@ func ignitionFailure(c cluster.TestCluster) error { } } -// get current path and create tmp dir -func GetTempdir(dirname string) (string, error) { +func bootfsFailure(c cluster.TestCluster) error { + // Create fakeboot disk + fakeConfig, err := conf.EmptyIgnition().Render(conf.FailWarnings) + if err != nil { + return errors.Wrapf(err, "creating empty config") + } + // get current path and create tmp dir + dirname := "tmp" dir, err := os.Getwd() if err != nil { - return "", err + return err } - path := filepath.Join(dir, dirname) - return path, 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) + tempDir := filepath.Join(dir, dirname) + // Change the current working directory + if err := os.Chdir(tempDir); err != nil { + return err + } + bootName := "fakeboot" + createBoot, err := os.Create(bootName) if err != nil { - return errors.Wrapf(err, "creating empty config") + return err } - - // Config which theoretically aims to reference fakeboot disk - fakeConfig, err := conf.EmptyIgnition().Render(conf.FailWarnings) + // Truncate the file to 1 gigabyte + // 1<<30 is a way to represent 1gb in terms of bytes + // (bitwise left shift operation) + const oneGB = 1 << 30 + err = os.Truncate(createBoot.Name(), oneGB) if err != nil { - 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) - } + return err + } + cmd := exec.Command("mkfs.ext4", "-L", "boot", createBoot.Name()) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + c.Fatal(err) } builder := platform.NewQemuBuilder() defer builder.Close() - builder.SetConfig(failConfig) + builder.SetConfig(fakeConfig) + err = builder.AddDisk(&platform.Disk{ + BackingFile: tempDir, + BackingFormat: "raw", + }) + if err != nil { + return err + } err = builder.AddBootDisk(&platform.Disk{ BackingFile: kola.QEMUOptions.DiskImage, }) @@ -179,24 +178,6 @@ 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()