25 "git.curoverse.com/arvados.git/sdk/go/arvados"
26 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
27 "git.curoverse.com/arvados.git/sdk/go/keepclient"
28 "git.curoverse.com/arvados.git/sdk/go/manifest"
30 dockertypes "github.com/docker/docker/api/types"
31 dockercontainer "github.com/docker/docker/api/types/container"
32 dockernetwork "github.com/docker/docker/api/types/network"
36 // Gocheck boilerplate
37 func TestCrunchExec(t *testing.T) {
41 type TestSuite struct{}
43 // Gocheck boilerplate
44 var _ = Suite(&TestSuite{})
46 type ArvTestClient struct {
49 Content []arvadosclient.Dict
51 Logs map[string]*bytes.Buffer
56 type KeepTestClient struct {
61 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
62 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
63 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
65 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
66 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
68 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"
69 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
71 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"
72 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
74 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
75 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
77 type TestDockerClient struct {
79 logReader io.ReadCloser
80 logWriter io.WriteCloser
81 fn func(t *TestDockerClient)
89 func NewTestDockerClient(exitCode int) *TestDockerClient {
90 t := &TestDockerClient{}
91 t.logReader, t.logWriter = io.Pipe()
93 t.stop = make(chan bool)
98 type MockConn struct {
102 func (m *MockConn) Write(b []byte) (int, error) {
106 func NewMockConn() *MockConn {
111 func (t *TestDockerClient) ContainerAttach(ctx context.Context, container string, options dockertypes.ContainerAttachOptions) (dockertypes.HijackedResponse, error) {
112 return dockertypes.HijackedResponse{Conn: NewMockConn(), Reader: bufio.NewReader(t.logReader)}, nil
115 func (t *TestDockerClient) ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error) {
116 if config.WorkingDir != "" {
117 t.cwd = config.WorkingDir
120 return dockercontainer.ContainerCreateCreatedBody{ID: "abcde"}, nil
123 func (t *TestDockerClient) ContainerStart(ctx context.Context, container string, options dockertypes.ContainerStartOptions) error {
124 if container == "abcde" {
128 return errors.New("Invalid container id")
132 func (t *TestDockerClient) ContainerStop(ctx context.Context, container string, timeout *time.Duration) error {
137 func (t *TestDockerClient) ContainerWait(ctx context.Context, container string) (int64, error) {
138 return int64(t.finish), nil
141 func (t *TestDockerClient) ImageInspectWithRaw(ctx context.Context, image string) (dockertypes.ImageInspect, []byte, error) {
142 if t.imageLoaded == image {
143 return dockertypes.ImageInspect{}, nil, nil
145 return dockertypes.ImageInspect{}, nil, errors.New("")
149 func (t *TestDockerClient) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (dockertypes.ImageLoadResponse, error) {
150 _, err := io.Copy(ioutil.Discard, input)
152 return dockertypes.ImageLoadResponse{}, err
154 t.imageLoaded = hwImageId
155 return dockertypes.ImageLoadResponse{Body: ioutil.NopCloser(input)}, nil
159 func (*TestDockerClient) ImageRemove(ctx context.Context, image string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {
163 func (client *ArvTestClient) Create(resourceType string,
164 parameters arvadosclient.Dict,
165 output interface{}) error {
168 defer client.Mutex.Unlock()
171 client.Content = append(client.Content, parameters)
173 if resourceType == "logs" {
174 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
175 if client.Logs == nil {
176 client.Logs = make(map[string]*bytes.Buffer)
178 if client.Logs[et] == nil {
179 client.Logs[et] = &bytes.Buffer{}
181 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
184 if resourceType == "collections" && output != nil {
185 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
186 outmap := output.(*arvados.Collection)
187 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
193 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
195 case method == "GET" && resourceType == "containers" && action == "auth":
196 return json.Unmarshal([]byte(`{
197 "kind": "arvados#api_client_authorization",
198 "uuid": "`+fakeAuthUUID+`",
199 "api_token": "`+fakeAuthToken+`"
202 return fmt.Errorf("Not found")
206 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
207 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
209 "command": ["sleep", "1"],
210 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
213 "mounts": {"/tmp": {"kind": "tmp"} },
214 "output_path": "/tmp",
216 "runtime_constraints": {}
218 return ioutil.NopCloser(bytes.NewReader(j)), nil
221 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
222 if resourceType == "collections" {
224 output.(*arvados.Collection).ManifestText = hwManifest
225 } else if uuid == otherPDH {
226 output.(*arvados.Collection).ManifestText = otherManifest
227 } else if uuid == normalizedWithSubdirsPDH {
228 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
229 } else if uuid == denormalizedWithSubdirsPDH {
230 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
233 if resourceType == "containers" {
234 (*output.(*arvados.Container)) = client.Container
239 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
241 defer client.Mutex.Unlock()
243 client.Content = append(client.Content, parameters)
244 if resourceType == "containers" {
245 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
246 client.WasSetRunning = true
252 var discoveryMap = map[string]interface{}{"defaultTrashLifetime": float64(1209600)}
254 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
255 return discoveryMap[key], nil
258 // CalledWith returns the parameters from the first API call whose
259 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
260 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
261 // no call matches, it returns nil.
262 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
264 for _, content := range client.Content {
265 var v interface{} = content
266 for _, k := range strings.Split(jpath, ".") {
267 if dict, ok := v.(arvadosclient.Dict); !ok {
280 func (client *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
282 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
285 type FileWrapper struct {
290 func (fw FileWrapper) Len() uint64 {
294 func (fw FileWrapper) Seek(int64, int) (int64, error) {
295 return 0, errors.New("not implemented")
298 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
299 if filename == hwImageId+".tar" {
300 rdr := ioutil.NopCloser(&bytes.Buffer{})
302 return FileWrapper{rdr, 1321984}, nil
307 func (client *KeepTestClient) CollectionFileReader(collection map[string]interface{}, filename string) (keepclient.Reader, error) {
308 if filename == "/file1_in_main.txt" {
309 rdr := ioutil.NopCloser(strings.NewReader("foo"))
311 return FileWrapper{rdr, 3}, nil
316 func (s *TestSuite) TestLoadImage(c *C) {
317 kc := &KeepTestClient{}
318 docker := NewTestDockerClient(0)
319 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
321 _, err := cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
323 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
326 cr.Container.ContainerImage = hwPDH
328 // (1) Test loading image from keep
329 c.Check(kc.Called, Equals, false)
330 c.Check(cr.ContainerConfig.Image, Equals, "")
336 cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
339 c.Check(kc.Called, Equals, true)
340 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
342 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
345 // (2) Test using image that's already loaded
347 cr.ContainerConfig.Image = ""
351 c.Check(kc.Called, Equals, false)
352 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
356 type ArvErrorTestClient struct{}
358 func (ArvErrorTestClient) Create(resourceType string,
359 parameters arvadosclient.Dict,
360 output interface{}) error {
364 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
365 return errors.New("ArvError")
368 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
369 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
370 return nil, errors.New("ArvError")
373 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
374 return errors.New("ArvError")
377 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
381 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
382 return discoveryMap[key], nil
385 type KeepErrorTestClient struct{}
387 func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
388 return "", 0, errors.New("KeepError")
391 func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
392 return nil, errors.New("KeepError")
395 func (KeepErrorTestClient) CollectionFileReader(c map[string]interface{}, f string) (keepclient.Reader, error) {
396 return nil, errors.New("KeepError")
399 type KeepReadErrorTestClient struct{}
401 func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
405 type ErrorReader struct{}
407 func (ErrorReader) Read(p []byte) (n int, err error) {
408 return 0, errors.New("ErrorReader")
411 func (ErrorReader) Close() error {
415 func (ErrorReader) Len() uint64 {
419 func (ErrorReader) Seek(int64, int) (int64, error) {
420 return 0, errors.New("ErrorReader")
423 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
424 return ErrorReader{}, nil
427 func (KeepReadErrorTestClient) CollectionFileReader(c map[string]interface{}, f string) (keepclient.Reader, error) {
428 return ErrorReader{}, nil
431 func (s *TestSuite) TestLoadImageArvError(c *C) {
433 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
434 cr.Container.ContainerImage = hwPDH
436 err := cr.LoadImage()
437 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
440 func (s *TestSuite) TestLoadImageKeepError(c *C) {
442 docker := NewTestDockerClient(0)
443 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
444 cr.Container.ContainerImage = hwPDH
446 err := cr.LoadImage()
447 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
450 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
451 // (3) Collection doesn't contain image
452 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
453 cr.Container.ContainerImage = otherPDH
455 err := cr.LoadImage()
456 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
459 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
460 // (4) Collection doesn't contain image
461 docker := NewTestDockerClient(0)
462 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
463 cr.Container.ContainerImage = hwPDH
465 err := cr.LoadImage()
469 type ClosableBuffer struct {
473 func (*ClosableBuffer) Close() error {
477 type TestLogs struct {
478 Stdout ClosableBuffer
479 Stderr ClosableBuffer
482 func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
483 if logstr == "stdout" {
486 if logstr == "stderr" {
492 func dockerLog(fd byte, msg string) []byte {
494 header := make([]byte, 8+len(by))
496 header[7] = byte(len(by))
501 func (s *TestSuite) TestRunContainer(c *C) {
502 docker := NewTestDockerClient(0)
503 docker.fn = func(t *TestDockerClient) {
504 t.logWriter.Write(dockerLog(1, "Hello world\n"))
507 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
510 cr.NewLogWriter = logs.NewTestLoggingWriter
511 cr.Container.ContainerImage = hwPDH
512 cr.Container.Command = []string{"./hw"}
513 err := cr.LoadImage()
516 err = cr.CreateContainer()
519 err = cr.StartContainer()
522 err = cr.WaitFinish()
525 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
526 c.Check(logs.Stderr.String(), Equals, "")
529 func (s *TestSuite) TestCommitLogs(c *C) {
530 api := &ArvTestClient{}
531 kc := &KeepTestClient{}
532 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
533 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
535 cr.CrunchLog.Print("Hello world!")
536 cr.CrunchLog.Print("Goodbye")
537 cr.finalState = "Complete"
539 err := cr.CommitLogs()
542 c.Check(api.Calls, Equals, 2)
543 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
544 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
545 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
546 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
549 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
550 api := &ArvTestClient{}
551 kc := &KeepTestClient{}
552 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
554 err := cr.UpdateContainerRunning()
557 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
560 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
561 api := &ArvTestClient{}
562 kc := &KeepTestClient{}
563 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
565 cr.LogsPDH = new(string)
566 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
568 cr.ExitCode = new(int)
570 cr.finalState = "Complete"
572 err := cr.UpdateContainerFinal()
575 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
576 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
577 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
580 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
581 api := &ArvTestClient{}
582 kc := &KeepTestClient{}
583 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
585 cr.finalState = "Cancelled"
587 err := cr.UpdateContainerFinal()
590 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
591 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
592 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
595 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
596 // dress rehearsal of the Run() function, starting from a JSON container record.
597 func FullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, realTemp string) {
598 rec := arvados.Container{}
599 err := json.Unmarshal([]byte(record), &rec)
602 docker := NewTestDockerClient(exitCode)
604 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
606 api = &ArvTestClient{Container: rec}
608 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
609 cr.statInterval = 100 * time.Millisecond
610 am := &ArvMountCmdLine{}
611 cr.RunArvMount = am.ArvMountTest
613 realTemp, err = ioutil.TempDir("", "crunchrun_test1-")
615 defer os.RemoveAll(realTemp)
618 cr.MkTempDir = func(_ string, prefix string) (string, error) {
620 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
621 err := os.Mkdir(d, os.ModePerm)
622 if err != nil && strings.Contains(err.Error(), ": file exists") {
623 // Test case must have pre-populated the tempdir
629 if extraMounts != nil && len(extraMounts) > 0 {
630 err := cr.SetupArvMountPoint("keep")
633 for _, m := range extraMounts {
634 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
640 c.Check(api.WasSetRunning, Equals, true)
642 c.Check(api.Content[api.Calls-1]["container"].(arvadosclient.Dict)["log"], NotNil)
645 for k, v := range api.Logs {
654 func (s *TestSuite) TestFullRunHello(c *C) {
655 api, _, _ := FullRunHelper(c, `{
656 "command": ["echo", "hello world"],
657 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
660 "mounts": {"/tmp": {"kind": "tmp"} },
661 "output_path": "/tmp",
663 "runtime_constraints": {}
664 }`, nil, 0, func(t *TestDockerClient) {
665 t.logWriter.Write(dockerLog(1, "hello world\n"))
669 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
670 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
671 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
675 func (s *TestSuite) TestCrunchstat(c *C) {
676 api, _, _ := FullRunHelper(c, `{
677 "command": ["sleep", "1"],
678 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
681 "mounts": {"/tmp": {"kind": "tmp"} },
682 "output_path": "/tmp",
684 "runtime_constraints": {}
685 }`, nil, 0, func(t *TestDockerClient) {
686 time.Sleep(time.Second)
690 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
691 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
693 // We didn't actually start a container, so crunchstat didn't
694 // find accounting files and therefore didn't log any stats.
695 // It should have logged a "can't find accounting files"
696 // message after one poll interval, though, so we can confirm
698 c.Assert(api.Logs["crunchstat"], NotNil)
699 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
701 // The "files never appeared" log assures us that we called
702 // (*crunchstat.Reporter)Stop(), and that we set it up with
703 // the correct container ID "abcde":
704 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
707 func (s *TestSuite) TestNodeInfoLog(c *C) {
708 api, _, _ := FullRunHelper(c, `{
709 "command": ["sleep", "1"],
710 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
713 "mounts": {"/tmp": {"kind": "tmp"} },
714 "output_path": "/tmp",
716 "runtime_constraints": {}
718 func(t *TestDockerClient) {
719 time.Sleep(time.Second)
723 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
724 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
726 c.Assert(api.Logs["node-info"], NotNil)
727 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Host Information.*`)
728 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*CPU Information.*`)
729 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Memory Information.*`)
730 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk Space.*`)
731 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk INodes.*`)
734 func (s *TestSuite) TestContainerRecordLog(c *C) {
735 api, _, _ := FullRunHelper(c, `{
736 "command": ["sleep", "1"],
737 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
740 "mounts": {"/tmp": {"kind": "tmp"} },
741 "output_path": "/tmp",
743 "runtime_constraints": {}
745 func(t *TestDockerClient) {
746 time.Sleep(time.Second)
750 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
751 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
753 c.Assert(api.Logs["container"], NotNil)
754 c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
757 func (s *TestSuite) TestFullRunStderr(c *C) {
758 api, _, _ := FullRunHelper(c, `{
759 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
760 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
763 "mounts": {"/tmp": {"kind": "tmp"} },
764 "output_path": "/tmp",
766 "runtime_constraints": {}
767 }`, nil, 1, func(t *TestDockerClient) {
768 t.logWriter.Write(dockerLog(1, "hello\n"))
769 t.logWriter.Write(dockerLog(2, "world\n"))
773 final := api.CalledWith("container.state", "Complete")
774 c.Assert(final, NotNil)
775 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
776 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
778 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
779 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
782 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
783 api, _, _ := FullRunHelper(c, `{
785 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
788 "mounts": {"/tmp": {"kind": "tmp"} },
789 "output_path": "/tmp",
791 "runtime_constraints": {}
792 }`, nil, 0, func(t *TestDockerClient) {
793 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
797 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
798 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
799 c.Log(api.Logs["stdout"])
800 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
803 func (s *TestSuite) TestFullRunSetCwd(c *C) {
804 api, _, _ := FullRunHelper(c, `{
806 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
809 "mounts": {"/tmp": {"kind": "tmp"} },
810 "output_path": "/tmp",
812 "runtime_constraints": {}
813 }`, nil, 0, func(t *TestDockerClient) {
814 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
818 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
819 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
820 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
823 func (s *TestSuite) TestStopOnSignal(c *C) {
824 s.testStopContainer(c, func(cr *ContainerRunner) {
827 time.Sleep(time.Millisecond)
829 cr.SigChan <- syscall.SIGINT
834 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
835 s.testStopContainer(c, func(cr *ContainerRunner) {
836 cr.ArvMountExit = make(chan error)
838 cr.ArvMountExit <- exec.Command("true").Run()
839 close(cr.ArvMountExit)
844 func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
846 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
847 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
850 "mounts": {"/tmp": {"kind": "tmp"} },
851 "output_path": "/tmp",
853 "runtime_constraints": {}
856 rec := arvados.Container{}
857 err := json.Unmarshal([]byte(record), &rec)
860 docker := NewTestDockerClient(0)
861 docker.fn = func(t *TestDockerClient) {
863 t.logWriter.Write(dockerLog(1, "foo\n"))
866 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
868 api := &ArvTestClient{Container: rec}
869 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
870 cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
873 done := make(chan error)
878 case <-time.After(20 * time.Second):
879 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
884 for k, v := range api.Logs {
889 c.Check(api.CalledWith("container.log", nil), NotNil)
890 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
891 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
894 func (s *TestSuite) TestFullRunSetEnv(c *C) {
895 api, _, _ := FullRunHelper(c, `{
896 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
897 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
899 "environment": {"FROBIZ": "bilbo"},
900 "mounts": {"/tmp": {"kind": "tmp"} },
901 "output_path": "/tmp",
903 "runtime_constraints": {}
904 }`, nil, 0, func(t *TestDockerClient) {
905 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
909 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
910 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
911 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
914 type ArvMountCmdLine struct {
919 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
925 func stubCert(temp string) string {
926 path := temp + "/ca-certificates.crt"
927 crt, _ := os.Create(path)
929 arvadosclient.CertFiles = []string{path}
933 func (s *TestSuite) TestSetupMounts(c *C) {
934 api := &ArvTestClient{}
935 kc := &KeepTestClient{}
936 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
937 am := &ArvMountCmdLine{}
938 cr.RunArvMount = am.ArvMountTest
940 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
942 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
944 stubCertPath := stubCert(certTemp)
946 defer os.RemoveAll(realTemp)
947 defer os.RemoveAll(certTemp)
950 cr.MkTempDir = func(_ string, prefix string) (string, error) {
952 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
953 err := os.Mkdir(d, os.ModePerm)
954 if err != nil && strings.Contains(err.Error(), ": file exists") {
955 // Test case must have pre-populated the tempdir
961 checkEmpty := func() {
962 filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
963 c.Check(path, Equals, realTemp)
971 cr.ArvMountPoint = ""
972 cr.Container.Mounts = make(map[string]arvados.Mount)
973 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
974 cr.OutputPath = "/tmp"
976 err := cr.SetupMounts()
978 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
979 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
986 cr.ArvMountPoint = ""
987 cr.Container.Mounts = make(map[string]arvados.Mount)
988 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
989 cr.OutputPath = "/tmp"
992 cr.Container.RuntimeConstraints.API = &apiflag
994 err := cr.SetupMounts()
996 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
997 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
1006 cr.ArvMountPoint = ""
1007 cr.Container.Mounts = map[string]arvados.Mount{
1008 "/keeptmp": {Kind: "collection", Writable: true},
1010 cr.OutputPath = "/keeptmp"
1012 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1014 err := cr.SetupMounts()
1016 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1017 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
1024 cr.ArvMountPoint = ""
1025 cr.Container.Mounts = map[string]arvados.Mount{
1026 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1027 "/keepout": {Kind: "collection", Writable: true},
1029 cr.OutputPath = "/keepout"
1031 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1032 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1034 err := cr.SetupMounts()
1036 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1037 sort.StringSlice(cr.Binds).Sort()
1038 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1039 realTemp + "/keep1/tmp0:/keepout"})
1046 cr.ArvMountPoint = ""
1047 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1048 cr.Container.Mounts = map[string]arvados.Mount{
1049 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1050 "/keepout": {Kind: "collection", Writable: true},
1052 cr.OutputPath = "/keepout"
1054 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1055 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1057 err := cr.SetupMounts()
1059 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1060 sort.StringSlice(cr.Binds).Sort()
1061 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1062 realTemp + "/keep1/tmp0:/keepout"})
1067 for _, test := range []struct {
1071 {in: "foo", out: `"foo"`},
1072 {in: nil, out: `null`},
1073 {in: map[string]int{"foo": 123}, out: `{"foo":123}`},
1076 cr.ArvMountPoint = ""
1077 cr.Container.Mounts = map[string]arvados.Mount{
1078 "/mnt/test.json": {Kind: "json", Content: test.in},
1080 err := cr.SetupMounts()
1082 sort.StringSlice(cr.Binds).Sort()
1083 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
1084 content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
1086 c.Check(content, DeepEquals, []byte(test.out))
1091 // Read-only mount points are allowed underneath output_dir mount point
1094 cr.ArvMountPoint = ""
1095 cr.Container.Mounts = make(map[string]arvados.Mount)
1096 cr.Container.Mounts = map[string]arvados.Mount{
1097 "/tmp": {Kind: "tmp"},
1098 "/tmp/foo": {Kind: "collection"},
1100 cr.OutputPath = "/tmp"
1102 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1104 err := cr.SetupMounts()
1106 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1107 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
1112 // Writable mount points are not allowed underneath output_dir mount point
1115 cr.ArvMountPoint = ""
1116 cr.Container.Mounts = make(map[string]arvados.Mount)
1117 cr.Container.Mounts = map[string]arvados.Mount{
1118 "/tmp": {Kind: "tmp"},
1119 "/tmp/foo": {Kind: "collection", Writable: true},
1121 cr.OutputPath = "/tmp"
1123 err := cr.SetupMounts()
1124 c.Check(err, NotNil)
1125 c.Check(err, ErrorMatches, `Writable mount points are not permitted underneath the output_path.*`)
1130 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1133 cr.ArvMountPoint = ""
1134 cr.Container.Mounts = make(map[string]arvados.Mount)
1135 cr.Container.Mounts = map[string]arvados.Mount{
1136 "/tmp": {Kind: "tmp"},
1137 "/tmp/foo": {Kind: "json"},
1139 cr.OutputPath = "/tmp"
1141 err := cr.SetupMounts()
1142 c.Check(err, NotNil)
1143 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1148 // Only mount point of kind 'collection' is allowed for stdin
1151 cr.ArvMountPoint = ""
1152 cr.Container.Mounts = make(map[string]arvados.Mount)
1153 cr.Container.Mounts = map[string]arvados.Mount{
1154 "stdin": {Kind: "tmp"},
1157 err := cr.SetupMounts()
1158 c.Check(err, NotNil)
1159 c.Check(err, ErrorMatches, `Unsupported mount kind 'tmp' for stdin.*`)
1165 func (s *TestSuite) TestStdout(c *C) {
1167 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1168 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1170 "environment": {"FROBIZ": "bilbo"},
1171 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1172 "output_path": "/tmp",
1174 "runtime_constraints": {}
1177 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1178 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1182 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1183 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1184 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1187 // Used by the TestStdoutWithWrongPath*()
1188 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1189 rec := arvados.Container{}
1190 err = json.Unmarshal([]byte(record), &rec)
1193 docker := NewTestDockerClient(0)
1195 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1197 api = &ArvTestClient{Container: rec}
1198 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1199 am := &ArvMountCmdLine{}
1200 cr.RunArvMount = am.ArvMountTest
1206 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1207 _, _, err := StdoutErrorRunHelper(c, `{
1208 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1209 "output_path": "/tmp"
1210 }`, func(t *TestDockerClient) {})
1212 c.Check(err, NotNil)
1213 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1216 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1217 _, _, err := StdoutErrorRunHelper(c, `{
1218 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1219 "output_path": "/tmp"
1220 }`, func(t *TestDockerClient) {})
1222 c.Check(err, NotNil)
1223 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1226 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1227 _, _, err := StdoutErrorRunHelper(c, `{
1228 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1229 "output_path": "/tmp"
1230 }`, func(t *TestDockerClient) {})
1232 c.Check(err, NotNil)
1233 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1236 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1237 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1238 defer os.Unsetenv("ARVADOS_API_HOST")
1239 api, _, _ := FullRunHelper(c, `{
1240 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1241 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1244 "mounts": {"/tmp": {"kind": "tmp"} },
1245 "output_path": "/tmp",
1247 "runtime_constraints": {"API": true}
1248 }`, nil, 0, func(t *TestDockerClient) {
1249 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1253 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1254 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1255 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1256 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1259 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1260 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1261 defer os.Unsetenv("ARVADOS_API_HOST")
1262 api, _, _ := FullRunHelper(c, `{
1263 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1264 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1267 "mounts": {"/tmp": {"kind": "tmp"} },
1268 "output_path": "/tmp",
1270 "runtime_constraints": {"API": true}
1271 }`, nil, 0, func(t *TestDockerClient) {
1272 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1276 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1277 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1278 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1281 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1283 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1284 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1286 "environment": {"FROBIZ": "bilbo"},
1288 "/tmp": {"kind": "tmp"},
1289 "/tmp/foo": {"kind": "collection",
1290 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1291 "exclude_from_output": true
1293 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1295 "output_path": "/tmp",
1297 "runtime_constraints": {}
1300 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1302 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1303 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1307 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1308 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1309 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1312 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1314 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1315 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1317 "environment": {"FROBIZ": "bilbo"},
1319 "/tmp": {"kind": "tmp"},
1320 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1321 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1322 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1323 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1324 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1326 "output_path": "/tmp",
1328 "runtime_constraints": {}
1331 extraMounts := []string{
1332 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1333 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1334 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1337 api, runner, realtemp := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1338 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1342 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/2:/tmp",
1343 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1344 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1345 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1346 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1349 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1350 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1351 for _, v := range api.Content {
1352 if v["collection"] != nil {
1353 c.Check(v["ensure_unique_name"], Equals, true)
1354 collection := v["collection"].(arvadosclient.Dict)
1355 if strings.Index(collection["name"].(string), "output") == 0 {
1356 manifest := collection["manifest_text"].(string)
1358 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1359 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar 9:18:sub1file2
1360 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1361 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1362 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1369 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1371 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1372 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1374 "environment": {"FROBIZ": "bilbo"},
1376 "/tmp": {"kind": "tmp"},
1377 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1378 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1380 "output_path": "/tmp",
1382 "runtime_constraints": {}
1385 extraMounts := []string{
1386 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1389 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1390 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1394 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1395 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1396 for _, v := range api.Content {
1397 if v["collection"] != nil {
1398 collection := v["collection"].(arvadosclient.Dict)
1399 if strings.Index(collection["name"].(string), "output") == 0 {
1400 manifest := collection["manifest_text"].(string)
1402 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1403 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1410 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1412 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1413 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1415 "environment": {"FROBIZ": "bilbo"},
1417 "/tmp": {"kind": "tmp"},
1418 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1419 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1421 "output_path": "/tmp",
1423 "runtime_constraints": {}
1426 extraMounts := []string{
1427 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1430 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1431 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1435 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1436 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1437 for _, v := range api.Content {
1438 if v["collection"] != nil {
1439 collection := v["collection"].(arvadosclient.Dict)
1440 if strings.Index(collection["name"].(string), "output") == 0 {
1441 manifest := collection["manifest_text"].(string)
1443 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1450 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1452 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1453 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1455 "environment": {"FROBIZ": "bilbo"},
1457 "/tmp": {"kind": "tmp"},
1458 "stdin": {"kind": "json", "content": "foo"},
1459 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1461 "output_path": "/tmp",
1463 "runtime_constraints": {}
1466 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1467 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1471 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1472 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1473 for _, v := range api.Content {
1474 if v["collection"] != nil {
1475 collection := v["collection"].(arvadosclient.Dict)
1476 if strings.Index(collection["name"].(string), "output") == 0 {
1477 manifest := collection["manifest_text"].(string)
1479 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out