22 "git.curoverse.com/arvados.git/sdk/go/arvados"
23 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
24 "git.curoverse.com/arvados.git/sdk/go/keepclient"
25 "git.curoverse.com/arvados.git/sdk/go/manifest"
26 "github.com/curoverse/dockerclient"
30 // Gocheck boilerplate
31 func TestCrunchExec(t *testing.T) {
35 type TestSuite struct{}
37 // Gocheck boilerplate
38 var _ = Suite(&TestSuite{})
40 type ArvTestClient struct {
43 Content []arvadosclient.Dict
45 Logs map[string]*bytes.Buffer
50 type KeepTestClient struct {
55 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
56 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
57 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
59 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
60 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
62 var normalizedManifestWithSubdirs = ". 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 0:9:file1_in_main.txt 9:18:file2_in_main.txt 0:27:zzzzz-8i9sb-bcdefghijkdhvnk.log.txt\n./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt\n./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt\n"
63 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
65 var denormalizedManifestWithSubdirs = ". 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 0:9:file1_in_main.txt 9:18:file2_in_main.txt 0:27:zzzzz-8i9sb-bcdefghijkdhvnk.log.txt 0:10:subdir1/file1_in_subdir1.txt 10:17:subdir1/file2_in_subdir1.txt\n"
66 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
68 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
69 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
71 type TestDockerClient struct {
73 logReader io.ReadCloser
74 logWriter io.WriteCloser
75 fn func(t *TestDockerClient)
76 finish chan dockerclient.WaitResult
83 func NewTestDockerClient() *TestDockerClient {
84 t := &TestDockerClient{}
85 t.logReader, t.logWriter = io.Pipe()
86 t.finish = make(chan dockerclient.WaitResult)
87 t.stop = make(chan bool)
92 func (t *TestDockerClient) StopContainer(id string, timeout int) error {
97 func (t *TestDockerClient) InspectImage(id string) (*dockerclient.ImageInfo, error) {
98 if t.imageLoaded == id {
99 return &dockerclient.ImageInfo{}, nil
101 return nil, errors.New("")
105 func (t *TestDockerClient) LoadImage(reader io.Reader) error {
106 _, err := io.Copy(ioutil.Discard, reader)
110 t.imageLoaded = hwImageId
115 func (t *TestDockerClient) CreateContainer(config *dockerclient.ContainerConfig, name string, authConfig *dockerclient.AuthConfig) (string, error) {
116 if config.WorkingDir != "" {
117 t.cwd = config.WorkingDir
123 func (t *TestDockerClient) StartContainer(id string, config *dockerclient.HostConfig) error {
128 return errors.New("Invalid container id")
132 func (t *TestDockerClient) AttachContainer(id string, options *dockerclient.AttachOptions) (io.ReadCloser, error) {
133 return t.logReader, nil
136 func (t *TestDockerClient) Wait(id string) <-chan dockerclient.WaitResult {
140 func (*TestDockerClient) RemoveImage(name string, force bool) ([]*dockerclient.ImageDelete, error) {
144 func (client *ArvTestClient) Create(resourceType string,
145 parameters arvadosclient.Dict,
146 output interface{}) error {
149 defer client.Mutex.Unlock()
152 client.Content = append(client.Content, parameters)
154 if resourceType == "logs" {
155 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
156 if client.Logs == nil {
157 client.Logs = make(map[string]*bytes.Buffer)
159 if client.Logs[et] == nil {
160 client.Logs[et] = &bytes.Buffer{}
162 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
165 if resourceType == "collections" && output != nil {
166 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
167 outmap := output.(*arvados.Collection)
168 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
174 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
176 case method == "GET" && resourceType == "containers" && action == "auth":
177 return json.Unmarshal([]byte(`{
178 "kind": "arvados#api_client_authorization",
179 "uuid": "`+fakeAuthUUID+`",
180 "api_token": "`+fakeAuthToken+`"
183 return fmt.Errorf("Not found")
187 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
188 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
190 "command": ["sleep", "1"],
191 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
194 "mounts": {"/tmp": {"kind": "tmp"} },
195 "output_path": "/tmp",
197 "runtime_constraints": {}
199 return ioutil.NopCloser(bytes.NewReader(j)), nil
202 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
203 if resourceType == "collections" {
205 output.(*arvados.Collection).ManifestText = hwManifest
206 } else if uuid == otherPDH {
207 output.(*arvados.Collection).ManifestText = otherManifest
208 } else if uuid == normalizedWithSubdirsPDH {
209 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
210 } else if uuid == denormalizedWithSubdirsPDH {
211 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
214 if resourceType == "containers" {
215 (*output.(*arvados.Container)) = client.Container
220 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
222 defer client.Mutex.Unlock()
224 client.Content = append(client.Content, parameters)
225 if resourceType == "containers" {
226 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
227 client.WasSetRunning = true
233 var discoveryMap = map[string]interface{}{"defaultTrashLifetime": float64(1209600)}
235 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
236 return discoveryMap[key], nil
239 // CalledWith returns the parameters from the first API call whose
240 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
241 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
242 // no call matches, it returns nil.
243 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
245 for _, content := range client.Content {
246 var v interface{} = content
247 for _, k := range strings.Split(jpath, ".") {
248 if dict, ok := v.(arvadosclient.Dict); !ok {
261 func (client *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
263 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
266 type FileWrapper struct {
271 func (fw FileWrapper) Len() uint64 {
275 func (fw FileWrapper) Seek(int64, int) (int64, error) {
276 return 0, errors.New("not implemented")
279 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
280 if filename == hwImageId+".tar" {
281 rdr := ioutil.NopCloser(&bytes.Buffer{})
283 return FileWrapper{rdr, 1321984}, nil
288 func (s *TestSuite) TestLoadImage(c *C) {
289 kc := &KeepTestClient{}
290 docker := NewTestDockerClient()
291 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
293 _, err := cr.Docker.RemoveImage(hwImageId, true)
295 _, err = cr.Docker.InspectImage(hwImageId)
298 cr.Container.ContainerImage = hwPDH
300 // (1) Test loading image from keep
301 c.Check(kc.Called, Equals, false)
302 c.Check(cr.ContainerConfig.Image, Equals, "")
308 cr.Docker.RemoveImage(hwImageId, true)
311 c.Check(kc.Called, Equals, true)
312 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
314 _, err = cr.Docker.InspectImage(hwImageId)
317 // (2) Test using image that's already loaded
319 cr.ContainerConfig.Image = ""
323 c.Check(kc.Called, Equals, false)
324 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
328 type ArvErrorTestClient struct{}
330 func (ArvErrorTestClient) Create(resourceType string,
331 parameters arvadosclient.Dict,
332 output interface{}) error {
336 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
337 return errors.New("ArvError")
340 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
341 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
342 return nil, errors.New("ArvError")
345 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
346 return errors.New("ArvError")
349 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
353 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
354 return discoveryMap[key], nil
357 type KeepErrorTestClient struct{}
359 func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
360 return "", 0, errors.New("KeepError")
363 func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
364 return nil, errors.New("KeepError")
367 type KeepReadErrorTestClient struct{}
369 func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
373 type ErrorReader struct{}
375 func (ErrorReader) Read(p []byte) (n int, err error) {
376 return 0, errors.New("ErrorReader")
379 func (ErrorReader) Close() error {
383 func (ErrorReader) Len() uint64 {
387 func (ErrorReader) Seek(int64, int) (int64, error) {
388 return 0, errors.New("ErrorReader")
391 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
392 return ErrorReader{}, nil
395 func (s *TestSuite) TestLoadImageArvError(c *C) {
397 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
398 cr.Container.ContainerImage = hwPDH
400 err := cr.LoadImage()
401 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
404 func (s *TestSuite) TestLoadImageKeepError(c *C) {
406 docker := NewTestDockerClient()
407 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
408 cr.Container.ContainerImage = hwPDH
410 err := cr.LoadImage()
411 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
414 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
415 // (3) Collection doesn't contain image
416 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
417 cr.Container.ContainerImage = otherPDH
419 err := cr.LoadImage()
420 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
423 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
424 // (4) Collection doesn't contain image
425 docker := NewTestDockerClient()
426 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
427 cr.Container.ContainerImage = hwPDH
429 err := cr.LoadImage()
433 type ClosableBuffer struct {
437 func (*ClosableBuffer) Close() error {
441 type TestLogs struct {
442 Stdout ClosableBuffer
443 Stderr ClosableBuffer
446 func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
447 if logstr == "stdout" {
450 if logstr == "stderr" {
456 func dockerLog(fd byte, msg string) []byte {
458 header := make([]byte, 8+len(by))
460 header[7] = byte(len(by))
465 func (s *TestSuite) TestRunContainer(c *C) {
466 docker := NewTestDockerClient()
467 docker.fn = func(t *TestDockerClient) {
468 t.logWriter.Write(dockerLog(1, "Hello world\n"))
470 t.finish <- dockerclient.WaitResult{}
472 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
475 cr.NewLogWriter = logs.NewTestLoggingWriter
476 cr.Container.ContainerImage = hwPDH
477 cr.Container.Command = []string{"./hw"}
478 err := cr.LoadImage()
481 err = cr.CreateContainer()
484 err = cr.StartContainer()
487 err = cr.WaitFinish()
490 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
491 c.Check(logs.Stderr.String(), Equals, "")
494 func (s *TestSuite) TestCommitLogs(c *C) {
495 api := &ArvTestClient{}
496 kc := &KeepTestClient{}
497 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
498 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
500 cr.CrunchLog.Print("Hello world!")
501 cr.CrunchLog.Print("Goodbye")
502 cr.finalState = "Complete"
504 err := cr.CommitLogs()
507 c.Check(api.Calls, Equals, 2)
508 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
509 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
510 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
511 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
514 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
515 api := &ArvTestClient{}
516 kc := &KeepTestClient{}
517 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
519 err := cr.UpdateContainerRunning()
522 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
525 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
526 api := &ArvTestClient{}
527 kc := &KeepTestClient{}
528 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
530 cr.LogsPDH = new(string)
531 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
533 cr.ExitCode = new(int)
535 cr.finalState = "Complete"
537 err := cr.UpdateContainerFinal()
540 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
541 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
542 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
545 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
546 api := &ArvTestClient{}
547 kc := &KeepTestClient{}
548 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
550 cr.finalState = "Cancelled"
552 err := cr.UpdateContainerFinal()
555 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
556 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
557 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
560 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
561 // dress rehearsal of the Run() function, starting from a JSON container record.
562 func FullRunHelper(c *C, record string, extraMounts []string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, realTemp string) {
563 rec := arvados.Container{}
564 err := json.Unmarshal([]byte(record), &rec)
567 docker := NewTestDockerClient()
569 docker.RemoveImage(hwImageId, true)
571 api = &ArvTestClient{Container: rec}
573 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
574 cr.statInterval = 100 * time.Millisecond
575 am := &ArvMountCmdLine{}
576 cr.RunArvMount = am.ArvMountTest
578 realTemp, err = ioutil.TempDir("", "crunchrun_test1-")
580 defer os.RemoveAll(realTemp)
583 cr.MkTempDir = func(_ string, prefix string) (string, error) {
585 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
586 err := os.Mkdir(d, os.ModePerm)
587 if err != nil && strings.Contains(err.Error(), ": file exists") {
588 // Test case must have pre-populated the tempdir
594 if extraMounts != nil && len(extraMounts) > 0 {
595 err := cr.SetupArvMountPoint("keep")
598 for _, m := range extraMounts {
599 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
605 c.Check(api.WasSetRunning, Equals, true)
607 c.Check(api.Content[api.Calls-1]["container"].(arvadosclient.Dict)["log"], NotNil)
610 for k, v := range api.Logs {
619 func (s *TestSuite) TestFullRunHello(c *C) {
620 api, _, _ := FullRunHelper(c, `{
621 "command": ["echo", "hello world"],
622 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
625 "mounts": {"/tmp": {"kind": "tmp"} },
626 "output_path": "/tmp",
628 "runtime_constraints": {}
629 }`, nil, func(t *TestDockerClient) {
630 t.logWriter.Write(dockerLog(1, "hello world\n"))
632 t.finish <- dockerclient.WaitResult{}
635 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
636 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
637 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
641 func (s *TestSuite) TestCrunchstat(c *C) {
642 api, _, _ := FullRunHelper(c, `{
643 "command": ["sleep", "1"],
644 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
647 "mounts": {"/tmp": {"kind": "tmp"} },
648 "output_path": "/tmp",
650 "runtime_constraints": {}
651 }`, nil, func(t *TestDockerClient) {
652 time.Sleep(time.Second)
654 t.finish <- dockerclient.WaitResult{}
657 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
658 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
660 // We didn't actually start a container, so crunchstat didn't
661 // find accounting files and therefore didn't log any stats.
662 // It should have logged a "can't find accounting files"
663 // message after one poll interval, though, so we can confirm
665 c.Assert(api.Logs["crunchstat"], NotNil)
666 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
668 // The "files never appeared" log assures us that we called
669 // (*crunchstat.Reporter)Stop(), and that we set it up with
670 // the correct container ID "abcde":
671 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
674 func (s *TestSuite) TestNodeInfoLog(c *C) {
675 api, _, _ := FullRunHelper(c, `{
676 "command": ["sleep", "1"],
677 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
680 "mounts": {"/tmp": {"kind": "tmp"} },
681 "output_path": "/tmp",
683 "runtime_constraints": {}
684 }`, nil, func(t *TestDockerClient) {
685 time.Sleep(time.Second)
687 t.finish <- dockerclient.WaitResult{}
690 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
691 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
693 c.Assert(api.Logs["node-info"], NotNil)
694 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Host Information.*`)
695 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*CPU Information.*`)
696 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Memory Information.*`)
697 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk Space.*`)
698 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk INodes.*`)
701 func (s *TestSuite) TestContainerRecordLog(c *C) {
702 api, _, _ := FullRunHelper(c, `{
703 "command": ["sleep", "1"],
704 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
707 "mounts": {"/tmp": {"kind": "tmp"} },
708 "output_path": "/tmp",
710 "runtime_constraints": {}
711 }`, nil, func(t *TestDockerClient) {
712 time.Sleep(time.Second)
714 t.finish <- dockerclient.WaitResult{}
717 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
718 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
720 c.Assert(api.Logs["container"], NotNil)
721 c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
724 func (s *TestSuite) TestFullRunStderr(c *C) {
725 api, _, _ := FullRunHelper(c, `{
726 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
727 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
730 "mounts": {"/tmp": {"kind": "tmp"} },
731 "output_path": "/tmp",
733 "runtime_constraints": {}
734 }`, nil, func(t *TestDockerClient) {
735 t.logWriter.Write(dockerLog(1, "hello\n"))
736 t.logWriter.Write(dockerLog(2, "world\n"))
738 t.finish <- dockerclient.WaitResult{ExitCode: 1}
741 final := api.CalledWith("container.state", "Complete")
742 c.Assert(final, NotNil)
743 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
744 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
746 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
747 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
750 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
751 api, _, _ := FullRunHelper(c, `{
753 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
756 "mounts": {"/tmp": {"kind": "tmp"} },
757 "output_path": "/tmp",
759 "runtime_constraints": {}
760 }`, nil, func(t *TestDockerClient) {
761 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
763 t.finish <- dockerclient.WaitResult{ExitCode: 0}
766 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
767 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
768 c.Log(api.Logs["stdout"])
769 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
772 func (s *TestSuite) TestFullRunSetCwd(c *C) {
773 api, _, _ := FullRunHelper(c, `{
775 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
778 "mounts": {"/tmp": {"kind": "tmp"} },
779 "output_path": "/tmp",
781 "runtime_constraints": {}
782 }`, nil, func(t *TestDockerClient) {
783 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
785 t.finish <- dockerclient.WaitResult{ExitCode: 0}
788 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
789 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
790 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
793 func (s *TestSuite) TestStopOnSignal(c *C) {
794 s.testStopContainer(c, func(cr *ContainerRunner) {
797 time.Sleep(time.Millisecond)
799 cr.SigChan <- syscall.SIGINT
804 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
805 s.testStopContainer(c, func(cr *ContainerRunner) {
806 cr.ArvMountExit = make(chan error)
808 cr.ArvMountExit <- exec.Command("true").Run()
809 close(cr.ArvMountExit)
814 func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
816 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
817 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
820 "mounts": {"/tmp": {"kind": "tmp"} },
821 "output_path": "/tmp",
823 "runtime_constraints": {}
826 rec := arvados.Container{}
827 err := json.Unmarshal([]byte(record), &rec)
830 docker := NewTestDockerClient()
831 docker.fn = func(t *TestDockerClient) {
833 t.logWriter.Write(dockerLog(1, "foo\n"))
835 t.finish <- dockerclient.WaitResult{ExitCode: 0}
837 docker.RemoveImage(hwImageId, true)
839 api := &ArvTestClient{Container: rec}
840 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
841 cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
844 done := make(chan error)
849 case <-time.After(20 * time.Second):
850 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
855 for k, v := range api.Logs {
860 c.Check(api.CalledWith("container.log", nil), NotNil)
861 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
862 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
865 func (s *TestSuite) TestFullRunSetEnv(c *C) {
866 api, _, _ := FullRunHelper(c, `{
867 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
868 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
870 "environment": {"FROBIZ": "bilbo"},
871 "mounts": {"/tmp": {"kind": "tmp"} },
872 "output_path": "/tmp",
874 "runtime_constraints": {}
875 }`, nil, func(t *TestDockerClient) {
876 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
878 t.finish <- dockerclient.WaitResult{ExitCode: 0}
881 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
882 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
883 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
886 type ArvMountCmdLine struct {
891 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
897 func stubCert(temp string) string {
898 path := temp + "/ca-certificates.crt"
899 crt, _ := os.Create(path)
901 arvadosclient.CertFiles = []string{path}
905 func (s *TestSuite) TestSetupMounts(c *C) {
906 api := &ArvTestClient{}
907 kc := &KeepTestClient{}
908 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
909 am := &ArvMountCmdLine{}
910 cr.RunArvMount = am.ArvMountTest
912 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
914 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
916 stubCertPath := stubCert(certTemp)
918 defer os.RemoveAll(realTemp)
919 defer os.RemoveAll(certTemp)
922 cr.MkTempDir = func(_ string, prefix string) (string, error) {
924 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
925 err := os.Mkdir(d, os.ModePerm)
926 if err != nil && strings.Contains(err.Error(), ": file exists") {
927 // Test case must have pre-populated the tempdir
933 checkEmpty := func() {
934 filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
935 c.Check(path, Equals, realTemp)
943 cr.ArvMountPoint = ""
944 cr.Container.Mounts = make(map[string]arvados.Mount)
945 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
946 cr.OutputPath = "/tmp"
948 err := cr.SetupMounts()
950 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
951 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
958 cr.ArvMountPoint = ""
959 cr.Container.Mounts = make(map[string]arvados.Mount)
960 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
961 cr.OutputPath = "/tmp"
964 cr.Container.RuntimeConstraints.API = &apiflag
966 err := cr.SetupMounts()
968 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
969 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
978 cr.ArvMountPoint = ""
979 cr.Container.Mounts = map[string]arvados.Mount{
980 "/keeptmp": {Kind: "collection", Writable: true},
982 cr.OutputPath = "/keeptmp"
984 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
986 err := cr.SetupMounts()
988 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
989 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
996 cr.ArvMountPoint = ""
997 cr.Container.Mounts = map[string]arvados.Mount{
998 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
999 "/keepout": {Kind: "collection", Writable: true},
1001 cr.OutputPath = "/keepout"
1003 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1004 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1006 err := cr.SetupMounts()
1008 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1009 sort.StringSlice(cr.Binds).Sort()
1010 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1011 realTemp + "/keep1/tmp0:/keepout"})
1018 cr.ArvMountPoint = ""
1019 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1020 cr.Container.Mounts = map[string]arvados.Mount{
1021 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1022 "/keepout": {Kind: "collection", Writable: true},
1024 cr.OutputPath = "/keepout"
1026 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1027 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1029 err := cr.SetupMounts()
1031 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1032 sort.StringSlice(cr.Binds).Sort()
1033 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1034 realTemp + "/keep1/tmp0:/keepout"})
1039 for _, test := range []struct {
1043 {in: "foo", out: `"foo"`},
1044 {in: nil, out: `null`},
1045 {in: map[string]int{"foo": 123}, out: `{"foo":123}`},
1048 cr.ArvMountPoint = ""
1049 cr.Container.Mounts = map[string]arvados.Mount{
1050 "/mnt/test.json": {Kind: "json", Content: test.in},
1052 err := cr.SetupMounts()
1054 sort.StringSlice(cr.Binds).Sort()
1055 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
1056 content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
1058 c.Check(content, DeepEquals, []byte(test.out))
1063 // Read-only mount points are allowed underneath output_dir mount point
1066 cr.ArvMountPoint = ""
1067 cr.Container.Mounts = make(map[string]arvados.Mount)
1068 cr.Container.Mounts = map[string]arvados.Mount{
1069 "/tmp": {Kind: "tmp"},
1070 "/tmp/foo": {Kind: "collection"},
1072 cr.OutputPath = "/tmp"
1074 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1076 err := cr.SetupMounts()
1078 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1079 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
1084 // Writable mount points are not allowed underneath output_dir mount point
1087 cr.ArvMountPoint = ""
1088 cr.Container.Mounts = make(map[string]arvados.Mount)
1089 cr.Container.Mounts = map[string]arvados.Mount{
1090 "/tmp": {Kind: "tmp"},
1091 "/tmp/foo": {Kind: "collection", Writable: true},
1093 cr.OutputPath = "/tmp"
1095 err := cr.SetupMounts()
1096 c.Check(err, NotNil)
1097 c.Check(err, ErrorMatches, `Writable mount points are not permitted underneath the output_path.*`)
1102 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1105 cr.ArvMountPoint = ""
1106 cr.Container.Mounts = make(map[string]arvados.Mount)
1107 cr.Container.Mounts = map[string]arvados.Mount{
1108 "/tmp": {Kind: "tmp"},
1109 "/tmp/foo": {Kind: "json"},
1111 cr.OutputPath = "/tmp"
1113 err := cr.SetupMounts()
1114 c.Check(err, NotNil)
1115 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1121 func (s *TestSuite) TestStdout(c *C) {
1123 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1124 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1126 "environment": {"FROBIZ": "bilbo"},
1127 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1128 "output_path": "/tmp",
1130 "runtime_constraints": {}
1133 api, _, _ := FullRunHelper(c, helperRecord, nil, func(t *TestDockerClient) {
1134 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1136 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1139 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1140 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1141 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1144 // Used by the TestStdoutWithWrongPath*()
1145 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1146 rec := arvados.Container{}
1147 err = json.Unmarshal([]byte(record), &rec)
1150 docker := NewTestDockerClient()
1152 docker.RemoveImage(hwImageId, true)
1154 api = &ArvTestClient{Container: rec}
1155 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1156 am := &ArvMountCmdLine{}
1157 cr.RunArvMount = am.ArvMountTest
1163 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1164 _, _, err := StdoutErrorRunHelper(c, `{
1165 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1166 "output_path": "/tmp"
1167 }`, func(t *TestDockerClient) {})
1169 c.Check(err, NotNil)
1170 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1173 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1174 _, _, err := StdoutErrorRunHelper(c, `{
1175 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1176 "output_path": "/tmp"
1177 }`, func(t *TestDockerClient) {})
1179 c.Check(err, NotNil)
1180 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1183 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1184 _, _, err := StdoutErrorRunHelper(c, `{
1185 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1186 "output_path": "/tmp"
1187 }`, func(t *TestDockerClient) {})
1189 c.Check(err, NotNil)
1190 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1193 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1194 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1195 defer os.Unsetenv("ARVADOS_API_HOST")
1196 api, _, _ := FullRunHelper(c, `{
1197 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1198 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1201 "mounts": {"/tmp": {"kind": "tmp"} },
1202 "output_path": "/tmp",
1204 "runtime_constraints": {"API": true}
1205 }`, nil, func(t *TestDockerClient) {
1206 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1208 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1211 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1212 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1213 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1214 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1217 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1218 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1219 defer os.Unsetenv("ARVADOS_API_HOST")
1220 api, _, _ := FullRunHelper(c, `{
1221 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1222 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1225 "mounts": {"/tmp": {"kind": "tmp"} },
1226 "output_path": "/tmp",
1228 "runtime_constraints": {"API": true}
1229 }`, nil, func(t *TestDockerClient) {
1230 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1232 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1235 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1236 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1237 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1240 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1242 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1243 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1245 "environment": {"FROBIZ": "bilbo"},
1247 "/tmp": {"kind": "tmp"},
1248 "/tmp/foo": {"kind": "collection",
1249 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1250 "exclude_from_output": true
1252 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1254 "output_path": "/tmp",
1256 "runtime_constraints": {}
1259 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1261 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, func(t *TestDockerClient) {
1262 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1264 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1267 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1268 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1269 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1272 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1274 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1275 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1277 "environment": {"FROBIZ": "bilbo"},
1279 "/tmp": {"kind": "tmp"},
1280 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1281 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1282 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1283 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1284 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1286 "output_path": "/tmp",
1288 "runtime_constraints": {}
1291 extraMounts := []string{
1292 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1293 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1294 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1297 api, runner, realtemp := FullRunHelper(c, helperRecord, extraMounts, func(t *TestDockerClient) {
1298 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1300 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1303 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/2:/tmp",
1304 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1305 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1306 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1307 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1310 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1311 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1312 for _, v := range api.Content {
1313 if v["collection"] != nil {
1314 c.Check(v["ensure_unique_name"], Equals, true)
1315 collection := v["collection"].(arvadosclient.Dict)
1316 if strings.Index(collection["name"].(string), "output") == 0 {
1317 manifest := collection["manifest_text"].(string)
1319 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1320 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar 9:18:sub1file2
1321 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1322 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1323 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1330 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1332 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1333 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1335 "environment": {"FROBIZ": "bilbo"},
1337 "/tmp": {"kind": "tmp"},
1338 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1339 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1341 "output_path": "/tmp",
1343 "runtime_constraints": {}
1346 extraMounts := []string{
1347 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1350 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, func(t *TestDockerClient) {
1351 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1353 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1356 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1357 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1358 for _, v := range api.Content {
1359 if v["collection"] != nil {
1360 collection := v["collection"].(arvadosclient.Dict)
1361 if strings.Index(collection["name"].(string), "output") == 0 {
1362 manifest := collection["manifest_text"].(string)
1364 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1365 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar