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/cloud/agent/e2e/BUILD.bazel b/cloud/agent/e2e/BUILD.bazel
index 0fbc1ba..39dd031 100644
--- a/cloud/agent/e2e/BUILD.bazel
+++ b/cloud/agent/e2e/BUILD.bazel
@@ -6,9 +6,17 @@
data = [
"//cloud/agent/takeover:initramfs",
"//metropolis/installer/test/testos:testos_bundle",
- "//third_party/edk2:firmware",
+ "//third_party/edk2:OVMF_CODE.fd",
+ "//third_party/edk2:OVMF_VARS.fd",
"//third_party/linux",
],
+ x_defs = {
+ "xBundleFilePath": "$(rlocationpath //metropolis/installer/test/testos:testos_bundle )",
+ "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
+ "xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
+ "xKernelPath": "$(rlocationpath //third_party/linux )",
+ "xInitramfsOrigPath": "$(rlocationpath //cloud/agent/takeover:initramfs )",
+ },
deps = [
"//cloud/agent/api",
"//cloud/bmaas/server/api",
diff --git a/cloud/agent/e2e/main_test.go b/cloud/agent/e2e/main_test.go
index ec1ee0c..dcde625 100644
--- a/cloud/agent/e2e/main_test.go
+++ b/cloud/agent/e2e/main_test.go
@@ -34,6 +34,30 @@
"source.monogon.dev/osbase/pki"
)
+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.
+ xBundleFilePath string
+ xOvmfVarsPath string
+ xOvmfCodePath string
+ xKernelPath string
+ xInitramfsOrigPath string
+)
+
+func init() {
+ var err error
+ for _, path := range []*string{
+ &xBundleFilePath, &xOvmfVarsPath, &xOvmfCodePath,
+ &xKernelPath, &xInitramfsOrigPath,
+ } {
+ *path, err = runfiles.Rlocation(*path)
+ if err != nil {
+ panic(err)
+ }
+ }
+}
+
type fakeServer struct {
hardwareReport *bpb.AgentHardwareReport
installationRequest *bpb.OSInstallationRequest
@@ -139,12 +163,9 @@
grpcListenAddr := grpcLis.Addr().(*net.TCPAddr)
m := http.NewServeMux()
- bundleFilePath, err := runfiles.Rlocation("_main/metropolis/installer/test/testos/testos_bundle.zip")
- if err != nil {
- t.Fatal(err)
- }
+
m.HandleFunc("/bundle.bin", func(w http.ResponseWriter, req *http.Request) {
- http.ServeFile(w, req, bundleFilePath)
+ http.ServeFile(w, req, xBundleFilePath)
})
blobLis, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
@@ -178,23 +199,7 @@
t.Fatalf("ftruncate failed: %v", err)
}
- ovmfVarsPath, err := runfiles.Rlocation("edk2/OVMF_VARS.fd")
- if err != nil {
- t.Fatal(err)
- }
- ovmfCodePath, err := runfiles.Rlocation("edk2/OVMF_CODE.fd")
- if err != nil {
- t.Fatal(err)
- }
- kernelPath, err := runfiles.Rlocation("_main/third_party/linux/bzImage")
- if err != nil {
- t.Fatal(err)
- }
- initramfsOrigPath, err := runfiles.Rlocation("_main/cloud/agent/takeover/initramfs.cpio.zst")
- if err != nil {
- t.Fatal(err)
- }
- initramfsOrigFile, err := os.Open(initramfsOrigPath)
+ initramfsOrigFile, err := os.Open(xInitramfsOrigPath)
if err != nil {
t.Fatal(err)
}
@@ -235,7 +240,7 @@
if err != nil {
t.Fatal(err)
}
- ovmfVarsTmpl, err := os.Open(ovmfVarsPath)
+ ovmfVarsTmpl, err := os.Open(xOvmfVarsPath)
if err != nil {
t.Fatal(err)
}
@@ -246,7 +251,7 @@
qemuArgs := []string{
"-machine", "q35", "-accel", "kvm", "-nographic", "-nodefaults", "-m", "1024",
"-cpu", "host", "-smp", "sockets=1,cpus=1,cores=2,threads=2,maxcpus=4",
- "-drive", "if=pflash,format=raw,readonly=on,file=" + ovmfCodePath,
+ "-drive", "if=pflash,format=raw,readonly=on,file=" + xOvmfCodePath,
"-drive", "if=pflash,format=raw,file=" + ovmfVars.Name(),
"-drive", "if=virtio,format=raw,cache=unsafe,file=" + rootDisk.Name(),
"-netdev", fmt.Sprintf("user,id=net0,net=10.42.0.0/24,dhcpstart=10.42.0.10,%s,%s", grpcGuestFwd, blobGuestFwd),
@@ -256,7 +261,7 @@
"-no-reboot",
}
stage1Args := append(qemuArgs,
- "-kernel", kernelPath,
+ "-kernel", xKernelPath,
"-initrd", initramfsFile.Name(),
"-append", "console=ttyS0 quiet")
qemuCmdAgent := exec.Command("qemu-system-x86_64", stage1Args...)