9 "git.curoverse.com/arvados.git/sdk/go/arvados"
10 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
11 "git.curoverse.com/arvados.git/sdk/go/keepclient"
12 "git.curoverse.com/arvados.git/sdk/go/manifest"
13 "github.com/curoverse/dockerclient"
28 // Gocheck boilerplate
29 func TestCrunchExec(t *testing.T) {
33 type TestSuite struct{}
35 // Gocheck boilerplate
36 var _ = Suite(&TestSuite{})
38 type ArvTestClient struct {
41 Content []arvadosclient.Dict
43 Logs map[string]*bytes.Buffer
48 type KeepTestClient struct {
53 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
54 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
55 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
57 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
58 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
60 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
61 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
63 type TestDockerClient struct {
65 logReader io.ReadCloser
66 logWriter io.WriteCloser
67 fn func(t *TestDockerClient)
68 finish chan dockerclient.WaitResult
74 func NewTestDockerClient() *TestDockerClient {
75 t := &TestDockerClient{}
76 t.logReader, t.logWriter = io.Pipe()
77 t.finish = make(chan dockerclient.WaitResult)
78 t.stop = make(chan bool)
83 func (t *TestDockerClient) StopContainer(id string, timeout int) error {
88 func (t *TestDockerClient) InspectImage(id string) (*dockerclient.ImageInfo, error) {
89 if t.imageLoaded == id {
90 return &dockerclient.ImageInfo{}, nil
92 return nil, errors.New("")
96 func (t *TestDockerClient) LoadImage(reader io.Reader) error {
97 _, err := io.Copy(ioutil.Discard, reader)
101 t.imageLoaded = hwImageId
106 func (t *TestDockerClient) CreateContainer(config *dockerclient.ContainerConfig, name string, authConfig *dockerclient.AuthConfig) (string, error) {
107 if config.WorkingDir != "" {
108 t.cwd = config.WorkingDir
114 func (t *TestDockerClient) StartContainer(id string, config *dockerclient.HostConfig) error {
119 return errors.New("Invalid container id")
123 func (t *TestDockerClient) AttachContainer(id string, options *dockerclient.AttachOptions) (io.ReadCloser, error) {
124 return t.logReader, nil
127 func (t *TestDockerClient) Wait(id string) <-chan dockerclient.WaitResult {
131 func (*TestDockerClient) RemoveImage(name string, force bool) ([]*dockerclient.ImageDelete, error) {
135 func (this *ArvTestClient) Create(resourceType string,
136 parameters arvadosclient.Dict,
137 output interface{}) error {
140 defer this.Mutex.Unlock()
143 this.Content = append(this.Content, parameters)
145 if resourceType == "logs" {
146 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
147 if this.Logs == nil {
148 this.Logs = make(map[string]*bytes.Buffer)
150 if this.Logs[et] == nil {
151 this.Logs[et] = &bytes.Buffer{}
153 this.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
156 if resourceType == "collections" && output != nil {
157 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
158 outmap := output.(*CollectionRecord)
159 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
165 func (this *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
167 case method == "GET" && resourceType == "containers" && action == "auth":
168 return json.Unmarshal([]byte(`{
169 "kind": "arvados#api_client_authorization",
170 "uuid": "`+fakeAuthUUID+`",
171 "api_token": "`+fakeAuthToken+`"
174 return fmt.Errorf("Not found")
178 func (this *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
179 if resourceType == "collections" {
181 output.(*CollectionRecord).ManifestText = hwManifest
182 } else if uuid == otherPDH {
183 output.(*CollectionRecord).ManifestText = otherManifest
186 if resourceType == "containers" {
187 (*output.(*arvados.Container)) = this.Container
192 func (this *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
194 defer this.Mutex.Unlock()
196 this.Content = append(this.Content, parameters)
197 if resourceType == "containers" {
198 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
199 this.WasSetRunning = true
205 // CalledWith returns the parameters from the first API call whose
206 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
207 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
208 // no call matches, it returns nil.
209 func (this *ArvTestClient) CalledWith(jpath, expect string) arvadosclient.Dict {
211 for _, content := range this.Content {
212 var v interface{} = content
213 for _, k := range strings.Split(jpath, ".") {
214 if dict, ok := v.(arvadosclient.Dict); !ok {
220 if v, ok := v.(string); ok && v == expect {
227 func (this *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
229 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
232 type FileWrapper struct {
237 func (this FileWrapper) Len() uint64 {
241 func (this *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
242 if filename == hwImageId+".tar" {
243 rdr := ioutil.NopCloser(&bytes.Buffer{})
245 return FileWrapper{rdr, 1321984}, nil
250 func (s *TestSuite) TestLoadImage(c *C) {
251 kc := &KeepTestClient{}
252 docker := NewTestDockerClient()
253 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
255 _, err := cr.Docker.RemoveImage(hwImageId, true)
257 _, err = cr.Docker.InspectImage(hwImageId)
260 cr.Container.ContainerImage = hwPDH
262 // (1) Test loading image from keep
263 c.Check(kc.Called, Equals, false)
264 c.Check(cr.ContainerConfig.Image, Equals, "")
270 cr.Docker.RemoveImage(hwImageId, true)
273 c.Check(kc.Called, Equals, true)
274 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
276 _, err = cr.Docker.InspectImage(hwImageId)
279 // (2) Test using image that's already loaded
281 cr.ContainerConfig.Image = ""
285 c.Check(kc.Called, Equals, false)
286 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
290 type ArvErrorTestClient struct{}
291 type KeepErrorTestClient struct{}
292 type KeepReadErrorTestClient struct{}
294 func (this ArvErrorTestClient) Create(resourceType string,
295 parameters arvadosclient.Dict,
296 output interface{}) error {
300 func (this ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
301 return errors.New("ArvError")
304 func (this ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
305 return errors.New("ArvError")
308 func (this ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
312 func (this KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
313 return "", 0, errors.New("KeepError")
316 func (this KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
317 return nil, errors.New("KeepError")
320 func (this KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
324 type ErrorReader struct{}
326 func (this ErrorReader) Read(p []byte) (n int, err error) {
327 return 0, errors.New("ErrorReader")
330 func (this ErrorReader) Close() error {
334 func (this ErrorReader) Len() uint64 {
338 func (this KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
339 return ErrorReader{}, nil
342 func (s *TestSuite) TestLoadImageArvError(c *C) {
344 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
345 cr.Container.ContainerImage = hwPDH
347 err := cr.LoadImage()
348 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
351 func (s *TestSuite) TestLoadImageKeepError(c *C) {
353 docker := NewTestDockerClient()
354 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
355 cr.Container.ContainerImage = hwPDH
357 err := cr.LoadImage()
358 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
361 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
362 // (3) Collection doesn't contain image
363 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
364 cr.Container.ContainerImage = otherPDH
366 err := cr.LoadImage()
367 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
370 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
371 // (4) Collection doesn't contain image
372 docker := NewTestDockerClient()
373 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
374 cr.Container.ContainerImage = hwPDH
376 err := cr.LoadImage()
380 type ClosableBuffer struct {
384 type TestLogs struct {
385 Stdout ClosableBuffer
386 Stderr ClosableBuffer
389 func (this *ClosableBuffer) Close() error {
393 func (this *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
394 if logstr == "stdout" {
397 if logstr == "stderr" {
403 func dockerLog(fd byte, msg string) []byte {
405 header := make([]byte, 8+len(by))
407 header[7] = byte(len(by))
412 func (s *TestSuite) TestRunContainer(c *C) {
413 docker := NewTestDockerClient()
414 docker.fn = func(t *TestDockerClient) {
415 t.logWriter.Write(dockerLog(1, "Hello world\n"))
417 t.finish <- dockerclient.WaitResult{}
419 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
422 cr.NewLogWriter = logs.NewTestLoggingWriter
423 cr.Container.ContainerImage = hwPDH
424 cr.Container.Command = []string{"./hw"}
425 err := cr.LoadImage()
428 err = cr.CreateContainer()
431 err = cr.StartContainer()
434 err = cr.WaitFinish()
437 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
438 c.Check(logs.Stderr.String(), Equals, "")
441 func (s *TestSuite) TestCommitLogs(c *C) {
442 api := &ArvTestClient{}
443 kc := &KeepTestClient{}
444 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
445 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
447 cr.CrunchLog.Print("Hello world!")
448 cr.CrunchLog.Print("Goodbye")
449 cr.finalState = "Complete"
451 err := cr.CommitLogs()
454 c.Check(api.Calls, Equals, 2)
455 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
456 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
457 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
460 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
461 api := &ArvTestClient{}
462 kc := &KeepTestClient{}
463 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
465 err := cr.UpdateContainerRunning()
468 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
471 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
472 api := &ArvTestClient{}
473 kc := &KeepTestClient{}
474 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
476 cr.LogsPDH = new(string)
477 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
479 cr.ExitCode = new(int)
481 cr.finalState = "Complete"
483 err := cr.UpdateContainerFinal()
486 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
487 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
488 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
491 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
492 api := &ArvTestClient{}
493 kc := &KeepTestClient{}
494 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
496 cr.finalState = "Cancelled"
498 err := cr.UpdateContainerFinal()
501 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
502 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
503 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
506 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
507 // dress rehearsal of the Run() function, starting from a JSON container record.
508 func FullRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner) {
509 rec := arvados.Container{}
510 err := json.Unmarshal([]byte(record), &rec)
513 docker := NewTestDockerClient()
515 docker.RemoveImage(hwImageId, true)
517 api = &ArvTestClient{Container: rec}
518 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
519 am := &ArvMountCmdLine{}
520 cr.RunArvMount = am.ArvMountTest
524 c.Check(api.WasSetRunning, Equals, true)
526 c.Check(api.Content[api.Calls-1]["container"].(arvadosclient.Dict)["log"], NotNil)
529 for k, v := range api.Logs {
538 func (s *TestSuite) TestFullRunHello(c *C) {
539 api, _ := FullRunHelper(c, `{
540 "command": ["echo", "hello world"],
541 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
544 "mounts": {"/tmp": {"kind": "tmp"} },
545 "output_path": "/tmp",
547 "runtime_constraints": {}
548 }`, func(t *TestDockerClient) {
549 t.logWriter.Write(dockerLog(1, "hello world\n"))
551 t.finish <- dockerclient.WaitResult{}
554 c.Check(api.Calls, Equals, 7)
555 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
556 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
558 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
562 func (s *TestSuite) TestFullRunStderr(c *C) {
563 api, _ := FullRunHelper(c, `{
564 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
565 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
568 "mounts": {"/tmp": {"kind": "tmp"} },
569 "output_path": "/tmp",
571 "runtime_constraints": {}
572 }`, func(t *TestDockerClient) {
573 t.logWriter.Write(dockerLog(1, "hello\n"))
574 t.logWriter.Write(dockerLog(2, "world\n"))
576 t.finish <- dockerclient.WaitResult{ExitCode: 1}
579 c.Assert(api.Calls, Equals, 8)
580 c.Check(api.Content[7]["container"].(arvadosclient.Dict)["log"], NotNil)
581 c.Check(api.Content[7]["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
582 c.Check(api.Content[7]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
584 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
585 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
588 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
589 api, _ := FullRunHelper(c, `{
591 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
594 "mounts": {"/tmp": {"kind": "tmp"} },
595 "output_path": "/tmp",
597 "runtime_constraints": {}
598 }`, func(t *TestDockerClient) {
599 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
601 t.finish <- dockerclient.WaitResult{ExitCode: 0}
604 c.Check(api.Calls, Equals, 7)
605 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
606 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
608 log.Print(api.Logs["stdout"].String())
610 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
613 func (s *TestSuite) TestFullRunSetCwd(c *C) {
614 api, _ := FullRunHelper(c, `{
616 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
619 "mounts": {"/tmp": {"kind": "tmp"} },
620 "output_path": "/tmp",
622 "runtime_constraints": {}
623 }`, func(t *TestDockerClient) {
624 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
626 t.finish <- dockerclient.WaitResult{ExitCode: 0}
629 c.Check(api.Calls, Equals, 7)
630 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
631 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
633 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
636 func (s *TestSuite) TestCancel(c *C) {
638 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
639 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
642 "mounts": {"/tmp": {"kind": "tmp"} },
643 "output_path": "/tmp",
645 "runtime_constraints": {}
648 rec := arvados.Container{}
649 err := json.Unmarshal([]byte(record), &rec)
652 docker := NewTestDockerClient()
653 docker.fn = func(t *TestDockerClient) {
655 t.logWriter.Write(dockerLog(1, "foo\n"))
657 t.finish <- dockerclient.WaitResult{ExitCode: 0}
659 docker.RemoveImage(hwImageId, true)
661 api := &ArvTestClient{Container: rec}
662 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
663 am := &ArvMountCmdLine{}
664 cr.RunArvMount = am.ArvMountTest
667 for cr.ContainerID == "" {
668 time.Sleep(time.Millisecond)
670 cr.SigChan <- syscall.SIGINT
677 for k, v := range api.Logs {
683 c.Assert(api.Calls, Equals, 6)
684 c.Check(api.Content[5]["container"].(arvadosclient.Dict)["log"], IsNil)
685 c.Check(api.Content[5]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
686 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
690 func (s *TestSuite) TestFullRunSetEnv(c *C) {
691 api, _ := FullRunHelper(c, `{
692 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
693 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
695 "environment": {"FROBIZ": "bilbo"},
696 "mounts": {"/tmp": {"kind": "tmp"} },
697 "output_path": "/tmp",
699 "runtime_constraints": {}
700 }`, func(t *TestDockerClient) {
701 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
703 t.finish <- dockerclient.WaitResult{ExitCode: 0}
706 c.Check(api.Calls, Equals, 7)
707 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
708 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
710 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
713 type ArvMountCmdLine struct {
718 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
724 func (s *TestSuite) TestSetupMounts(c *C) {
725 api := &ArvTestClient{}
726 kc := &KeepTestClient{}
727 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
728 am := &ArvMountCmdLine{}
729 cr.RunArvMount = am.ArvMountTest
732 cr.MkTempDir = func(string, string) (string, error) {
734 d := fmt.Sprintf("/tmp/mktmpdir%d", i)
735 os.Mkdir(d, os.ModePerm)
740 cr.Container.Mounts = make(map[string]arvados.Mount)
741 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
742 cr.OutputPath = "/tmp"
744 err := cr.SetupMounts()
746 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
747 c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir2:/tmp"})
753 cr.Container.Mounts = make(map[string]arvados.Mount)
754 cr.Container.Mounts["/keeptmp"] = arvados.Mount{Kind: "collection", Writable: true}
755 cr.OutputPath = "/keeptmp"
757 os.MkdirAll("/tmp/mktmpdir1/tmp0", os.ModePerm)
759 err := cr.SetupMounts()
761 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
762 c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir1/tmp0:/keeptmp"})
768 cr.Container.Mounts = make(map[string]arvados.Mount)
769 cr.Container.Mounts["/keepinp"] = arvados.Mount{Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"}
770 cr.Container.Mounts["/keepout"] = arvados.Mount{Kind: "collection", Writable: true}
771 cr.OutputPath = "/keepout"
773 os.MkdirAll("/tmp/mktmpdir1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
774 os.MkdirAll("/tmp/mktmpdir1/tmp0", os.ModePerm)
776 err := cr.SetupMounts()
778 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
779 var ss sort.StringSlice = cr.Binds
781 c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
782 "/tmp/mktmpdir1/tmp0:/keepout"})
787 func (s *TestSuite) TestStdout(c *C) {
789 helperRecord += `"command": ["/bin/sh", "-c", "echo $FROBIZ"],`
790 helperRecord += `"container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",`
791 helperRecord += `"cwd": "/bin",`
792 helperRecord += `"environment": {"FROBIZ": "bilbo"},`
793 helperRecord += `"mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },`
794 helperRecord += `"output_path": "/tmp",`
795 helperRecord += `"priority": 1,`
796 helperRecord += `"runtime_constraints": {}`
799 api, _ := FullRunHelper(c, helperRecord, func(t *TestDockerClient) {
800 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
802 t.finish <- dockerclient.WaitResult{ExitCode: 0}
805 c.Assert(api.Calls, Equals, 6)
806 c.Check(api.Content[5]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
807 c.Check(api.Content[5]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
808 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), Not(IsNil))
811 // Used by the TestStdoutWithWrongPath*()
812 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
813 rec := arvados.Container{}
814 err = json.Unmarshal([]byte(record), &rec)
817 docker := NewTestDockerClient()
819 docker.RemoveImage(hwImageId, true)
821 api = &ArvTestClient{Container: rec}
822 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
823 am := &ArvMountCmdLine{}
824 cr.RunArvMount = am.ArvMountTest
830 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
831 _, _, err := StdoutErrorRunHelper(c, `{
832 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
833 "output_path": "/tmp"
834 }`, func(t *TestDockerClient) {})
837 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
840 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
841 _, _, err := StdoutErrorRunHelper(c, `{
842 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
843 "output_path": "/tmp"
844 }`, func(t *TestDockerClient) {})
847 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
850 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
851 _, _, err := StdoutErrorRunHelper(c, `{
852 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
853 "output_path": "/tmp"
854 }`, func(t *TestDockerClient) {})
857 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)