Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move truncate to native golang
Browse files Browse the repository at this point in the history
c4rt0 committed Oct 25, 2023
1 parent 0bc49aa commit fca48b0
Showing 1 changed file with 39 additions and 58 deletions.
97 changes: 39 additions & 58 deletions mantle/kola/tests/ignition/qemufailure.go
Original file line number Diff line number Diff line change
@@ -41,12 +41,9 @@ func init() {
Tags: []string{"ignition"},
})
register.RegisterTest(&register.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()

0 comments on commit fca48b0

Please sign in to comment.