X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/bcab6c50f54f155f14d1dd635becd85a5e91289d..469ea187586ea8017e26874c2d80414ce7571fae:/lib/crunchrun/crunchrun_test.go diff --git a/lib/crunchrun/crunchrun_test.go b/lib/crunchrun/crunchrun_test.go index 5f7e71d957..9971757893 100644 --- a/lib/crunchrun/crunchrun_test.go +++ b/lib/crunchrun/crunchrun_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "git.arvados.org/arvados.git/lib/cmd" "git.arvados.org/arvados.git/sdk/go/arvados" "git.arvados.org/arvados.git/sdk/go/arvadosclient" "git.arvados.org/arvados.git/sdk/go/arvadostest" @@ -39,31 +40,43 @@ func TestCrunchExec(t *testing.T) { var _ = Suite(&TestSuite{}) type TestSuite struct { - client *arvados.Client - api *ArvTestClient - runner *ContainerRunner - executor *stubExecutor - keepmount string + client *arvados.Client + api *ArvTestClient + runner *ContainerRunner + executor *stubExecutor + keepmount string + keepmountTmp []string + testDispatcherKeepClient KeepTestClient + testContainerKeepClient KeepTestClient } func (s *TestSuite) SetUpTest(c *C) { - *brokenNodeHook = "" s.client = arvados.NewClientFromEnv() s.executor = &stubExecutor{} var err error s.api = &ArvTestClient{} - s.runner, err = NewContainerRunner(s.client, s.api, &KeepTestClient{}, "zzzzz-zzzzz-zzzzzzzzzzzzzzz") + s.runner, err = NewContainerRunner(s.client, s.api, &s.testDispatcherKeepClient, "zzzzz-zzzzz-zzzzzzzzzzzzzzz") c.Assert(err, IsNil) s.runner.executor = s.executor s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) { - return s.api, &KeepTestClient{}, s.client, nil + return s.api, &s.testContainerKeepClient, s.client, nil } s.runner.RunArvMount = func(cmd []string, tok string) (*exec.Cmd, error) { s.runner.ArvMountPoint = s.keepmount + for i, opt := range cmd { + if opt == "--mount-tmp" { + err := os.Mkdir(s.keepmount+"/"+cmd[i+1], 0700) + if err != nil { + return nil, err + } + s.keepmountTmp = append(s.keepmountTmp, cmd[i+1]) + } + } return nil, nil } s.keepmount = c.MkDir() err = os.Mkdir(s.keepmount+"/by_id", 0755) + s.keepmountTmp = nil c.Assert(err, IsNil) err = os.Mkdir(s.keepmount+"/by_id/"+arvadostest.DockerImage112PDH, 0755) c.Assert(err, IsNil) @@ -88,8 +101,9 @@ type ArvTestClient struct { } type KeepTestClient struct { - Called bool - Content []byte + Called bool + Content []byte + StorageClasses []string } type stubExecutor struct { @@ -109,18 +123,25 @@ type stubExecutor struct { exit chan int } -func (e *stubExecutor) ImageLoaded(imageID string) bool { return e.imageLoaded } -func (e *stubExecutor) LoadImage(filename string) error { e.loaded = filename; return e.loadErr } +func (e *stubExecutor) LoadImage(imageId string, tarball string, container arvados.Container, keepMount string, + containerClient *arvados.Client) error { + e.loaded = tarball + return e.loadErr +} +func (e *stubExecutor) Runtime() string { return "stub" } +func (e *stubExecutor) Version() string { return "stub " + cmd.Version.String() } func (e *stubExecutor) Create(spec containerSpec) error { e.created = spec; return e.createErr } func (e *stubExecutor) Start() error { e.exit = make(chan int, 1); go e.runFunc(); return e.startErr } func (e *stubExecutor) CgroupID() string { return "cgroupid" } func (e *stubExecutor) Stop() error { e.stopped = true; go func() { e.exit <- -1 }(); return e.stopErr } func (e *stubExecutor) Close() { e.closed = true } func (e *stubExecutor) Wait(context.Context) (int, error) { - defer e.created.Stdout.Close() - defer e.created.Stderr.Close() return <-e.exit, e.waitErr } +func (e *stubExecutor) InjectCommand(ctx context.Context, _, _ string, _ bool, _ []string) (*exec.Cmd, error) { + return nil, errors.New("unimplemented") +} +func (e *stubExecutor) IPAddress() (string, error) { return "", errors.New("unimplemented") } const fakeInputCollectionPDH = "ffffffffaaaaaaaa88888888eeeeeeee+1234" @@ -304,9 +325,11 @@ func (client *KeepTestClient) LocalLocator(locator string) (string, error) { return locator, nil } -func (client *KeepTestClient) PutB(buf []byte) (string, int, error) { - client.Content = buf - return fmt.Sprintf("%x+%d", md5.Sum(buf), len(buf)), len(buf), nil +func (client *KeepTestClient) BlockWrite(_ context.Context, opts arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) { + client.Content = opts.Data + return arvados.BlockWriteResponse{ + Locator: fmt.Sprintf("%x+%d", md5.Sum(opts.Data), len(opts.Data)), + }, nil } func (client *KeepTestClient) ReadAt(string, []byte, int) (int, error) { @@ -320,6 +343,10 @@ func (client *KeepTestClient) Close() { client.Content = nil } +func (client *KeepTestClient) SetStorageClasses(sc []string) { + client.StorageClasses = sc +} + type FileWrapper struct { io.ReadCloser len int64 @@ -353,6 +380,14 @@ func (fw FileWrapper) Sync() error { return errors.New("not implemented") } +func (fw FileWrapper) Snapshot() (*arvados.Subtree, error) { + return nil, errors.New("not implemented") +} + +func (fw FileWrapper) Splice(*arvados.Subtree) error { + return errors.New("not implemented") +} + func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) { if filename == hwImageID+".tar" { rdr := ioutil.NopCloser(&bytes.Buffer{}) @@ -396,16 +431,6 @@ func (s *TestSuite) TestLoadImage(c *C) { imageID, err = s.runner.LoadImage() c.Check(err, ErrorMatches, "image collection does not include a \\.tar image file") c.Check(s.executor.loaded, Equals, "") - - // if executor reports image is already loaded, LoadImage should not be called - s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH - s.executor.imageLoaded = true - s.executor.loaded = "" - s.executor.loadErr = nil - imageID, err = s.runner.LoadImage() - c.Check(err, IsNil) - c.Check(s.executor.loaded, Equals, "") - c.Check(imageID, Equals, strings.TrimSuffix(arvadostest.DockerImage112Filename, ".tar")) } type ArvErrorTestClient struct{} @@ -448,8 +473,8 @@ func (*KeepErrorTestClient) ManifestFileReader(manifest.Manifest, string) (arvad return nil, errors.New("KeepError") } -func (*KeepErrorTestClient) PutB(buf []byte) (string, int, error) { - return "", 0, errors.New("KeepError") +func (*KeepErrorTestClient) BlockWrite(context.Context, arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) { + return arvados.BlockWriteResponse{}, errors.New("KeepError") } func (*KeepErrorTestClient) LocalLocator(string) (string, error) { @@ -515,8 +540,6 @@ func dockerLog(fd byte, msg string) []byte { func (s *TestSuite) TestRunContainer(c *C) { s.executor.runFunc = func() { fmt.Fprintf(s.executor.created.Stdout, "Hello world\n") - s.executor.created.Stdout.Close() - s.executor.created.Stderr.Close() s.executor.exit <- 0 } @@ -524,6 +547,7 @@ func (s *TestSuite) TestRunContainer(c *C) { s.runner.NewLogWriter = logs.NewTestLoggingWriter s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH s.runner.Container.Command = []string{"./hw"} + s.runner.Container.OutputStorageClasses = []string{"default"} imageID, err := s.runner.LoadImage() c.Assert(err, IsNil) @@ -638,8 +662,6 @@ func (s *TestSuite) fullRunHelper(c *C, record string, extraMounts []string, exi s.runner.statInterval = 100 * time.Millisecond s.runner.containerWatchdogInterval = time.Second - am := &ArvMountCmdLine{} - s.runner.RunArvMount = am.ArvMountTest realTemp := c.MkDir() tempcount := 0 @@ -654,7 +676,7 @@ func (s *TestSuite) fullRunHelper(c *C, record string, extraMounts []string, exi return d, err } s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) { - return &ArvTestClient{secretMounts: secretMounts}, &KeepTestClient{}, nil, nil + return &ArvTestClient{secretMounts: secretMounts}, &s.testContainerKeepClient, nil, nil } if extraMounts != nil && len(extraMounts) > 0 { @@ -705,7 +727,8 @@ func (s *TestSuite) TestFullRunHello(c *C) { "output_path": "/tmp", "priority": 1, "runtime_constraints": {"vcpus":1,"ram":1000000}, - "state": "Locked" + "state": "Locked", + "output_storage_classes": ["default"] }`, nil, 0, func() { c.Check(s.executor.created.Command, DeepEquals, []string{"echo", "hello world"}) c.Check(s.executor.created.Image, Equals, "sha256:d8309758b8fe2c81034ffc8a10c36460b77db7bc5e7b448c4e5b684f9d95a678") @@ -714,13 +737,15 @@ func (s *TestSuite) TestFullRunHello(c *C) { c.Check(s.executor.created.RAM, Equals, int64(1000000)) c.Check(s.executor.created.NetworkMode, Equals, "default") c.Check(s.executor.created.EnableNetwork, Equals, false) + c.Check(s.executor.created.CUDADeviceCount, Equals, 0) fmt.Fprintln(s.executor.created.Stdout, "hello world") }) c.Check(s.api.CalledWith("container.exit_code", 0), NotNil) c.Check(s.api.CalledWith("container.state", "Complete"), NotNil) c.Check(s.api.Logs["stdout"].String(), Matches, ".*hello world\n") - + c.Check(s.testDispatcherKeepClient.StorageClasses, DeepEquals, []string{"default"}) + c.Check(s.testContainerKeepClient.StorageClasses, DeepEquals, []string{"default"}) } func (s *TestSuite) TestRunAlreadyRunning(c *C) { @@ -848,6 +873,28 @@ func (s *TestSuite) TestNodeInfoLog(c *C) { c.Check(json, Matches, `(?ms).*Disk INodes.*`) } +func (s *TestSuite) TestLogVersionAndRuntime(c *C) { + s.fullRunHelper(c, `{ + "command": ["sleep", "1"], + "container_image": "`+arvadostest.DockerImage112PDH+`", + "cwd": ".", + "environment": {}, + "mounts": {"/tmp": {"kind": "tmp"} }, + "output_path": "/tmp", + "priority": 1, + "runtime_constraints": {}, + "state": "Locked" + }`, nil, 0, + func() { + }) + + c.Assert(s.api.Logs["crunch-run"], NotNil) + c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*crunch-run \S+ \(go\S+\) start.*`) + c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*crunch-run process has uid=\d+\(.+\) gid=\d+\(.+\) groups=\d+\(.+\)(,\d+\(.+\))*\n.*`) + c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Executing container: zzzzz-zzzzz-zzzzzzzzzzzzzzz.*`) + c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Using container runtime: stub.*`) +} + func (s *TestSuite) TestContainerRecordLog(c *C) { s.fullRunHelper(c, `{ "command": ["sleep", "1"], @@ -937,6 +984,65 @@ func (s *TestSuite) TestFullRunSetCwd(c *C) { c.Check(s.api.Logs["stdout"].String(), Matches, ".*/bin\n") } +func (s *TestSuite) TestFullRunSetOutputStorageClasses(c *C) { + s.fullRunHelper(c, `{ + "command": ["pwd"], + "container_image": "`+arvadostest.DockerImage112PDH+`", + "cwd": "/bin", + "environment": {}, + "mounts": {"/tmp": {"kind": "tmp"} }, + "output_path": "/tmp", + "priority": 1, + "runtime_constraints": {}, + "state": "Locked", + "output_storage_classes": ["foo", "bar"] +}`, nil, 0, func() { + fmt.Fprintln(s.executor.created.Stdout, s.executor.created.WorkingDir) + }) + + c.Check(s.api.CalledWith("container.exit_code", 0), NotNil) + c.Check(s.api.CalledWith("container.state", "Complete"), NotNil) + c.Check(s.api.Logs["stdout"].String(), Matches, ".*/bin\n") + c.Check(s.testDispatcherKeepClient.StorageClasses, DeepEquals, []string{"foo", "bar"}) + c.Check(s.testContainerKeepClient.StorageClasses, DeepEquals, []string{"foo", "bar"}) +} + +func (s *TestSuite) TestEnableCUDADeviceCount(c *C) { + s.fullRunHelper(c, `{ + "command": ["pwd"], + "container_image": "`+arvadostest.DockerImage112PDH+`", + "cwd": "/bin", + "environment": {}, + "mounts": {"/tmp": {"kind": "tmp"} }, + "output_path": "/tmp", + "priority": 1, + "runtime_constraints": {"cuda": {"device_count": 2}}, + "state": "Locked", + "output_storage_classes": ["foo", "bar"] +}`, nil, 0, func() { + fmt.Fprintln(s.executor.created.Stdout, "ok") + }) + c.Check(s.executor.created.CUDADeviceCount, Equals, 2) +} + +func (s *TestSuite) TestEnableCUDAHardwareCapability(c *C) { + s.fullRunHelper(c, `{ + "command": ["pwd"], + "container_image": "`+arvadostest.DockerImage112PDH+`", + "cwd": "/bin", + "environment": {}, + "mounts": {"/tmp": {"kind": "tmp"} }, + "output_path": "/tmp", + "priority": 1, + "runtime_constraints": {"cuda": {"hardware_capability": "foo"}}, + "state": "Locked", + "output_storage_classes": ["foo", "bar"] +}`, nil, 0, func() { + fmt.Fprintln(s.executor.created.Stdout, "ok") + }) + c.Check(s.executor.created.CUDADeviceCount, Equals, 0) +} + func (s *TestSuite) TestStopOnSignal(c *C) { s.executor.runFunc = func() { s.executor.created.Stdout.Write([]byte("foo\n")) @@ -1042,6 +1148,7 @@ func (s *TestSuite) TestSetupMounts(c *C) { cr.RunArvMount = am.ArvMountTest cr.ContainerArvClient = &ArvTestClient{} cr.ContainerKeepClient = &KeepTestClient{} + cr.Container.OutputStorageClasses = []string{"default"} realTemp := c.MkDir() certTemp := c.MkDir() @@ -1078,9 +1185,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { cr.statInterval = 5 * time.Second bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", - "--read-write", "--crunchstat-interval=5", - "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", + "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", + "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"}) c.Check(bindmounts, DeepEquals, map[string]bindmount{"/tmp": {realTemp + "/tmp2", false}}) os.RemoveAll(cr.ArvMountPoint) cr.CleanupDirs() @@ -1094,12 +1201,13 @@ func (s *TestSuite) TestSetupMounts(c *C) { cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"} cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"} cr.Container.OutputPath = "/out" + cr.Container.OutputStorageClasses = []string{"foo", "bar"} bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", - "--read-write", "--crunchstat-interval=5", - "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", + "--read-write", "--storage-classes", "foo,bar", "--crunchstat-interval=5", + "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"}) c.Check(bindmounts, DeepEquals, map[string]bindmount{"/out": {realTemp + "/tmp2", false}, "/tmp": {realTemp + "/tmp3", false}}) os.RemoveAll(cr.ArvMountPoint) cr.CleanupDirs() @@ -1113,12 +1221,13 @@ func (s *TestSuite) TestSetupMounts(c *C) { cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"} cr.Container.OutputPath = "/tmp" cr.Container.RuntimeConstraints.API = true + cr.Container.OutputStorageClasses = []string{"default"} bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", - "--read-write", "--crunchstat-interval=5", - "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", + "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", + "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"}) c.Check(bindmounts, DeepEquals, map[string]bindmount{"/tmp": {realTemp + "/tmp2", false}, "/etc/arvados/ca-certificates.crt": {stubCertPath, true}}) os.RemoveAll(cr.ArvMountPoint) cr.CleanupDirs() @@ -1139,9 +1248,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", - "--read-write", "--crunchstat-interval=5", - "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", + "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", + "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"}) c.Check(bindmounts, DeepEquals, map[string]bindmount{"/keeptmp": {realTemp + "/keep1/tmp0", false}}) os.RemoveAll(cr.ArvMountPoint) cr.CleanupDirs() @@ -1162,9 +1271,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", - "--read-write", "--crunchstat-interval=5", - "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", + "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", + "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"}) c.Check(bindmounts, DeepEquals, map[string]bindmount{ "/keepinp": {realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", true}, "/keepout": {realTemp + "/keep1/tmp0", false}, @@ -1189,9 +1298,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", - "--read-write", "--crunchstat-interval=5", - "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", + "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", + "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"}) c.Check(bindmounts, DeepEquals, map[string]bindmount{ "/keepinp": {realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", true}, "/keepout": {realTemp + "/keep1/tmp0", false}, @@ -1272,9 +1381,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", - "--read-write", "--crunchstat-interval=5", - "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", + "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", + "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"}) c.Check(bindmounts, DeepEquals, map[string]bindmount{ "/tmp": {realTemp + "/tmp2", false}, "/tmp/foo": {realTemp + "/keep1/tmp0", true}, @@ -1482,6 +1591,7 @@ func (s *TestSuite) TestFullRunWithAPI(c *C) { }) c.Check(s.api.CalledWith("container.exit_code", 3), NotNil) c.Check(s.api.CalledWith("container.state", "Complete"), NotNil) + c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*status code 3\n.*`) } func (s *TestSuite) TestFullRunSetOutput(c *C) { @@ -1506,6 +1616,38 @@ func (s *TestSuite) TestFullRunSetOutput(c *C) { c.Check(s.api.CalledWith("container.output", arvadostest.DockerImage112PDH), NotNil) } +func (s *TestSuite) TestArvMountRuntimeStatusWarning(c *C) { + s.runner.RunArvMount = func([]string, string) (*exec.Cmd, error) { + os.Mkdir(s.runner.ArvMountPoint+"/by_id", 0666) + ioutil.WriteFile(s.runner.ArvMountPoint+"/by_id/README", nil, 0666) + return s.runner.ArvMountCmd([]string{"bash", "-c", "echo >&2 Test: Keep write error: I am a teapot; sleep 3"}, "") + } + s.executor.runFunc = func() { + time.Sleep(time.Second) + s.executor.exit <- 137 + } + record := `{ + "command": ["sleep", "1"], + "container_image": "` + arvadostest.DockerImage112PDH + `", + "cwd": "/bin", + "environment": {}, + "mounts": {"/tmp": {"kind": "tmp"} }, + "output_path": "/tmp", + "priority": 1, + "runtime_constraints": {"API": true}, + "state": "Locked" +}` + err := json.Unmarshal([]byte(record), &s.api.Container) + c.Assert(err, IsNil) + err = s.runner.Run() + c.Assert(err, IsNil) + c.Check(s.api.CalledWith("container.exit_code", 137), NotNil) + c.Check(s.api.CalledWith("container.runtime_status.warning", "arv-mount: Keep write error"), NotNil) + c.Check(s.api.CalledWith("container.runtime_status.warningDetail", "Test: Keep write error: I am a teapot"), NotNil) + c.Check(s.api.CalledWith("container.state", "Complete"), NotNil) + c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Container exited with status code 137 \(signal 9, SIGKILL\).*`) +} + func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) { helperRecord := `{ "command": ["/bin/sh", "-c", "echo $FROBIZ"], @@ -1778,8 +1920,8 @@ func (s *TestSuite) TestFullBrokenDocker(c *C) { func() { c.Log("// loadErr = cannot connect") s.executor.loadErr = errors.New("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?") - *brokenNodeHook = c.MkDir() + "/broken-node-hook" - err := ioutil.WriteFile(*brokenNodeHook, []byte("#!/bin/sh\nexec echo killme\n"), 0700) + s.runner.brokenNodeHook = c.MkDir() + "/broken-node-hook" + err := ioutil.WriteFile(s.runner.brokenNodeHook, []byte("#!/bin/sh\nexec echo killme\n"), 0700) c.Assert(err, IsNil) nextState = "Queued" }, @@ -1799,7 +1941,7 @@ func (s *TestSuite) TestFullBrokenDocker(c *C) { }`, nil, 0, func() {}) c.Check(s.api.CalledWith("container.state", nextState), NotNil) c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*") - if *brokenNodeHook != "" { + if s.runner.brokenNodeHook != "" { c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Running broken node hook.*") c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*killme.*") c.Check(s.api.Logs["crunch-run"].String(), Not(Matches), "(?ms).*Writing /var/lock/crunch-run-broken to mark node as broken.*") @@ -1889,6 +2031,44 @@ func (s *TestSuite) TestSecretTextMountPoint(c *C) { c.Check(s.api.CalledWith("container.state", "Complete"), NotNil) c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". 34819d7beeabb9260a5c854bc85b3e44+10 0:10:secret.conf\n"), IsNil) c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ""), NotNil) + + // under secret mounts, output dir is a collection, not captured in output + helperRecord = `{ + "command": ["true"], + "container_image": "` + arvadostest.DockerImage112PDH + `", + "cwd": "/bin", + "mounts": { + "/tmp": {"kind": "collection", "writable": true} + }, + "secret_mounts": { + "/tmp/secret.conf": {"kind": "text", "content": "mypassword"} + }, + "output_path": "/tmp", + "priority": 1, + "runtime_constraints": {}, + "state": "Locked" + }` + + s.SetUpTest(c) + _, _, realtemp := s.fullRunHelper(c, helperRecord, nil, 0, func() { + // secret.conf should be provisioned as a separate + // bind mount, i.e., it should not appear in the + // (fake) fuse filesystem as viewed from the host. + content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf") + if !c.Check(errors.Is(err, os.ErrNotExist), Equals, true) { + c.Logf("secret.conf: content %q, err %#v", content, err) + } + err = ioutil.WriteFile(s.runner.HostOutputDir+"/.arvados#collection", []byte(`{"manifest_text":". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n"}`), 0700) + c.Check(err, IsNil) + }) + + content, err := ioutil.ReadFile(realtemp + "/text1/mountdata.text") + c.Check(err, IsNil) + c.Check(string(content), Equals, "mypassword") + c.Check(s.executor.created.BindMounts["/tmp/secret.conf"], DeepEquals, bindmount{realtemp + "/text1/mountdata.text", true}) + c.Check(s.api.CalledWith("container.exit_code", 0), NotNil) + c.Check(s.api.CalledWith("container.state", "Complete"), NotNil) + c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n"), NotNil) } type FakeProcess struct {