Skip to content

Commit

Permalink
qemufailure/bootfsFailure modify code to get absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
c4rt0 committed Oct 31, 2023
1 parent fca48b0 commit e919872
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions mantle/kola/tests/ignition/qemufailure.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ func init() {
})
register.RegisterTest(&register.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"},
})
}

Expand Down Expand Up @@ -117,47 +120,54 @@ 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)
}

builder := platform.NewQemuBuilder()
defer builder.Close()
builder.SetConfig(fakeConfig)

err = builder.AddDisk(&platform.Disk{
BackingFile: tempDir,
BackingFile: absPath,
BackingFormat: "raw",
})
if err != nil {
Expand Down

0 comments on commit e919872

Please sign in to comment.