service: align host tmp test path
This commit is contained in:
parent
678c68e294
commit
bd61275821
@ -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"
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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, "/"))
|
||||
}
|
||||
}
|
||||
|
||||
12
pkg/service/remote_test.go
Normal file
12
pkg/service/remote_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user