Skip to content

Commit 9376cce

Browse files
committed
Add GetTempDir function
1 parent 16d6714 commit 9376cce

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

mantle/kola/tests/ignition/qemufailure.go

+29-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"os"
2121
"os/exec"
22+
"path/filepath"
2223
"time"
2324

2425
"github.com/pkg/errors"
@@ -34,16 +35,19 @@ func init() {
3435
register.RegisterTest(&register.Test{
3536
Name: "coreos.ignition.failure",
3637
Description: "Verify ignition will fail with unsupported action.",
37-
Run: runIgnitionTestGroup,
38+
Run: runIgnitionFailure,
39+
ClusterSize: 0,
40+
Platforms: []string{"qemu"},
41+
Tags: []string{"ignition"},
42+
})
43+
register.RegisterTest(&register.Test{
44+
Name: "coreos.ignition.uniquebootfs",
45+
Description: "Verify there is only one bootfs.",
46+
Run: runBootfsFailure,
3847
ClusterSize: 0,
3948
Platforms: []string{"qemu"},
4049
Tags: []string{"ignition"},
4150
})
42-
}
43-
44-
func runIgnitionTestGroup(c cluster.TestCluster) {
45-
c.Run("ignition", runIgnitionFailure)
46-
c.Run("bootfs", runBootfsFailure)
4751
}
4852

4953
func runIgnitionFailure(c cluster.TestCluster) {
@@ -115,14 +119,30 @@ func ignitionFailure(c cluster.TestCluster) error {
115119
}
116120
}
117121

122+
// get current path and create tmp dir
123+
func GetTempdir(dirname string) (string, error) {
124+
dir, err := os.Getwd()
125+
if err != nil {
126+
return "", err
127+
}
128+
path := filepath.Join(dir, dirname)
129+
return path, nil
130+
}
131+
118132
func bootfsFailure(c cluster.TestCluster) error {
119133
// We can't create files in / due to the immutable bit OSTree creates, so
120134
// this is a convenient way to test Ignition failure.
121135
failConfig, err := conf.EmptyIgnition().Render(conf.FailWarnings)
122136
if err != nil {
123137
return errors.Wrapf(err, "creating empty config")
124138
}
125-
cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf(`set -euo pipefail;
139+
140+
tempDir, err := GetTempdir("tmp")
141+
if err != nil {
142+
fmt.Println("Error getting temp directory:", err)
143+
}
144+
fmt.Println("Temp directory:", tempDir)
145+
cmd := exec.Command(tempDir, "-c", fmt.Sprintf(`set -euo pipefail;
126146
truncate -s 1G fakeboot
127147
mkfs.ext4 -L boot fakeboot
128148
`))
@@ -136,9 +156,11 @@ func bootfsFailure(c cluster.TestCluster) error {
136156
builder := platform.NewQemuBuilder()
137157
defer builder.Close()
138158
builder.SetConfig(failConfig)
159+
139160
err = builder.AddBootDisk(&platform.Disk{
140161
BackingFile: kola.QEMUOptions.DiskImage,
141162
})
163+
142164
if err != nil {
143165
return err
144166
}

0 commit comments

Comments
 (0)