service: align host tmp test path

This commit is contained in:
Brad Stein 2026-03-31 21:46:59 -03:00
parent 678c68e294
commit bd61275821
4 changed files with 37 additions and 3 deletions

View File

@ -380,7 +380,11 @@ func hasMountedChildren(children []struct {
func humanHostPath(path string) string {
path = strings.TrimSpace(path)
if strings.HasPrefix(path, "/host-tmp/") {
return "/" + strings.TrimPrefix(path, "/host-tmp/")
trimmed := strings.TrimPrefix(path, "/host-tmp/")
if trimmed == "" {
return "/tmp"
}
return "/tmp/" + trimmed
}
if path == "/host-tmp" {
return "/tmp"

View File

@ -26,3 +26,9 @@ func TestOrasPushInvocationUsesRelativeWorkspacePaths(t *testing.T) {
t.Fatalf("unexpected metadata arg: %q", args[3])
}
}
func TestHumanHostPathMapsMountedTmpBackToHostTmp(t *testing.T) {
if got := humanHostPath("/host-tmp/metis-flash-test"); got != "/tmp/metis-flash-test" {
t.Fatalf("expected /tmp/metis-flash-test, got %q", got)
}
}

View File

@ -313,7 +313,7 @@ func (a *App) remoteDevicePodSpec(name, host, image string) map[string]any {
"command": []string{
"metis", "remote-devices",
"--max-device-bytes", fmt.Sprintf("%d", a.settings.MaxDeviceBytes),
"--host-tmp-dir", filepath.Join("/host-tmp", strings.TrimPrefix(a.settings.HostTmpDir, "/")),
"--host-tmp-dir", mountedHostTmpDir(a.settings.HostTmpDir),
},
"securityContext": map[string]any{"privileged": true, "runAsUser": 0},
"volumeMounts": []map[string]any{
@ -412,7 +412,7 @@ func (a *App) remoteFlashPodSpec(name, host, image, node, device, artifactRef st
"--artifact-ref", artifactRef,
"--work-dir", "/workspace/flash",
"--harbor-registry", a.settings.HarborRegistry,
"--host-tmp-dir", filepath.Join("/host-tmp", strings.TrimPrefix(a.settings.HostTmpDir, "/")),
"--host-tmp-dir", mountedHostTmpDir(a.settings.HostTmpDir),
},
"securityContext": map[string]any{"privileged": true, "runAsUser": 0},
"envFrom": []map[string]any{
@ -453,3 +453,15 @@ func inventoryNodeArch(spec *inventory.NodeSpec, class *inventory.NodeClass) str
}
return "arm64"
}
func mountedHostTmpDir(path string) string {
path = strings.TrimSpace(path)
switch {
case path == "", path == "/tmp":
return "/host-tmp"
case strings.HasPrefix(path, "/tmp/"):
return filepath.Join("/host-tmp", strings.TrimPrefix(path, "/tmp/"))
default:
return filepath.Join("/host-tmp", strings.TrimPrefix(path, "/"))
}
}

View File

@ -0,0 +1,12 @@
package service
import "testing"
func TestMountedHostTmpDirMapsConfiguredTmpPathIntoMount(t *testing.T) {
if got := mountedHostTmpDir("/tmp/metis-flash-test"); got != "/host-tmp/metis-flash-test" {
t.Fatalf("expected /host-tmp/metis-flash-test, got %q", got)
}
if got := mountedHostTmpDir("/tmp"); got != "/host-tmp" {
t.Fatalf("expected /host-tmp, got %q", got)
}
}