9 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
10 "git.curoverse.com/arvados.git/sdk/go/keepclient"
11 "git.curoverse.com/arvados.git/sdk/go/manifest"
12 "github.com/curoverse/dockerclient"
27 // Gocheck boilerplate
28 func TestCrunchExec(t *testing.T) {
32 type TestSuite struct{}
34 // Gocheck boilerplate
35 var _ = Suite(&TestSuite{})
37 type ArvTestClient struct {
40 Content []arvadosclient.Dict
42 Logs map[string]*bytes.Buffer
47 type KeepTestClient struct {
52 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
53 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
54 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
56 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
57 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
59 type TestDockerClient struct {
61 logReader io.ReadCloser
62 logWriter io.WriteCloser
63 fn func(t *TestDockerClient)
64 finish chan dockerclient.WaitResult
70 func NewTestDockerClient() *TestDockerClient {
71 t := &TestDockerClient{}
72 t.logReader, t.logWriter = io.Pipe()
73 t.finish = make(chan dockerclient.WaitResult)
74 t.stop = make(chan bool)
79 func (t *TestDockerClient) StopContainer(id string, timeout int) error {
84 func (t *TestDockerClient) InspectImage(id string) (*dockerclient.ImageInfo, error) {
85 if t.imageLoaded == id {
86 return &dockerclient.ImageInfo{}, nil
88 return nil, errors.New("")
92 func (t *TestDockerClient) LoadImage(reader io.Reader) error {
93 _, err := io.Copy(ioutil.Discard, reader)
97 t.imageLoaded = hwImageId
102 func (t *TestDockerClient) CreateContainer(config *dockerclient.ContainerConfig, name string, authConfig *dockerclient.AuthConfig) (string, error) {
103 if config.WorkingDir != "" {
104 t.cwd = config.WorkingDir
110 func (t *TestDockerClient) StartContainer(id string, config *dockerclient.HostConfig) error {
115 return errors.New("Invalid container id")
119 func (t *TestDockerClient) AttachContainer(id string, options *dockerclient.AttachOptions) (io.ReadCloser, error) {
120 return t.logReader, nil
123 func (t *TestDockerClient) Wait(id string) <-chan dockerclient.WaitResult {
127 func (*TestDockerClient) RemoveImage(name string, force bool) ([]*dockerclient.ImageDelete, error) {
131 func (this *ArvTestClient) Create(resourceType string,
132 parameters arvadosclient.Dict,
133 output interface{}) error {
136 defer this.Mutex.Unlock()
139 this.Content = append(this.Content, parameters)
141 if resourceType == "logs" {
142 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
143 if this.Logs == nil {
144 this.Logs = make(map[string]*bytes.Buffer)
146 if this.Logs[et] == nil {
147 this.Logs[et] = &bytes.Buffer{}
149 this.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
152 if resourceType == "collections" && output != nil {
153 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
154 outmap := output.(*CollectionRecord)
155 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
161 func (this *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
162 if resourceType == "collections" {
164 output.(*CollectionRecord).ManifestText = hwManifest
165 } else if uuid == otherPDH {
166 output.(*CollectionRecord).ManifestText = otherManifest
169 if resourceType == "containers" {
170 (*output.(*ContainerRecord)) = this.ContainerRecord
175 func (this *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
177 defer this.Mutex.Unlock()
179 this.Content = append(this.Content, parameters)
180 if resourceType == "containers" {
181 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
182 this.WasSetRunning = true
188 // CalledWith returns the parameters from the first API call whose
189 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
190 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
191 // no call matches, it returns nil.
192 func (this *ArvTestClient) CalledWith(jpath, expect string) arvadosclient.Dict {
193 call: for _, content := range this.Content {
194 var v interface{} = content
195 for _, k := range strings.Split(jpath, ".") {
196 if dict, ok := v.(arvadosclient.Dict); !ok {
202 if v, ok := v.(string); ok && v == expect {
209 func (this *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
211 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
214 type FileWrapper struct {
219 func (this FileWrapper) Len() uint64 {
223 func (this *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
224 if filename == hwImageId+".tar" {
225 rdr := ioutil.NopCloser(&bytes.Buffer{})
227 return FileWrapper{rdr, 1321984}, nil
232 func (s *TestSuite) TestLoadImage(c *C) {
233 kc := &KeepTestClient{}
234 docker := NewTestDockerClient()
235 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
237 _, err := cr.Docker.RemoveImage(hwImageId, true)
239 _, err = cr.Docker.InspectImage(hwImageId)
242 cr.ContainerRecord.ContainerImage = hwPDH
244 // (1) Test loading image from keep
245 c.Check(kc.Called, Equals, false)
246 c.Check(cr.ContainerConfig.Image, Equals, "")
252 cr.Docker.RemoveImage(hwImageId, true)
255 c.Check(kc.Called, Equals, true)
256 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
258 _, err = cr.Docker.InspectImage(hwImageId)
261 // (2) Test using image that's already loaded
263 cr.ContainerConfig.Image = ""
267 c.Check(kc.Called, Equals, false)
268 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
272 type ArvErrorTestClient struct{}
273 type KeepErrorTestClient struct{}
274 type KeepReadErrorTestClient struct{}
276 func (this ArvErrorTestClient) Create(resourceType string,
277 parameters arvadosclient.Dict,
278 output interface{}) error {
282 func (this ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
283 return errors.New("ArvError")
286 func (this ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
290 func (this KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
291 return "", 0, errors.New("KeepError")
294 func (this KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
295 return nil, errors.New("KeepError")
298 func (this KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
302 type ErrorReader struct{}
304 func (this ErrorReader) Read(p []byte) (n int, err error) {
305 return 0, errors.New("ErrorReader")
308 func (this ErrorReader) Close() error {
312 func (this ErrorReader) Len() uint64 {
316 func (this KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error) {
317 return ErrorReader{}, nil
320 func (s *TestSuite) TestLoadImageArvError(c *C) {
322 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
323 cr.ContainerRecord.ContainerImage = hwPDH
325 err := cr.LoadImage()
326 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
329 func (s *TestSuite) TestLoadImageKeepError(c *C) {
331 docker := NewTestDockerClient()
332 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
333 cr.ContainerRecord.ContainerImage = hwPDH
335 err := cr.LoadImage()
336 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
339 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
340 // (3) Collection doesn't contain image
341 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
342 cr.ContainerRecord.ContainerImage = otherPDH
344 err := cr.LoadImage()
345 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
348 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
349 // (4) Collection doesn't contain image
350 docker := NewTestDockerClient()
351 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
352 cr.ContainerRecord.ContainerImage = hwPDH
354 err := cr.LoadImage()
358 type ClosableBuffer struct {
362 type TestLogs struct {
363 Stdout ClosableBuffer
364 Stderr ClosableBuffer
367 func (this *ClosableBuffer) Close() error {
371 func (this *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
372 if logstr == "stdout" {
375 if logstr == "stderr" {
381 func dockerLog(fd byte, msg string) []byte {
383 header := make([]byte, 8+len(by))
385 header[7] = byte(len(by))
390 func (s *TestSuite) TestRunContainer(c *C) {
391 docker := NewTestDockerClient()
392 docker.fn = func(t *TestDockerClient) {
393 t.logWriter.Write(dockerLog(1, "Hello world\n"))
395 t.finish <- dockerclient.WaitResult{}
397 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
400 cr.NewLogWriter = logs.NewTestLoggingWriter
401 cr.ContainerRecord.ContainerImage = hwPDH
402 cr.ContainerRecord.Command = []string{"./hw"}
403 err := cr.LoadImage()
406 err = cr.StartContainer()
409 err = cr.WaitFinish()
412 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
413 c.Check(logs.Stderr.String(), Equals, "")
416 func (s *TestSuite) TestCommitLogs(c *C) {
417 api := &ArvTestClient{}
418 kc := &KeepTestClient{}
419 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
420 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
422 cr.CrunchLog.Print("Hello world!")
423 cr.CrunchLog.Print("Goodbye")
424 cr.finalState = "Complete"
426 err := cr.CommitLogs()
429 c.Check(api.Calls, Equals, 2)
430 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
431 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
432 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
435 func (s *TestSuite) TestUpdateContainerRecordRunning(c *C) {
436 api := &ArvTestClient{}
437 kc := &KeepTestClient{}
438 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
440 err := cr.UpdateContainerRecordRunning()
443 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
446 func (s *TestSuite) TestUpdateContainerRecordComplete(c *C) {
447 api := &ArvTestClient{}
448 kc := &KeepTestClient{}
449 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
451 cr.LogsPDH = new(string)
452 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
454 cr.ExitCode = new(int)
456 cr.finalState = "Complete"
458 err := cr.UpdateContainerRecordComplete()
461 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
462 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
463 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
466 func (s *TestSuite) TestUpdateContainerRecordCancelled(c *C) {
467 api := &ArvTestClient{}
468 kc := &KeepTestClient{}
469 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
471 cr.finalState = "Cancelled"
473 err := cr.UpdateContainerRecordComplete()
476 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
477 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
478 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
481 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
482 // dress rehearsal of the Run() function, starting from a JSON container record.
483 func FullRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner) {
484 rec := ContainerRecord{}
485 err := json.NewDecoder(strings.NewReader(record)).Decode(&rec)
488 docker := NewTestDockerClient()
490 docker.RemoveImage(hwImageId, true)
492 api = &ArvTestClient{ContainerRecord: rec}
493 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
494 am := &ArvMountCmdLine{}
495 cr.RunArvMount = am.ArvMountTest
499 c.Check(api.WasSetRunning, Equals, true)
501 c.Check(api.Content[api.Calls-1]["container"].(arvadosclient.Dict)["log"], NotNil)
504 for k, v := range api.Logs {
513 func (s *TestSuite) TestFullRunHello(c *C) {
514 api, _ := FullRunHelper(c, `{
515 "command": ["echo", "hello world"],
516 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
519 "mounts": {"/tmp": {"kind": "tmp"} },
520 "output_path": "/tmp",
522 "runtime_constraints": {}
523 }`, func(t *TestDockerClient) {
524 t.logWriter.Write(dockerLog(1, "hello world\n"))
526 t.finish <- dockerclient.WaitResult{}
529 c.Check(api.Calls, Equals, 7)
530 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
531 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
533 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
537 func (s *TestSuite) TestFullRunStderr(c *C) {
538 api, _ := FullRunHelper(c, `{
539 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
540 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
543 "mounts": {"/tmp": {"kind": "tmp"} },
544 "output_path": "/tmp",
546 "runtime_constraints": {}
547 }`, func(t *TestDockerClient) {
548 t.logWriter.Write(dockerLog(1, "hello\n"))
549 t.logWriter.Write(dockerLog(2, "world\n"))
551 t.finish <- dockerclient.WaitResult{ExitCode: 1}
554 c.Assert(api.Calls, Equals, 8)
555 c.Check(api.Content[7]["container"].(arvadosclient.Dict)["log"], NotNil)
556 c.Check(api.Content[7]["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
557 c.Check(api.Content[7]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
559 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
560 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
563 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
564 api, _ := FullRunHelper(c, `{
566 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
569 "mounts": {"/tmp": {"kind": "tmp"} },
570 "output_path": "/tmp",
572 "runtime_constraints": {}
573 }`, func(t *TestDockerClient) {
574 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
576 t.finish <- dockerclient.WaitResult{ExitCode: 0}
579 c.Check(api.Calls, Equals, 7)
580 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
581 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
583 log.Print(api.Logs["stdout"].String())
585 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
588 func (s *TestSuite) TestFullRunSetCwd(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 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
611 func (s *TestSuite) TestCancel(c *C) {
613 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
614 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
617 "mounts": {"/tmp": {"kind": "tmp"} },
618 "output_path": "/tmp",
620 "runtime_constraints": {}
623 rec := ContainerRecord{}
624 err := json.NewDecoder(strings.NewReader(record)).Decode(&rec)
627 docker := NewTestDockerClient()
628 docker.fn = func(t *TestDockerClient) {
630 t.logWriter.Write(dockerLog(1, "foo\n"))
632 t.finish <- dockerclient.WaitResult{ExitCode: 0}
634 docker.RemoveImage(hwImageId, true)
636 api := &ArvTestClient{ContainerRecord: rec}
637 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
638 am := &ArvMountCmdLine{}
639 cr.RunArvMount = am.ArvMountTest
642 for cr.ContainerID == "" {
643 time.Sleep(time.Millisecond)
645 cr.SigChan <- syscall.SIGINT
652 c.Check(api.Calls, Equals, 6)
653 c.Check(api.Content[5]["container"].(arvadosclient.Dict)["log"], NotNil)
656 for k, v := range api.Logs {
662 c.Check(api.Content[5]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
664 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
668 func (s *TestSuite) TestFullRunSetEnv(c *C) {
669 api, _ := FullRunHelper(c, `{
670 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
671 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
673 "environment": {"FROBIZ": "bilbo"},
674 "mounts": {"/tmp": {"kind": "tmp"} },
675 "output_path": "/tmp",
677 "runtime_constraints": {}
678 }`, func(t *TestDockerClient) {
679 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
681 t.finish <- dockerclient.WaitResult{ExitCode: 0}
684 c.Check(api.Calls, Equals, 7)
685 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
686 c.Check(api.Content[6]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
688 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
691 type ArvMountCmdLine struct {
695 func (am *ArvMountCmdLine) ArvMountTest(c []string) (*exec.Cmd, error) {
700 func (s *TestSuite) TestSetupMounts(c *C) {
701 api := &ArvTestClient{}
702 kc := &KeepTestClient{}
703 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
704 am := &ArvMountCmdLine{}
705 cr.RunArvMount = am.ArvMountTest
708 cr.MkTempDir = func(string, string) (string, error) {
710 d := fmt.Sprintf("/tmp/mktmpdir%d", i)
711 os.Mkdir(d, os.ModePerm)
716 cr.ContainerRecord.Mounts = make(map[string]Mount)
717 cr.ContainerRecord.Mounts["/tmp"] = Mount{Kind: "tmp"}
718 cr.OutputPath = "/tmp"
720 err := cr.SetupMounts()
722 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
723 c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir2:/tmp"})
729 cr.ContainerRecord.Mounts = make(map[string]Mount)
730 cr.ContainerRecord.Mounts["/keeptmp"] = Mount{Kind: "collection", Writable: true}
731 cr.OutputPath = "/keeptmp"
733 os.MkdirAll("/tmp/mktmpdir1/tmp0", os.ModePerm)
735 err := cr.SetupMounts()
737 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
738 c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir1/tmp0:/keeptmp"})
744 cr.ContainerRecord.Mounts = make(map[string]Mount)
745 cr.ContainerRecord.Mounts["/keepinp"] = Mount{Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"}
746 cr.ContainerRecord.Mounts["/keepout"] = Mount{Kind: "collection", Writable: true}
747 cr.OutputPath = "/keepout"
749 os.MkdirAll("/tmp/mktmpdir1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
750 os.MkdirAll("/tmp/mktmpdir1/tmp0", os.ModePerm)
752 err := cr.SetupMounts()
754 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "/tmp/mktmpdir1"})
755 var ss sort.StringSlice = cr.Binds
757 c.Check(cr.Binds, DeepEquals, []string{"/tmp/mktmpdir1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
758 "/tmp/mktmpdir1/tmp0:/keepout"})
763 func (s *TestSuite) TestStdout(c *C) {
765 helperRecord += `"command": ["/bin/sh", "-c", "echo $FROBIZ"],`
766 helperRecord += `"container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",`
767 helperRecord += `"cwd": "/bin",`
768 helperRecord += `"environment": {"FROBIZ": "bilbo"},`
769 helperRecord += `"mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },`
770 helperRecord += `"output_path": "/tmp",`
771 helperRecord += `"priority": 1,`
772 helperRecord += `"runtime_constraints": {}`
775 api, _ := FullRunHelper(c, helperRecord, func(t *TestDockerClient) {
776 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
778 t.finish <- dockerclient.WaitResult{ExitCode: 0}
781 c.Assert(api.Calls, Equals, 6)
782 c.Check(api.Content[5]["container"].(arvadosclient.Dict)["exit_code"], Equals, 0)
783 c.Check(api.Content[5]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
784 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), Not(IsNil))
787 // Used by the TestStdoutWithWrongPath*()
788 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
789 rec := ContainerRecord{}
790 err = json.NewDecoder(strings.NewReader(record)).Decode(&rec)
793 docker := NewTestDockerClient()
795 docker.RemoveImage(hwImageId, true)
797 api = &ArvTestClient{ContainerRecord: rec}
798 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
799 am := &ArvMountCmdLine{}
800 cr.RunArvMount = am.ArvMountTest
806 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
807 _, _, err := StdoutErrorRunHelper(c, `{
808 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
809 "output_path": "/tmp"
810 }`, func(t *TestDockerClient) {})
813 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
816 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
817 _, _, err := StdoutErrorRunHelper(c, `{
818 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
819 "output_path": "/tmp"
820 }`, func(t *TestDockerClient) {})
823 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
826 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
827 _, _, err := StdoutErrorRunHelper(c, `{
828 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
829 "output_path": "/tmp"
830 }`, func(t *TestDockerClient) {})
833 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)