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
303 } else if filename == "/file1_in_main.txt" {
304 rdr := ioutil.NopCloser(strings.NewReader("foo"))
306 return FileWrapper{rdr, 3}, nil
311 func (s *TestSuite) TestLoadImage(c *C) {
312 kc := &KeepTestClient{}
313 docker := NewTestDockerClient(0)
314 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
316 _, err := cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
318 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
321 cr.Container.ContainerImage = hwPDH
323 // (1) Test loading image from keep
324 c.Check(kc.Called, Equals, false)
325 c.Check(cr.ContainerConfig.Image, Equals, "")
331 cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
334 c.Check(kc.Called, Equals, true)
335 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
337 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
340 // (2) Test using image that's already loaded
342 cr.ContainerConfig.Image = ""
346 c.Check(kc.Called, Equals, false)
347 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
351 type ArvErrorTestClient struct{}
353 func (ArvErrorTestClient) Create(resourceType string,
354 parameters arvadosclient.Dict,
355 output interface{}) error {
359 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
360 return errors.New("ArvError")
363 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
364 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
365 return nil, errors.New("ArvError")
368 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
369 return errors.New("ArvError")
372 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
376 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
377 return discoveryMap[key], nil
380 type KeepErrorTestClient struct{}
382 func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
383 return "", 0, errors.New("KeepError")
386 func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
387 return nil, errors.New("KeepError")
390 type KeepReadErrorTestClient struct{}
392 func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
396 type ErrorReader struct{}
398 func (ErrorReader) Read(p []byte) (n int, err error) {
399 return 0, errors.New("ErrorReader")
402 func (ErrorReader) Close() error {
406 func (ErrorReader) Len() uint64 {
410 func (ErrorReader) Seek(int64, int) (int64, error) {
411 return 0, errors.New("ErrorReader")
414 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
415 return ErrorReader{}, nil
418 func (s *TestSuite) TestLoadImageArvError(c *C) {
420 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
421 cr.Container.ContainerImage = hwPDH
423 err := cr.LoadImage()
424 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
427 func (s *TestSuite) TestLoadImageKeepError(c *C) {
429 docker := NewTestDockerClient(0)
430 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
431 cr.Container.ContainerImage = hwPDH
433 err := cr.LoadImage()
434 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
437 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
438 // (3) Collection doesn't contain image
439 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
440 cr.Container.ContainerImage = otherPDH
442 err := cr.LoadImage()
443 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
446 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
447 // (4) Collection doesn't contain image
448 docker := NewTestDockerClient(0)
449 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
450 cr.Container.ContainerImage = hwPDH
452 err := cr.LoadImage()
456 type ClosableBuffer struct {
460 func (*ClosableBuffer) Close() error {
464 type TestLogs struct {
465 Stdout ClosableBuffer
466 Stderr ClosableBuffer
469 func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
470 if logstr == "stdout" {
473 if logstr == "stderr" {
479 func dockerLog(fd byte, msg string) []byte {
481 header := make([]byte, 8+len(by))
483 header[7] = byte(len(by))
488 func (s *TestSuite) TestRunContainer(c *C) {
489 docker := NewTestDockerClient(0)
490 docker.fn = func(t *TestDockerClient) {
491 t.logWriter.Write(dockerLog(1, "Hello world\n"))
494 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
497 cr.NewLogWriter = logs.NewTestLoggingWriter
498 cr.Container.ContainerImage = hwPDH
499 cr.Container.Command = []string{"./hw"}
500 err := cr.LoadImage()
503 err = cr.CreateContainer()
506 err = cr.StartContainer()
509 err = cr.WaitFinish()
512 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
513 c.Check(logs.Stderr.String(), Equals, "")
516 func (s *TestSuite) TestCommitLogs(c *C) {
517 api := &ArvTestClient{}
518 kc := &KeepTestClient{}
519 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
520 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
522 cr.CrunchLog.Print("Hello world!")
523 cr.CrunchLog.Print("Goodbye")
524 cr.finalState = "Complete"
526 err := cr.CommitLogs()
529 c.Check(api.Calls, Equals, 2)
530 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
531 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
532 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
533 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
536 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
537 api := &ArvTestClient{}
538 kc := &KeepTestClient{}
539 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
541 err := cr.UpdateContainerRunning()
544 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
547 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
548 api := &ArvTestClient{}
549 kc := &KeepTestClient{}
550 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
552 cr.LogsPDH = new(string)
553 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
555 cr.ExitCode = new(int)
557 cr.finalState = "Complete"
559 err := cr.UpdateContainerFinal()
562 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
563 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
564 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
567 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
568 api := &ArvTestClient{}
569 kc := &KeepTestClient{}
570 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
572 cr.finalState = "Cancelled"
574 err := cr.UpdateContainerFinal()
577 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
578 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
579 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
582 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
583 // dress rehearsal of the Run() function, starting from a JSON container record.
584 func FullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, realTemp string) {
585 rec := arvados.Container{}
586 err := json.Unmarshal([]byte(record), &rec)
589 docker := NewTestDockerClient(exitCode)
591 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
593 api = &ArvTestClient{Container: rec}
595 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
596 cr.statInterval = 100 * time.Millisecond
597 am := &ArvMountCmdLine{}
598 cr.RunArvMount = am.ArvMountTest
600 realTemp, err = ioutil.TempDir("", "crunchrun_test1-")
602 defer os.RemoveAll(realTemp)
605 cr.MkTempDir = func(_ string, prefix string) (string, error) {
607 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
608 err := os.Mkdir(d, os.ModePerm)
609 if err != nil && strings.Contains(err.Error(), ": file exists") {
610 // Test case must have pre-populated the tempdir
616 if extraMounts != nil && len(extraMounts) > 0 {
617 err := cr.SetupArvMountPoint("keep")
620 for _, m := range extraMounts {
621 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
627 c.Check(api.WasSetRunning, Equals, true)
629 c.Check(api.Content[api.Calls-1]["container"].(arvadosclient.Dict)["log"], NotNil)
632 for k, v := range api.Logs {
641 func (s *TestSuite) TestFullRunHello(c *C) {
642 api, _, _ := FullRunHelper(c, `{
643 "command": ["echo", "hello world"],
644 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
647 "mounts": {"/tmp": {"kind": "tmp"} },
648 "output_path": "/tmp",
650 "runtime_constraints": {}
651 }`, nil, 0, func(t *TestDockerClient) {
652 t.logWriter.Write(dockerLog(1, "hello world\n"))
656 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
657 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
658 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
662 func (s *TestSuite) TestCrunchstat(c *C) {
663 api, _, _ := FullRunHelper(c, `{
664 "command": ["sleep", "1"],
665 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
668 "mounts": {"/tmp": {"kind": "tmp"} },
669 "output_path": "/tmp",
671 "runtime_constraints": {}
672 }`, nil, 0, func(t *TestDockerClient) {
673 time.Sleep(time.Second)
677 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
678 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
680 // We didn't actually start a container, so crunchstat didn't
681 // find accounting files and therefore didn't log any stats.
682 // It should have logged a "can't find accounting files"
683 // message after one poll interval, though, so we can confirm
685 c.Assert(api.Logs["crunchstat"], NotNil)
686 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
688 // The "files never appeared" log assures us that we called
689 // (*crunchstat.Reporter)Stop(), and that we set it up with
690 // the correct container ID "abcde":
691 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
694 func (s *TestSuite) TestNodeInfoLog(c *C) {
695 api, _, _ := FullRunHelper(c, `{
696 "command": ["sleep", "1"],
697 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
700 "mounts": {"/tmp": {"kind": "tmp"} },
701 "output_path": "/tmp",
703 "runtime_constraints": {}
705 func(t *TestDockerClient) {
706 time.Sleep(time.Second)
710 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
711 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
713 c.Assert(api.Logs["node-info"], NotNil)
714 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Host Information.*`)
715 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*CPU Information.*`)
716 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Memory Information.*`)
717 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk Space.*`)
718 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk INodes.*`)
721 func (s *TestSuite) TestContainerRecordLog(c *C) {
722 api, _, _ := FullRunHelper(c, `{
723 "command": ["sleep", "1"],
724 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
727 "mounts": {"/tmp": {"kind": "tmp"} },
728 "output_path": "/tmp",
730 "runtime_constraints": {}
732 func(t *TestDockerClient) {
733 time.Sleep(time.Second)
737 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
738 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
740 c.Assert(api.Logs["container"], NotNil)
741 c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
744 func (s *TestSuite) TestFullRunStderr(c *C) {
745 api, _, _ := FullRunHelper(c, `{
746 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
747 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
750 "mounts": {"/tmp": {"kind": "tmp"} },
751 "output_path": "/tmp",
753 "runtime_constraints": {}
754 }`, nil, 1, func(t *TestDockerClient) {
755 t.logWriter.Write(dockerLog(1, "hello\n"))
756 t.logWriter.Write(dockerLog(2, "world\n"))
760 final := api.CalledWith("container.state", "Complete")
761 c.Assert(final, NotNil)
762 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
763 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
765 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
766 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
769 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
770 api, _, _ := FullRunHelper(c, `{
772 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
775 "mounts": {"/tmp": {"kind": "tmp"} },
776 "output_path": "/tmp",
778 "runtime_constraints": {}
779 }`, nil, 0, func(t *TestDockerClient) {
780 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
784 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
785 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
786 c.Log(api.Logs["stdout"])
787 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
790 func (s *TestSuite) TestFullRunSetCwd(c *C) {
791 api, _, _ := FullRunHelper(c, `{
793 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
796 "mounts": {"/tmp": {"kind": "tmp"} },
797 "output_path": "/tmp",
799 "runtime_constraints": {}
800 }`, nil, 0, func(t *TestDockerClient) {
801 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
805 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
806 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
807 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
810 func (s *TestSuite) TestStopOnSignal(c *C) {
811 s.testStopContainer(c, func(cr *ContainerRunner) {
814 time.Sleep(time.Millisecond)
816 cr.SigChan <- syscall.SIGINT
821 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
822 s.testStopContainer(c, func(cr *ContainerRunner) {
823 cr.ArvMountExit = make(chan error)
825 cr.ArvMountExit <- exec.Command("true").Run()
826 close(cr.ArvMountExit)
831 func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
833 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
834 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
837 "mounts": {"/tmp": {"kind": "tmp"} },
838 "output_path": "/tmp",
840 "runtime_constraints": {}
843 rec := arvados.Container{}
844 err := json.Unmarshal([]byte(record), &rec)
847 docker := NewTestDockerClient(0)
848 docker.fn = func(t *TestDockerClient) {
850 t.logWriter.Write(dockerLog(1, "foo\n"))
853 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
855 api := &ArvTestClient{Container: rec}
856 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
857 cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
860 done := make(chan error)
865 case <-time.After(20 * time.Second):
866 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
871 for k, v := range api.Logs {
876 c.Check(api.CalledWith("container.log", nil), NotNil)
877 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
878 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
881 func (s *TestSuite) TestFullRunSetEnv(c *C) {
882 api, _, _ := FullRunHelper(c, `{
883 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
884 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
886 "environment": {"FROBIZ": "bilbo"},
887 "mounts": {"/tmp": {"kind": "tmp"} },
888 "output_path": "/tmp",
890 "runtime_constraints": {}
891 }`, nil, 0, func(t *TestDockerClient) {
892 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
896 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
897 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
898 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
901 type ArvMountCmdLine struct {
906 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
912 func stubCert(temp string) string {
913 path := temp + "/ca-certificates.crt"
914 crt, _ := os.Create(path)
916 arvadosclient.CertFiles = []string{path}
920 func (s *TestSuite) TestSetupMounts(c *C) {
921 api := &ArvTestClient{}
922 kc := &KeepTestClient{}
923 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
924 am := &ArvMountCmdLine{}
925 cr.RunArvMount = am.ArvMountTest
927 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
929 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
931 stubCertPath := stubCert(certTemp)
933 defer os.RemoveAll(realTemp)
934 defer os.RemoveAll(certTemp)
937 cr.MkTempDir = func(_ string, prefix string) (string, error) {
939 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
940 err := os.Mkdir(d, os.ModePerm)
941 if err != nil && strings.Contains(err.Error(), ": file exists") {
942 // Test case must have pre-populated the tempdir
948 checkEmpty := func() {
949 filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
950 c.Check(path, Equals, realTemp)
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"
963 err := cr.SetupMounts()
965 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
966 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
973 cr.ArvMountPoint = ""
974 cr.Container.Mounts = make(map[string]arvados.Mount)
975 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
976 cr.OutputPath = "/tmp"
979 cr.Container.RuntimeConstraints.API = &apiflag
981 err := cr.SetupMounts()
983 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
984 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
993 cr.ArvMountPoint = ""
994 cr.Container.Mounts = map[string]arvados.Mount{
995 "/keeptmp": {Kind: "collection", Writable: true},
997 cr.OutputPath = "/keeptmp"
999 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1001 err := cr.SetupMounts()
1003 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1004 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
1011 cr.ArvMountPoint = ""
1012 cr.Container.Mounts = map[string]arvados.Mount{
1013 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1014 "/keepout": {Kind: "collection", Writable: true},
1016 cr.OutputPath = "/keepout"
1018 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1019 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1021 err := cr.SetupMounts()
1023 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1024 sort.StringSlice(cr.Binds).Sort()
1025 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1026 realTemp + "/keep1/tmp0:/keepout"})
1033 cr.ArvMountPoint = ""
1034 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1035 cr.Container.Mounts = map[string]arvados.Mount{
1036 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1037 "/keepout": {Kind: "collection", Writable: true},
1039 cr.OutputPath = "/keepout"
1041 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1042 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1044 err := cr.SetupMounts()
1046 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1047 sort.StringSlice(cr.Binds).Sort()
1048 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1049 realTemp + "/keep1/tmp0:/keepout"})
1054 for _, test := range []struct {
1058 {in: "foo", out: `"foo"`},
1059 {in: nil, out: `null`},
1060 {in: map[string]int{"foo": 123}, out: `{"foo":123}`},
1063 cr.ArvMountPoint = ""
1064 cr.Container.Mounts = map[string]arvados.Mount{
1065 "/mnt/test.json": {Kind: "json", Content: test.in},
1067 err := cr.SetupMounts()
1069 sort.StringSlice(cr.Binds).Sort()
1070 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
1071 content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
1073 c.Check(content, DeepEquals, []byte(test.out))
1078 // Read-only mount points are allowed underneath output_dir mount point
1081 cr.ArvMountPoint = ""
1082 cr.Container.Mounts = make(map[string]arvados.Mount)
1083 cr.Container.Mounts = map[string]arvados.Mount{
1084 "/tmp": {Kind: "tmp"},
1085 "/tmp/foo": {Kind: "collection"},
1087 cr.OutputPath = "/tmp"
1089 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1091 err := cr.SetupMounts()
1093 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1094 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
1099 // Writable mount points are not allowed underneath output_dir mount point
1102 cr.ArvMountPoint = ""
1103 cr.Container.Mounts = make(map[string]arvados.Mount)
1104 cr.Container.Mounts = map[string]arvados.Mount{
1105 "/tmp": {Kind: "tmp"},
1106 "/tmp/foo": {Kind: "collection", Writable: true},
1108 cr.OutputPath = "/tmp"
1110 err := cr.SetupMounts()
1111 c.Check(err, NotNil)
1112 c.Check(err, ErrorMatches, `Writable mount points are not permitted underneath the output_path.*`)
1117 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1120 cr.ArvMountPoint = ""
1121 cr.Container.Mounts = make(map[string]arvados.Mount)
1122 cr.Container.Mounts = map[string]arvados.Mount{
1123 "/tmp": {Kind: "tmp"},
1124 "/tmp/foo": {Kind: "json"},
1126 cr.OutputPath = "/tmp"
1128 err := cr.SetupMounts()
1129 c.Check(err, NotNil)
1130 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1135 // Only mount point of kind 'collection' is allowed for stdin
1138 cr.ArvMountPoint = ""
1139 cr.Container.Mounts = make(map[string]arvados.Mount)
1140 cr.Container.Mounts = map[string]arvados.Mount{
1141 "stdin": {Kind: "tmp"},
1144 err := cr.SetupMounts()
1145 c.Check(err, NotNil)
1146 c.Check(err, ErrorMatches, `Unsupported mount kind 'tmp' for stdin.*`)
1152 func (s *TestSuite) TestStdout(c *C) {
1154 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1155 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1157 "environment": {"FROBIZ": "bilbo"},
1158 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1159 "output_path": "/tmp",
1161 "runtime_constraints": {}
1164 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1165 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1169 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1170 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1171 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1174 // Used by the TestStdoutWithWrongPath*()
1175 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1176 rec := arvados.Container{}
1177 err = json.Unmarshal([]byte(record), &rec)
1180 docker := NewTestDockerClient(0)
1182 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1184 api = &ArvTestClient{Container: rec}
1185 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1186 am := &ArvMountCmdLine{}
1187 cr.RunArvMount = am.ArvMountTest
1193 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1194 _, _, err := StdoutErrorRunHelper(c, `{
1195 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1196 "output_path": "/tmp"
1197 }`, func(t *TestDockerClient) {})
1199 c.Check(err, NotNil)
1200 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1203 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1204 _, _, err := StdoutErrorRunHelper(c, `{
1205 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1206 "output_path": "/tmp"
1207 }`, func(t *TestDockerClient) {})
1209 c.Check(err, NotNil)
1210 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1213 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1214 _, _, err := StdoutErrorRunHelper(c, `{
1215 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1216 "output_path": "/tmp"
1217 }`, func(t *TestDockerClient) {})
1219 c.Check(err, NotNil)
1220 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1223 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1224 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1225 defer os.Unsetenv("ARVADOS_API_HOST")
1226 api, _, _ := FullRunHelper(c, `{
1227 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1228 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1231 "mounts": {"/tmp": {"kind": "tmp"} },
1232 "output_path": "/tmp",
1234 "runtime_constraints": {"API": true}
1235 }`, nil, 0, func(t *TestDockerClient) {
1236 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1240 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1241 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1242 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1243 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1246 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1247 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1248 defer os.Unsetenv("ARVADOS_API_HOST")
1249 api, _, _ := FullRunHelper(c, `{
1250 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1251 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1254 "mounts": {"/tmp": {"kind": "tmp"} },
1255 "output_path": "/tmp",
1257 "runtime_constraints": {"API": true}
1258 }`, nil, 0, func(t *TestDockerClient) {
1259 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1263 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1264 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1265 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1268 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1270 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1271 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1273 "environment": {"FROBIZ": "bilbo"},
1275 "/tmp": {"kind": "tmp"},
1276 "/tmp/foo": {"kind": "collection",
1277 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1278 "exclude_from_output": true
1280 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1282 "output_path": "/tmp",
1284 "runtime_constraints": {}
1287 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1289 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1290 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1294 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1295 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1296 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1299 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1301 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1302 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1304 "environment": {"FROBIZ": "bilbo"},
1306 "/tmp": {"kind": "tmp"},
1307 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1308 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1309 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1310 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1311 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1313 "output_path": "/tmp",
1315 "runtime_constraints": {}
1318 extraMounts := []string{
1319 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1320 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1321 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1324 api, runner, realtemp := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1325 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1329 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/2:/tmp",
1330 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1331 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1332 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1333 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1336 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1337 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1338 for _, v := range api.Content {
1339 if v["collection"] != nil {
1340 c.Check(v["ensure_unique_name"], Equals, true)
1341 collection := v["collection"].(arvadosclient.Dict)
1342 if strings.Index(collection["name"].(string), "output") == 0 {
1343 manifest := collection["manifest_text"].(string)
1345 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1346 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar 9:18:sub1file2
1347 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1348 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1349 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1356 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1358 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1359 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1361 "environment": {"FROBIZ": "bilbo"},
1363 "/tmp": {"kind": "tmp"},
1364 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1365 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1367 "output_path": "/tmp",
1369 "runtime_constraints": {}
1372 extraMounts := []string{
1373 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1376 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1377 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1381 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1382 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1383 for _, v := range api.Content {
1384 if v["collection"] != nil {
1385 collection := v["collection"].(arvadosclient.Dict)
1386 if strings.Index(collection["name"].(string), "output") == 0 {
1387 manifest := collection["manifest_text"].(string)
1389 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1390 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1397 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1399 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1400 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1402 "environment": {"FROBIZ": "bilbo"},
1404 "/tmp": {"kind": "tmp"},
1405 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1406 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1408 "output_path": "/tmp",
1410 "runtime_constraints": {}
1413 extraMounts := []string{
1414 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1417 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1418 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1422 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1423 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1424 for _, v := range api.Content {
1425 if v["collection"] != nil {
1426 collection := v["collection"].(arvadosclient.Dict)
1427 if strings.Index(collection["name"].(string), "output") == 0 {
1428 manifest := collection["manifest_text"].(string)
1429 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1436 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1438 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1439 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1441 "environment": {"FROBIZ": "bilbo"},
1443 "/tmp": {"kind": "tmp"},
1444 "stdin": {"kind": "json", "content": "foo"},
1445 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1447 "output_path": "/tmp",
1449 "runtime_constraints": {}
1452 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1453 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1457 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1458 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1459 for _, v := range api.Content {
1460 if v["collection"] != nil {
1461 collection := v["collection"].(arvadosclient.Dict)
1462 if strings.Index(collection["name"].(string), "output") == 0 {
1463 manifest := collection["manifest_text"].(string)
1464 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1471 func (s *TestSuite) TestStderrMount(c *C) {
1472 api, _, _ := FullRunHelper(c, `{
1473 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
1474 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1477 "mounts": {"/tmp": {"kind": "tmp"},
1478 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
1479 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
1480 "output_path": "/tmp",
1482 "runtime_constraints": {}
1483 }`, nil, 1, func(t *TestDockerClient) {
1484 t.logWriter.Write(dockerLog(1, "hello\n"))
1485 t.logWriter.Write(dockerLog(2, "oops\n"))
1489 final := api.CalledWith("container.state", "Complete")
1490 c.Assert(final, NotNil)
1491 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1492 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1494 c.Check(api.CalledWith("collection.manifest_text", "./a b1946ac92492d2347c6235b4d2611184+6 0:6:out.txt\n./b 38af5c54926b620264ab1501150cf189+5 0:5:err.txt\n"), NotNil)