treewide: replace hardcoded runfiles paths
We hardcoded some of the runfiles paths to find specific files. This replaces the hardcoded paths by a call to rlocationpath. This prevents running a target without the correct dependencies at build time instead of at runtime
Change-Id: I7ce56935ac80be6b28b824ccb0781ab401bd6521
Reviewed-on: https://review.monogon.dev/c/monogon/+/3301
Reviewed-by: Serge Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/test/e2e/suites/core/BUILD.bazel b/metropolis/test/e2e/suites/core/BUILD.bazel
index e3ccc59..a8c90ad 100644
--- a/metropolis/test/e2e/suites/core/BUILD.bazel
+++ b/metropolis/test/e2e/suites/core/BUILD.bazel
@@ -4,9 +4,7 @@
name = "core_test",
srcs = ["run_test.go"],
data = [
- "//metropolis/node:image",
"//metropolis/test/e2e:testimages_manifest",
- "//third_party/edk2:firmware",
],
tags = [
"resources:iops:5000",
@@ -14,6 +12,9 @@
# 2x2048 for nodes plus some extra.
"resources:ram:4500",
],
+ x_defs = {
+ "xTestImagesManifestPath": "$(rlocationpath //metropolis/test/e2e:testimages_manifest )",
+ },
deps = [
"//metropolis/node",
"//metropolis/node/core/rpc",
diff --git a/metropolis/test/e2e/suites/core/run_test.go b/metropolis/test/e2e/suites/core/run_test.go
index 21640a6..c8f654f 100644
--- a/metropolis/test/e2e/suites/core/run_test.go
+++ b/metropolis/test/e2e/suites/core/run_test.go
@@ -28,6 +28,25 @@
cpb "source.monogon.dev/metropolis/proto/common"
)
+var (
+ // These are filled by bazel at linking time with the canonical path of
+ // their corresponding file. Inside the init function we resolve it
+ // with the rules_go runfiles package to the real path.
+ xTestImagesManifestPath string
+)
+
+func init() {
+ var err error
+ for _, path := range []*string{
+ &xTestImagesManifestPath,
+ } {
+ *path, err = runfiles.Rlocation(*path)
+ if err != nil {
+ panic(err)
+ }
+ }
+}
+
const (
// Timeout for the global test context.
//
@@ -49,11 +68,7 @@
ctx, cancel := context.WithTimeout(context.Background(), globalTestTimeout)
defer cancel()
- rPath, err := runfiles.Rlocation("_main/metropolis/test/e2e/testimages_manifest.prototxt")
- if err != nil {
- t.Fatalf("Resolving registry manifest failed: %v", err)
- }
- df, err := os.ReadFile(rPath)
+ df, err := os.ReadFile(xTestImagesManifestPath)
if err != nil {
t.Fatalf("Reading registry manifest failed: %v", err)
}
diff --git a/metropolis/test/e2e/suites/ha/BUILD.bazel b/metropolis/test/e2e/suites/ha/BUILD.bazel
index 5a2a4dd..3d9c688 100644
--- a/metropolis/test/e2e/suites/ha/BUILD.bazel
+++ b/metropolis/test/e2e/suites/ha/BUILD.bazel
@@ -4,9 +4,7 @@
name = "ha_test",
srcs = ["run_test.go"],
data = [
- "//metropolis/node:image",
"//metropolis/test/e2e:testimages_manifest",
- "//third_party/edk2:firmware",
],
tags = [
"resources:iops:5000",
@@ -14,6 +12,9 @@
# 3x2048 for nodes plus some extra.
"resources:ram:7000",
],
+ x_defs = {
+ "xTestImagesManifestPath": "$(rlocationpath //metropolis/test/e2e:testimages_manifest )",
+ },
deps = [
"//metropolis/test/launch",
"//metropolis/test/localregistry",
diff --git a/metropolis/test/e2e/suites/ha/run_test.go b/metropolis/test/e2e/suites/ha/run_test.go
index cc02df4..f2f7cc2 100644
--- a/metropolis/test/e2e/suites/ha/run_test.go
+++ b/metropolis/test/e2e/suites/ha/run_test.go
@@ -15,6 +15,25 @@
"source.monogon.dev/osbase/test/launch"
)
+var (
+ // These are filled by bazel at linking time with the canonical path of
+ // their corresponding file. Inside the init function we resolve it
+ // with the rules_go runfiles package to the real path.
+ xTestImagesManifestPath string
+)
+
+func init() {
+ var err error
+ for _, path := range []*string{
+ &xTestImagesManifestPath,
+ } {
+ *path, err = runfiles.Rlocation(*path)
+ if err != nil {
+ panic(err)
+ }
+ }
+}
+
const (
// Timeout for the global test context.
//
@@ -35,11 +54,7 @@
ctx, cancel := context.WithTimeout(context.Background(), globalTestTimeout)
defer cancel()
- rPath, err := runfiles.Rlocation("_main/metropolis/test/e2e/testimages_manifest.prototxt")
- if err != nil {
- t.Fatalf("Resolving registry manifest failed: %v", err)
- }
- df, err := os.ReadFile(rPath)
+ df, err := os.ReadFile(xTestImagesManifestPath)
if err != nil {
t.Fatalf("Reading registry manifest failed: %v", err)
}
diff --git a/metropolis/test/e2e/suites/kubernetes/BUILD.bazel b/metropolis/test/e2e/suites/kubernetes/BUILD.bazel
index 6234e94..302f3ac 100644
--- a/metropolis/test/e2e/suites/kubernetes/BUILD.bazel
+++ b/metropolis/test/e2e/suites/kubernetes/BUILD.bazel
@@ -20,9 +20,7 @@
name = "kubernetes_test",
srcs = ["run_test.go"],
data = [
- "//metropolis/node:image",
"//metropolis/test/e2e:testimages_manifest",
- "//third_party/edk2:firmware",
],
embed = [":kubernetes"],
tags = [
@@ -31,6 +29,9 @@
# 2x2048 for nodes plus some extra.
"resources:ram:4500",
],
+ x_defs = {
+ "xTestImagesManifestPath": "$(rlocationpath //metropolis/test/e2e:testimages_manifest )",
+ },
deps = [
"//metropolis/node",
"//metropolis/test/launch",
diff --git a/metropolis/test/e2e/suites/kubernetes/run_test.go b/metropolis/test/e2e/suites/kubernetes/run_test.go
index f15fafd..3608c3c 100644
--- a/metropolis/test/e2e/suites/kubernetes/run_test.go
+++ b/metropolis/test/e2e/suites/kubernetes/run_test.go
@@ -30,6 +30,25 @@
common "source.monogon.dev/metropolis/node"
)
+var (
+ // These are filled by bazel at linking time with the canonical path of
+ // their corresponding file. Inside the init function we resolve it
+ // with the rules_go runfiles package to the real path.
+ xTestImagesManifestPath string
+)
+
+func init() {
+ var err error
+ for _, path := range []*string{
+ &xTestImagesManifestPath,
+ } {
+ *path, err = runfiles.Rlocation(*path)
+ if err != nil {
+ panic(err)
+ }
+ }
+}
+
const (
// Timeout for the global test context.
//
@@ -50,11 +69,7 @@
ctx, cancel := context.WithTimeout(context.Background(), globalTestTimeout)
defer cancel()
- rPath, err := runfiles.Rlocation("_main/metropolis/test/e2e/testimages_manifest.prototxt")
- if err != nil {
- t.Fatalf("Resolving registry manifest failed: %v", err)
- }
- df, err := os.ReadFile(rPath)
+ df, err := os.ReadFile(xTestImagesManifestPath)
if err != nil {
t.Fatalf("Reading registry manifest failed: %v", err)
}