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 normalizedManifestWithSubdirs = ". 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 0:9:file1_in_main.txt 9:18:file2_in_main.txt 27:5649: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"
61 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
63 var denormalizedManifestWithSubdirs = ". 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 0:9:file1_in_main.txt 9:18:file2_in_main.txt 27:5649:zzzzz-8i9sb-bcdefghijkdhvnk.log.txt 5676:10:subdir1/file1_in_subdir1.txt 5686:18:subdir1/file2_in_subdir1.txt\n"
64 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
66 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
67 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
69 type TestDockerClient struct {
71 logReader io.ReadCloser
72 logWriter io.WriteCloser
73 fn func(t *TestDockerClient)
74 finish chan dockerclient.WaitResult
81 func NewTestDockerClient() *TestDockerClient {
82 t := &TestDockerClient{}
83 t.logReader, t.logWriter = io.Pipe()
84 t.finish = make(chan dockerclient.WaitResult)
85 t.stop = make(chan bool)
90 func (t *TestDockerClient) StopContainer(id string, timeout int) error {
95 func (t *TestDockerClient) InspectImage(id string) (*dockerclient.ImageInfo, error) {
96 if t.imageLoaded == id {
97 return &dockerclient.ImageInfo{}, nil
99 return nil, errors.New("")
103 func (t *TestDockerClient) LoadImage(reader io.Reader) error {
104 _, err := io.Copy(ioutil.Discard, reader)
108 t.imageLoaded = hwImageId
113 func (t *TestDockerClient) CreateContainer(config *dockerclient.ContainerConfig, name string, authConfig *dockerclient.AuthConfig) (string, error) {
114 if config.WorkingDir != "" {
115 t.cwd = config.WorkingDir
121 func (t *TestDockerClient) StartContainer(id string, config *dockerclient.HostConfig) error {
126 return errors.New("Invalid container id")
130 func (t *TestDockerClient) AttachContainer(id string, options *dockerclient.AttachOptions) (io.ReadCloser, error) {
131 return t.logReader, nil
134 func (t *TestDockerClient) Wait(id string) <-chan dockerclient.WaitResult {
138 func (*TestDockerClient) RemoveImage(name string, force bool) ([]*dockerclient.ImageDelete, error) {
142 func (client *ArvTestClient) Create(resourceType string,
143 parameters arvadosclient.Dict,
144 output interface{}) error {
147 defer client.Mutex.Unlock()
150 client.Content = append(client.Content, parameters)
152 if resourceType == "logs" {
153 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
154 if client.Logs == nil {
155 client.Logs = make(map[string]*bytes.Buffer)
157 if client.Logs[et] == nil {
158 client.Logs[et] = &bytes.Buffer{}
160 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
163 if resourceType == "collections" && output != nil {
164 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
165 outmap := output.(*arvados.Collection)
166 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
172 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
174 case method == "GET" && resourceType == "containers" && action == "auth":
175 return json.Unmarshal([]byte(`{
176 "kind": "arvados#api_client_authorization",
177 "uuid": "`+fakeAuthUUID+`",
178 "api_token": "`+fakeAuthToken+`"
181 return fmt.Errorf("Not found")
185 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
186 if resourceType == "collections" {
188 output.(*arvados.Collection).ManifestText = hwManifest
189 } else if uuid == otherPDH {
190 output.(*arvados.Collection).ManifestText = otherManifest
191 } else if uuid == normalizedWithSubdirsPDH {
192 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
193 } else if uuid == denormalizedWithSubdirsPDH {
194 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
197 if resourceType == "containers" {
198 (*output.(*arvados.Container)) = client.Container
203 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
205 defer client.Mutex.Unlock()
207 client.Content = append(client.Content, parameters)
208 if resourceType == "containers" {
209 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
210 client.WasSetRunning = true
216 var discoveryMap = map[string]interface{}{"defaultTrashLifetime": float64(1209600)}
218 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
219 return discoveryMap[key], nil
222 // CalledWith returns the parameters from the first API call whose
223 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
224 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
225 // no call matches, it returns nil.
226 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
228 for _, content := range client.Content {
229 var v interface{} = content
230 for _, k := range strings.Split(jpath, ".") {
231 if dict, ok := v.(arvadosclient.Dict); !ok {
244 func (client *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
246 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
249 type FileWrapper struct {
254 func (fw FileWrapper) Len() uint64 {
258 func (fw FileWrapper) Seek(int64, int) (int64, error) {
259 return 0, errors.New("not implemented")
262 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
263 if filename == hwImageId+".tar" {
264 rdr := ioutil.NopCloser(&bytes.Buffer{})
266 return FileWrapper{rdr, 1321984}, nil
271 func (s *TestSuite) TestLoadImage(c *C) {
272 kc := &KeepTestClient{}
273 docker := NewTestDockerClient()
274 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
276 _, err := cr.Docker.RemoveImage(hwImageId, true)
278 _, err = cr.Docker.InspectImage(hwImageId)
281 cr.Container.ContainerImage = hwPDH
283 // (1) Test loading image from keep
284 c.Check(kc.Called, Equals, false)
285 c.Check(cr.ContainerConfig.Image, Equals, "")
291 cr.Docker.RemoveImage(hwImageId, true)
294 c.Check(kc.Called, Equals, true)
295 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
297 _, err = cr.Docker.InspectImage(hwImageId)
300 // (2) Test using image that's already loaded
302 cr.ContainerConfig.Image = ""
306 c.Check(kc.Called, Equals, false)
307 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
311 type ArvErrorTestClient struct{}
313 func (ArvErrorTestClient) Create(resourceType string,
314 parameters arvadosclient.Dict,
315 output interface{}) error {
319 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
320 return errors.New("ArvError")
323 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
324 return errors.New("ArvError")
327 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
331 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
332 return discoveryMap[key], nil
335 type KeepErrorTestClient struct{}
337 func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
338 return "", 0, errors.New("KeepError")
341 func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
342 return nil, errors.New("KeepError")
345 type KeepReadErrorTestClient struct{}
347 func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
351 type ErrorReader struct{}
353 func (ErrorReader) Read(p []byte) (n int, err error) {
354 return 0, errors.New("ErrorReader")
357 func (ErrorReader) Close() error {
361 func (ErrorReader) Len() uint64 {
365 func (ErrorReader) Seek(int64, int) (int64, error) {
366 return 0, errors.New("ErrorReader")
369 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
370 return ErrorReader{}, nil
373 func (s *TestSuite) TestLoadImageArvError(c *C) {
375 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
376 cr.Container.ContainerImage = hwPDH
378 err := cr.LoadImage()
379 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
382 func (s *TestSuite) TestLoadImageKeepError(c *C) {
384 docker := NewTestDockerClient()
385 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
386 cr.Container.ContainerImage = hwPDH
388 err := cr.LoadImage()
389 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
392 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
393 // (3) Collection doesn't contain image
394 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
395 cr.Container.ContainerImage = otherPDH
397 err := cr.LoadImage()
398 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
401 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
402 // (4) Collection doesn't contain image
403 docker := NewTestDockerClient()
404 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
405 cr.Container.ContainerImage = hwPDH
407 err := cr.LoadImage()
411 type ClosableBuffer struct {
415 func (*ClosableBuffer) Close() error {
419 type TestLogs struct {
420 Stdout ClosableBuffer
421 Stderr ClosableBuffer
424 func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
425 if logstr == "stdout" {
428 if logstr == "stderr" {
434 func dockerLog(fd byte, msg string) []byte {
436 header := make([]byte, 8+len(by))
438 header[7] = byte(len(by))
443 func (s *TestSuite) TestRunContainer(c *C) {
444 docker := NewTestDockerClient()
445 docker.fn = func(t *TestDockerClient) {
446 t.logWriter.Write(dockerLog(1, "Hello world\n"))
448 t.finish <- dockerclient.WaitResult{}
450 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
453 cr.NewLogWriter = logs.NewTestLoggingWriter
454 cr.Container.ContainerImage = hwPDH
455 cr.Container.Command = []string{"./hw"}
456 err := cr.LoadImage()
459 err = cr.CreateContainer()
462 err = cr.StartContainer()
465 err = cr.WaitFinish()
468 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
469 c.Check(logs.Stderr.String(), Equals, "")
472 func (s *TestSuite) TestCommitLogs(c *C) {
473 api := &ArvTestClient{}
474 kc := &KeepTestClient{}
475 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
476 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
478 cr.CrunchLog.Print("Hello world!")
479 cr.CrunchLog.Print("Goodbye")
480 cr.finalState = "Complete"
482 err := cr.CommitLogs()
485 c.Check(api.Calls, Equals, 2)
486 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
487 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
488 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
491 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
492 api := &ArvTestClient{}
493 kc := &KeepTestClient{}
494 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
496 err := cr.UpdateContainerRunning()
499 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
502 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
503 api := &ArvTestClient{}
504 kc := &KeepTestClient{}
505 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
507 cr.LogsPDH = new(string)
508 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
510 cr.ExitCode = new(int)
512 cr.finalState = "Complete"
514 err := cr.UpdateContainerFinal()
517 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
518 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
519 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
522 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
523 api := &ArvTestClient{}
524 kc := &KeepTestClient{}
525 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
527 cr.finalState = "Cancelled"
529 err := cr.UpdateContainerFinal()
532 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
533 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
534 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
537 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
538 // dress rehearsal of the Run() function, starting from a JSON container record.
539 func FullRunHelper(c *C, record string, extraMounts []string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner) {
540 rec := arvados.Container{}
541 err := json.Unmarshal([]byte(record), &rec)
544 docker := NewTestDockerClient()
546 docker.RemoveImage(hwImageId, true)
548 api = &ArvTestClient{Container: rec}
550 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
551 cr.statInterval = 100 * time.Millisecond
552 am := &ArvMountCmdLine{}
553 cr.RunArvMount = am.ArvMountTest
555 if extraMounts != nil && len(extraMounts) > 0 {
556 err := cr.SetupArvMountPoint("keep")
559 for _, m := range extraMounts {
560 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
566 c.Check(api.WasSetRunning, Equals, true)
568 c.Check(api.Content[api.Calls-1]["container"].(arvadosclient.Dict)["log"], NotNil)
571 for k, v := range api.Logs {
580 func (s *TestSuite) TestFullRunHello(c *C) {
581 api, _ := FullRunHelper(c, `{
582 "command": ["echo", "hello world"],
583 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
586 "mounts": {"/tmp": {"kind": "tmp"} },
587 "output_path": "/tmp",
589 "runtime_constraints": {}
590 }`, nil, func(t *TestDockerClient) {
591 t.logWriter.Write(dockerLog(1, "hello world\n"))
593 t.finish <- dockerclient.WaitResult{}
596 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
597 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
598 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
602 func (s *TestSuite) TestCrunchstat(c *C) {
603 api, _ := FullRunHelper(c, `{
604 "command": ["sleep", "1"],
605 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
608 "mounts": {"/tmp": {"kind": "tmp"} },
609 "output_path": "/tmp",
611 "runtime_constraints": {}
612 }`, nil, func(t *TestDockerClient) {
613 time.Sleep(time.Second)
615 t.finish <- dockerclient.WaitResult{}
618 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
619 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
621 // We didn't actually start a container, so crunchstat didn't
622 // find accounting files and therefore didn't log any stats.
623 // It should have logged a "can't find accounting files"
624 // message after one poll interval, though, so we can confirm
626 c.Assert(api.Logs["crunchstat"], NotNil)
627 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
629 // The "files never appeared" log assures us that we called
630 // (*crunchstat.Reporter)Stop(), and that we set it up with
631 // the correct container ID "abcde":
632 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
635 func (s *TestSuite) TestFullRunStderr(c *C) {
636 api, _ := FullRunHelper(c, `{
637 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
638 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
641 "mounts": {"/tmp": {"kind": "tmp"} },
642 "output_path": "/tmp",
644 "runtime_constraints": {}
645 }`, nil, func(t *TestDockerClient) {
646 t.logWriter.Write(dockerLog(1, "hello\n"))
647 t.logWriter.Write(dockerLog(2, "world\n"))
649 t.finish <- dockerclient.WaitResult{ExitCode: 1}
652 final := api.CalledWith("container.state", "Complete")
653 c.Assert(final, NotNil)
654 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
655 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
657 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
658 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
661 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
662 api, _ := FullRunHelper(c, `{
664 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
667 "mounts": {"/tmp": {"kind": "tmp"} },
668 "output_path": "/tmp",
670 "runtime_constraints": {}
671 }`, nil, func(t *TestDockerClient) {
672 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
674 t.finish <- dockerclient.WaitResult{ExitCode: 0}
677 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
678 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
679 c.Log(api.Logs["stdout"])
680 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
683 func (s *TestSuite) TestFullRunSetCwd(c *C) {
684 api, _ := FullRunHelper(c, `{
686 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
689 "mounts": {"/tmp": {"kind": "tmp"} },
690 "output_path": "/tmp",
692 "runtime_constraints": {}
693 }`, nil, func(t *TestDockerClient) {
694 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
696 t.finish <- dockerclient.WaitResult{ExitCode: 0}
699 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
700 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
701 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
704 func (s *TestSuite) TestCancel(c *C) {
706 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
707 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
710 "mounts": {"/tmp": {"kind": "tmp"} },
711 "output_path": "/tmp",
713 "runtime_constraints": {}
716 rec := arvados.Container{}
717 err := json.Unmarshal([]byte(record), &rec)
720 docker := NewTestDockerClient()
721 docker.fn = func(t *TestDockerClient) {
723 t.logWriter.Write(dockerLog(1, "foo\n"))
725 t.finish <- dockerclient.WaitResult{ExitCode: 0}
727 docker.RemoveImage(hwImageId, true)
729 api := &ArvTestClient{Container: rec}
730 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
731 am := &ArvMountCmdLine{}
732 cr.RunArvMount = am.ArvMountTest
735 for cr.ContainerID == "" {
736 time.Sleep(time.Millisecond)
738 cr.SigChan <- syscall.SIGINT
745 for k, v := range api.Logs {
751 c.Check(api.CalledWith("container.log", nil), NotNil)
752 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
753 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
757 func (s *TestSuite) TestFullRunSetEnv(c *C) {
758 api, _ := FullRunHelper(c, `{
759 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
760 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
762 "environment": {"FROBIZ": "bilbo"},
763 "mounts": {"/tmp": {"kind": "tmp"} },
764 "output_path": "/tmp",
766 "runtime_constraints": {}
767 }`, nil, func(t *TestDockerClient) {
768 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
770 t.finish <- dockerclient.WaitResult{ExitCode: 0}
773 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
774 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
775 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
778 type ArvMountCmdLine struct {
783 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
789 func stubCert(temp string) string {
790 path := temp + "/ca-certificates.crt"
791 crt, _ := os.Create(path)
793 arvadosclient.CertFiles = []string{path}
797 func (s *TestSuite) TestSetupMounts(c *C) {
798 api := &ArvTestClient{}
799 kc := &KeepTestClient{}
800 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
801 am := &ArvMountCmdLine{}
802 cr.RunArvMount = am.ArvMountTest
804 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
806 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
808 stubCertPath := stubCert(certTemp)
810 defer os.RemoveAll(realTemp)
811 defer os.RemoveAll(certTemp)
814 cr.MkTempDir = func(_ string, prefix string) (string, error) {
816 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
817 err := os.Mkdir(d, os.ModePerm)
818 if err != nil && strings.Contains(err.Error(), ": file exists") {
819 // Test case must have pre-populated the tempdir
825 checkEmpty := func() {
826 filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
827 c.Check(path, Equals, realTemp)
835 cr.ArvMountPoint = ""
836 cr.Container.Mounts = make(map[string]arvados.Mount)
837 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
838 cr.OutputPath = "/tmp"
840 err := cr.SetupMounts()
842 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
843 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
850 cr.ArvMountPoint = ""
851 cr.Container.Mounts = make(map[string]arvados.Mount)
852 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
853 cr.OutputPath = "/tmp"
856 cr.Container.RuntimeConstraints.API = &apiflag
858 err := cr.SetupMounts()
860 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
861 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
870 cr.ArvMountPoint = ""
871 cr.Container.Mounts = map[string]arvados.Mount{
872 "/keeptmp": {Kind: "collection", Writable: true},
874 cr.OutputPath = "/keeptmp"
876 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
878 err := cr.SetupMounts()
880 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
881 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
888 cr.ArvMountPoint = ""
889 cr.Container.Mounts = map[string]arvados.Mount{
890 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
891 "/keepout": {Kind: "collection", Writable: true},
893 cr.OutputPath = "/keepout"
895 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
896 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
898 err := cr.SetupMounts()
900 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
901 sort.StringSlice(cr.Binds).Sort()
902 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
903 realTemp + "/keep1/tmp0:/keepout"})
910 cr.ArvMountPoint = ""
911 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
912 cr.Container.Mounts = map[string]arvados.Mount{
913 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
914 "/keepout": {Kind: "collection", Writable: true},
916 cr.OutputPath = "/keepout"
918 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
919 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
921 err := cr.SetupMounts()
923 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
924 sort.StringSlice(cr.Binds).Sort()
925 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
926 realTemp + "/keep1/tmp0:/keepout"})
931 for _, test := range []struct {
935 {in: "foo", out: `"foo"`},
936 {in: nil, out: `null`},
937 {in: map[string]int{"foo": 123}, out: `{"foo":123}`},
940 cr.ArvMountPoint = ""
941 cr.Container.Mounts = map[string]arvados.Mount{
942 "/mnt/test.json": {Kind: "json", Content: test.in},
944 err := cr.SetupMounts()
946 sort.StringSlice(cr.Binds).Sort()
947 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
948 content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
950 c.Check(content, DeepEquals, []byte(test.out))
955 // Read-only mount points are allowed underneath output_dir mount point
958 cr.ArvMountPoint = ""
959 cr.Container.Mounts = make(map[string]arvados.Mount)
960 cr.Container.Mounts = map[string]arvados.Mount{
961 "/tmp": {Kind: "tmp"},
962 "/tmp/foo": {Kind: "collection"},
964 cr.OutputPath = "/tmp"
966 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
968 err := cr.SetupMounts()
970 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
971 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
976 // Writable mount points are not allowed underneath output_dir mount point
979 cr.ArvMountPoint = ""
980 cr.Container.Mounts = make(map[string]arvados.Mount)
981 cr.Container.Mounts = map[string]arvados.Mount{
982 "/tmp": {Kind: "tmp"},
983 "/tmp/foo": {Kind: "collection", Writable: true},
985 cr.OutputPath = "/tmp"
987 err := cr.SetupMounts()
989 c.Check(err, ErrorMatches, `Writable mount points are not permitted underneath the output_path.*`)
994 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
997 cr.ArvMountPoint = ""
998 cr.Container.Mounts = make(map[string]arvados.Mount)
999 cr.Container.Mounts = map[string]arvados.Mount{
1000 "/tmp": {Kind: "tmp"},
1001 "/tmp/foo": {Kind: "json"},
1003 cr.OutputPath = "/tmp"
1005 err := cr.SetupMounts()
1006 c.Check(err, NotNil)
1007 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1013 func (s *TestSuite) TestStdout(c *C) {
1015 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1016 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1018 "environment": {"FROBIZ": "bilbo"},
1019 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1020 "output_path": "/tmp",
1022 "runtime_constraints": {}
1025 api, _ := FullRunHelper(c, helperRecord, nil, func(t *TestDockerClient) {
1026 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1028 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1031 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1032 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1033 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1036 // Used by the TestStdoutWithWrongPath*()
1037 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1038 rec := arvados.Container{}
1039 err = json.Unmarshal([]byte(record), &rec)
1042 docker := NewTestDockerClient()
1044 docker.RemoveImage(hwImageId, true)
1046 api = &ArvTestClient{Container: rec}
1047 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1048 am := &ArvMountCmdLine{}
1049 cr.RunArvMount = am.ArvMountTest
1055 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1056 _, _, err := StdoutErrorRunHelper(c, `{
1057 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1058 "output_path": "/tmp"
1059 }`, func(t *TestDockerClient) {})
1061 c.Check(err, NotNil)
1062 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1065 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1066 _, _, err := StdoutErrorRunHelper(c, `{
1067 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1068 "output_path": "/tmp"
1069 }`, func(t *TestDockerClient) {})
1071 c.Check(err, NotNil)
1072 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1075 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1076 _, _, err := StdoutErrorRunHelper(c, `{
1077 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1078 "output_path": "/tmp"
1079 }`, func(t *TestDockerClient) {})
1081 c.Check(err, NotNil)
1082 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1085 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1086 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1087 defer os.Unsetenv("ARVADOS_API_HOST")
1088 api, _ := FullRunHelper(c, `{
1089 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1090 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1093 "mounts": {"/tmp": {"kind": "tmp"} },
1094 "output_path": "/tmp",
1096 "runtime_constraints": {"API": true}
1097 }`, nil, func(t *TestDockerClient) {
1098 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1100 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1103 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1104 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1105 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1106 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1109 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1110 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1111 defer os.Unsetenv("ARVADOS_API_HOST")
1112 api, _ := FullRunHelper(c, `{
1113 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1114 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1117 "mounts": {"/tmp": {"kind": "tmp"} },
1118 "output_path": "/tmp",
1120 "runtime_constraints": {"API": true}
1121 }`, nil, func(t *TestDockerClient) {
1122 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1124 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1127 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1128 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1129 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1132 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1134 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1135 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1137 "environment": {"FROBIZ": "bilbo"},
1139 "/tmp": {"kind": "tmp"},
1140 "/tmp/foo": {"kind": "collection",
1141 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1142 "exclude_from_output": true
1144 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1146 "output_path": "/tmp",
1148 "runtime_constraints": {}
1151 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1153 api, _ := FullRunHelper(c, helperRecord, extraMounts, func(t *TestDockerClient) {
1154 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1156 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1159 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1160 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1161 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1164 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1166 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1167 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1169 "environment": {"FROBIZ": "bilbo"},
1171 "/tmp": {"kind": "tmp"},
1172 "/tmp/foo": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/"},
1173 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1174 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1175 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1176 "/tmp/foo/bar/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1177 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1179 "output_path": "/tmp",
1181 "runtime_constraints": {}
1184 extraMounts := []string{"a0def87f80dd594d4675809e83bd4f15+367"}
1186 api, _ := FullRunHelper(c, helperRecord, extraMounts, func(t *TestDockerClient) {
1187 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1189 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1192 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1193 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1194 for _, v := range api.Content {
1195 if v["collection"] != nil {
1196 collection := v["collection"].(arvadosclient.Dict)
1197 if strings.Index(collection["name"].(string), "output") == 0 {
1198 manifest := collection["manifest_text"].(string)
1200 c.Check(-1, Not(Equals), strings.Index(manifest, "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out"))
1202 origManifestWithDotReplacedAsFoo := strings.Replace(normalizedManifestWithSubdirs, "./", "./foo/", -1)
1203 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo"+origManifestWithDotReplacedAsFoo[1:]))
1205 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar"))
1207 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt"))
1209 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:sub1file2"))
1211 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo/bar 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2"))
1217 func (s *TestSuite) TestStdoutWithMountPointForFileUnderOutputDir(c *C) {
1219 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1220 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1222 "environment": {"FROBIZ": "bilbo"},
1224 "/tmp": {"kind": "tmp"},
1225 "/tmp/foo": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367"},
1226 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt"},
1227 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367/subdir1/"},
1228 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1229 "/tmp/foo/bar/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt"},
1230 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1232 "output_path": "/tmp",
1234 "runtime_constraints": {}
1237 extraMounts := []string{
1238 "a0def87f80dd594d4675809e83bd4f15+367",
1239 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1240 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1241 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1244 api, _ := FullRunHelper(c, helperRecord, extraMounts, func(t *TestDockerClient) {
1245 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1247 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1250 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1251 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1252 for _, v := range api.Content {
1253 if v["collection"] != nil {
1254 collection := v["collection"].(arvadosclient.Dict)
1255 if strings.Index(collection["name"].(string), "output") == 0 {
1256 manifest := collection["manifest_text"].(string)
1258 c.Check(-1, Not(Equals), strings.Index(manifest, "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out"))
1260 origManifestWithDotReplacedAsFoo := strings.Replace(normalizedManifestWithSubdirs, "./", "./foo/", -1)
1261 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo"+origManifestWithDotReplacedAsFoo[1:]))
1263 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar"))
1265 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt"))
1267 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:sub1file2"))
1269 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo/bar 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2"))
1275 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1277 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1278 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1280 "environment": {"FROBIZ": "bilbo"},
1282 "/tmp": {"kind": "tmp"},
1283 "/tmp/foo": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path":"/"},
1284 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path":"subdir1/file2_in_subdir1.txt"},
1285 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1287 "output_path": "/tmp",
1289 "runtime_constraints": {}
1292 extraMounts := []string{"b0def87f80dd594d4675809e83bd4f15+367"}
1294 api, _ := FullRunHelper(c, helperRecord, extraMounts, func(t *TestDockerClient) {
1295 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1297 t.finish <- dockerclient.WaitResult{ExitCode: 0}
1300 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1301 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1302 for _, v := range api.Content {
1303 if v["collection"] != nil {
1304 collection := v["collection"].(arvadosclient.Dict)
1305 if strings.Index(collection["name"].(string), "output") == 0 {
1306 manifest := collection["manifest_text"].(string)
1308 c.Check(-1, Not(Equals), strings.Index(manifest, "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out"))
1310 origManifestWithDotReplacedAsFoo := strings.Replace(denormalizedManifestWithSubdirs, "./", "./foo/", -1)
1311 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo"+origManifestWithDotReplacedAsFoo[1:]))
1313 c.Check(-1, Not(Equals), strings.Index(manifest, "./foo/bar 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 5686:18:subdir1/file2_in_subdir1.txt"))