treewide: override TMPDIR for tests that use qemu
When running QEMU with snapshot=on set, QEMU creates a copy of the
provided file in $TMPDIR. If $TMPDIR is set to /tmp, it will always
be overridden to /var/tmp. This creates an issue for us, as the
bazel tests only wire up /tmp, with /var/tmp being unaccessible
because of permissions. Bazel provides $TEST_TMPDIR for this
usecase, which we resolve to an absolute path and then override
$TMPDIR.
Change-Id: I767159211d3b3db2aafd0f4fc17d6d6480974f16
Reviewed-on: https://review.monogon.dev/c/monogon/+/4422
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
diff --git a/cloud/agent/takeover/e2e/main_test.go b/cloud/agent/takeover/e2e/main_test.go
index e243d58..2062be7 100644
--- a/cloud/agent/takeover/e2e/main_test.go
+++ b/cloud/agent/takeover/e2e/main_test.go
@@ -14,6 +14,7 @@
"net"
"os"
"os/exec"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -52,6 +53,18 @@
panic(err)
}
}
+ // When running QEMU with snapshot=on set, QEMU creates a copy of the
+ // provided file in $TMPDIR. If $TMPDIR is set to /tmp, it will always
+ // be overridden to /var/tmp. This creates an issue for us, as the
+ // bazel tests only wire up /tmp, with /var/tmp being unaccessible
+ // because of permissions. Bazel provides $TEST_TMPDIR for this
+ // usecase, which we resolve to an absolute path and then override
+ // $TMPDIR.
+ tmpDir, err := filepath.Abs(os.Getenv("TEST_TMPDIR"))
+ if err != nil {
+ panic(err)
+ }
+ os.Setenv("TMPDIR", tmpDir)
}
func TestE2E(t *testing.T) {
diff --git a/metropolis/cli/takeover/e2e/main_test.go b/metropolis/cli/takeover/e2e/main_test.go
index 482752a..556f300 100644
--- a/metropolis/cli/takeover/e2e/main_test.go
+++ b/metropolis/cli/takeover/e2e/main_test.go
@@ -14,6 +14,7 @@
"net"
"os"
"os/exec"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -53,6 +54,18 @@
panic(err)
}
}
+ // When running QEMU with snapshot=on set, QEMU creates a copy of the
+ // provided file in $TMPDIR. If $TMPDIR is set to /tmp, it will always
+ // be overridden to /var/tmp. This creates an issue for us, as the
+ // bazel tests only wire up /tmp, with /var/tmp being unaccessible
+ // because of permissions. Bazel provides $TEST_TMPDIR for this
+ // usecase, which we resolve to an absolute path and then override
+ // $TMPDIR.
+ tmpDir, err := filepath.Abs(os.Getenv("TEST_TMPDIR"))
+ if err != nil {
+ panic(err)
+ }
+ os.Setenv("TMPDIR", tmpDir)
}
const GiB = 1024 * 1024 * 1024
diff --git a/metropolis/installer/test/run_test.go b/metropolis/installer/test/run_test.go
index 3da188a..daff8cd 100644
--- a/metropolis/installer/test/run_test.go
+++ b/metropolis/installer/test/run_test.go
@@ -54,6 +54,18 @@
panic(err)
}
}
+ // When running QEMU with snapshot=on set, QEMU creates a copy of the
+ // provided file in $TMPDIR. If $TMPDIR is set to /tmp, it will always
+ // be overridden to /var/tmp. This creates an issue for us, as the
+ // bazel tests only wire up /tmp, with /var/tmp being unaccessible
+ // because of permissions. Bazel provides $TEST_TMPDIR for this
+ // usecase, which we resolve to an absolute path and then override
+ // $TMPDIR.
+ tmpDir, err := filepath.Abs(os.Getenv("TEST_TMPDIR"))
+ if err != nil {
+ panic(err)
+ }
+ os.Setenv("TMPDIR", tmpDir)
}
// Each variable in this block points to either a test dependency or a side
diff --git a/osbase/bringup/test/run_test.go b/osbase/bringup/test/run_test.go
index 5b9b4cb..03ae71b 100644
--- a/osbase/bringup/test/run_test.go
+++ b/osbase/bringup/test/run_test.go
@@ -5,6 +5,8 @@
import (
"context"
+ "os"
+ "path/filepath"
"testing"
"time"
@@ -36,6 +38,18 @@
panic(err)
}
}
+ // When running QEMU with snapshot=on set, QEMU creates a copy of the
+ // provided file in $TMPDIR. If $TMPDIR is set to /tmp, it will always
+ // be overridden to /var/tmp. This creates an issue for us, as the
+ // bazel tests only wire up /tmp, with /var/tmp being unaccessible
+ // because of permissions. Bazel provides $TEST_TMPDIR for this
+ // usecase, which we resolve to an absolute path and then override
+ // $TMPDIR.
+ tmpDir, err := filepath.Abs(os.Getenv("TEST_TMPDIR"))
+ if err != nil {
+ panic(err)
+ }
+ os.Setenv("TMPDIR", tmpDir)
}
// runQemu starts a new QEMU process, expecting the given output to appear