From e919872649e69d978af14af412d27f6f87e11589 Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Tue, 31 Oct 2023 18:26:25 +0000 Subject: [PATCH] qemufailure/bootfsFailure modify code to get absolute path --- mantle/kola/tests/ignition/qemufailure.go | 38 ++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/mantle/kola/tests/ignition/qemufailure.go b/mantle/kola/tests/ignition/qemufailure.go index 8646db97d4..5a454a3827 100644 --- a/mantle/kola/tests/ignition/qemufailure.go +++ b/mantle/kola/tests/ignition/qemufailure.go @@ -42,8 +42,11 @@ func init() { }) register.RegisterTest(®ister.Test{ Name: "coreos.unique.boot.failure", + ClusterSize: 0, Description: "Verify boot fails if there are multiple boot filesystems.", + Platforms: []string{"qemu"}, Run: runBootfsFailure, + Tags: []string{"ignition"}, }) } @@ -117,37 +120,44 @@ func ignitionFailure(c cluster.TestCluster) 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" + dirname := "tmp/fakeboot" + bootName := "fakeboot" dir, err := os.Getwd() if err != nil { return err } - tempDir := filepath.Join(dir, dirname) + tempDir := os.Chdir(filepath.Join(dir, dirname)) // Change the current working directory - if err := os.Chdir(tempDir); err != nil { + if err != nil { return err } - bootName := "fakeboot" + fmt.Println("Current dir: ", tempDir) + createBoot, err := os.Create(bootName) if err != nil { return err } + + // Get the absolute path of the file + absPath, err := filepath.Abs(createBoot.Name()) + if err != nil { + fmt.Println("Error getting absolute path:", err) + return err + } + fmt.Println("absPath: ", absPath) // 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) + err = os.Truncate(absPath, oneGB) if err != nil { return err } - cmd := exec.Command("mkfs.ext4", "-L", "boot", createBoot.Name()) - cmd.Stdout = os.Stdout + + cmd := exec.Command("mkfs.ext4", "-L", "boot", absPath) + cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { c.Fatal(err) @@ -155,9 +165,9 @@ func bootfsFailure(c cluster.TestCluster) error { builder := platform.NewQemuBuilder() defer builder.Close() - builder.SetConfig(fakeConfig) + err = builder.AddDisk(&platform.Disk{ - BackingFile: tempDir, + BackingFile: absPath, BackingFormat: "raw", }) if err != nil {