Skip to content

Commit

Permalink
Add GetTempDir function
Browse files Browse the repository at this point in the history
  • Loading branch information
c4rt0 committed Oct 23, 2023
1 parent 16d6714 commit 9376cce
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions mantle/kola/tests/ignition/qemufailure.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"time"

"github.com/pkg/errors"
Expand All @@ -34,16 +35,19 @@ func init() {
register.RegisterTest(&register.Test{
Name: "coreos.ignition.failure",
Description: "Verify ignition will fail with unsupported action.",
Run: runIgnitionTestGroup,
Run: runIgnitionFailure,
ClusterSize: 0,
Platforms: []string{"qemu"},
Tags: []string{"ignition"},
})
register.RegisterTest(&register.Test{
Name: "coreos.ignition.uniquebootfs",
Description: "Verify there is only one bootfs.",
Run: runBootfsFailure,
ClusterSize: 0,
Platforms: []string{"qemu"},
Tags: []string{"ignition"},
})
}

func runIgnitionTestGroup(c cluster.TestCluster) {
c.Run("ignition", runIgnitionFailure)
c.Run("bootfs", runBootfsFailure)
}

func runIgnitionFailure(c cluster.TestCluster) {
Expand Down Expand Up @@ -115,14 +119,30 @@ func ignitionFailure(c cluster.TestCluster) error {
}
}

// get current path and create tmp dir
func GetTempdir(dirname string) (string, error) {
dir, err := os.Getwd()
if err != nil {
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)
if err != nil {
return errors.Wrapf(err, "creating empty config")
}
cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf(`set -euo pipefail;

tempDir, err := GetTempdir("tmp")
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;

Check failure on line 145 in mantle/kola/tests/ignition/qemufailure.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
truncate -s 1G fakeboot
mkfs.ext4 -L boot fakeboot
`))
Expand All @@ -136,9 +156,11 @@ func bootfsFailure(c cluster.TestCluster) error {
builder := platform.NewQemuBuilder()
defer builder.Close()
builder.SetConfig(failConfig)

err = builder.AddBootDisk(&platform.Disk{
BackingFile: kola.QEMUOptions.DiskImage,
})

if err != nil {
return err
}
Expand Down

0 comments on commit 9376cce

Please sign in to comment.