X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9f7f123d653018219ee712ac9d6ccb18c038ce95..f608029e1aec903bc35a4748ef51e6f076dae0aa:/lib/crunchrun/crunchrun_test.go diff --git a/lib/crunchrun/crunchrun_test.go b/lib/crunchrun/crunchrun_test.go index 3539a3f656..c28cf73cbe 100644 --- a/lib/crunchrun/crunchrun_test.go +++ b/lib/crunchrun/crunchrun_test.go @@ -112,16 +112,18 @@ 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) 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 } @@ -307,9 +309,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) { @@ -403,16 +407,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{} @@ -455,8 +449,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) { @@ -522,8 +516,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 } @@ -547,8 +539,6 @@ func (s *TestSuite) TestRunContainer(c *C) { c.Check(logs.Stdout.String(), Matches, ".*Hello world\n") c.Check(logs.Stderr.String(), Equals, "") - c.Check(s.testDispatcherKeepClient, Equals, []string{"default"}) - c.Check(s.testContainerKeepClient, Equals, []string{"default"}) } func (s *TestSuite) TestCommitLogs(c *C) { @@ -664,7 +654,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 { @@ -715,7 +705,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") @@ -730,7 +721,8 @@ func (s *TestSuite) TestFullRunHello(c *C) { 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) { @@ -858,6 +850,26 @@ 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).*Executing container 'zzzzz-zzzzz-zzzzzzzzzzzzzzz' using stub runtime.*`) +} + func (s *TestSuite) TestContainerRecordLog(c *C) { s.fullRunHelper(c, `{ "command": ["sleep", "1"], @@ -947,6 +959,29 @@ 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) TestStopOnSignal(c *C) { s.executor.runFunc = func() { s.executor.created.Stdout.Write([]byte("foo\n")) @@ -1089,9 +1124,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", + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", - "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + "--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() @@ -1109,9 +1144,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", "--read-write", "--storage-classes", "foo,bar", "--crunchstat-interval=5", - "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + "--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() @@ -1129,9 +1164,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", + c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground", "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", - "--mount-by-pdh", "by_id", realTemp + "/keep1"}) + "--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() @@ -1152,9 +1187,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", + 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", realTemp + "/keep1"}) + "--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() @@ -1175,9 +1210,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", + 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", realTemp + "/keep1"}) + "--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}, @@ -1202,9 +1237,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", + 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", realTemp + "/keep1"}) + "--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}, @@ -1285,9 +1320,9 @@ func (s *TestSuite) TestSetupMounts(c *C) { bindmounts, err := cr.SetupMounts() c.Check(err, IsNil) - c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", + 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", realTemp + "/keep1"}) + "--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}, @@ -1519,6 +1554,37 @@ 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 <- 0 + } + 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", 0), 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) +} + func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) { helperRecord := `{ "command": ["/bin/sh", "-c", "echo $FROBIZ"],