1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
29 "git.curoverse.com/arvados.git/sdk/go/arvados"
30 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
31 "git.curoverse.com/arvados.git/sdk/go/manifest"
33 dockertypes "github.com/docker/docker/api/types"
34 dockercontainer "github.com/docker/docker/api/types/container"
35 dockernetwork "github.com/docker/docker/api/types/network"
39 // Gocheck boilerplate
40 func TestCrunchExec(t *testing.T) {
44 type TestSuite struct{}
46 // Gocheck boilerplate
47 var _ = Suite(&TestSuite{})
49 type ArvTestClient struct {
52 Content []arvadosclient.Dict
54 Logs map[string]*bytes.Buffer
59 type KeepTestClient struct {
64 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
65 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
66 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
68 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
69 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
71 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
72 ./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
73 ./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
76 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
78 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"
79 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
81 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
82 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
84 type TestDockerClient struct {
86 logReader io.ReadCloser
87 logWriter io.WriteCloser
88 fn func(t *TestDockerClient)
97 func NewTestDockerClient(exitCode int) *TestDockerClient {
98 t := &TestDockerClient{}
99 t.logReader, t.logWriter = io.Pipe()
101 t.stop = make(chan bool)
106 type MockConn struct {
110 func (m *MockConn) Write(b []byte) (int, error) {
114 func NewMockConn() *MockConn {
119 func (t *TestDockerClient) ContainerAttach(ctx context.Context, container string, options dockertypes.ContainerAttachOptions) (dockertypes.HijackedResponse, error) {
120 return dockertypes.HijackedResponse{Conn: NewMockConn(), Reader: bufio.NewReader(t.logReader)}, nil
123 func (t *TestDockerClient) ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error) {
124 if config.WorkingDir != "" {
125 t.cwd = config.WorkingDir
128 return dockercontainer.ContainerCreateCreatedBody{ID: "abcde"}, nil
131 func (t *TestDockerClient) ContainerStart(ctx context.Context, container string, options dockertypes.ContainerStartOptions) error {
132 if container == "abcde" {
136 return errors.New("Invalid container id")
140 func (t *TestDockerClient) ContainerStop(ctx context.Context, container string, timeout *time.Duration) error {
145 func (t *TestDockerClient) ContainerWait(ctx context.Context, container string, condition dockercontainer.WaitCondition) (<-chan dockercontainer.ContainerWaitOKBody, <-chan error) {
146 body := make(chan dockercontainer.ContainerWaitOKBody)
147 err := make(chan error)
149 body <- dockercontainer.ContainerWaitOKBody{StatusCode: int64(t.finish)}
156 func (t *TestDockerClient) ImageInspectWithRaw(ctx context.Context, image string) (dockertypes.ImageInspect, []byte, error) {
157 if t.imageLoaded == image {
158 return dockertypes.ImageInspect{}, nil, nil
160 return dockertypes.ImageInspect{}, nil, errors.New("")
164 func (t *TestDockerClient) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (dockertypes.ImageLoadResponse, error) {
165 _, err := io.Copy(ioutil.Discard, input)
167 return dockertypes.ImageLoadResponse{}, err
169 t.imageLoaded = hwImageId
170 return dockertypes.ImageLoadResponse{Body: ioutil.NopCloser(input)}, nil
174 func (*TestDockerClient) ImageRemove(ctx context.Context, image string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {
178 func (client *ArvTestClient) Create(resourceType string,
179 parameters arvadosclient.Dict,
180 output interface{}) error {
183 defer client.Mutex.Unlock()
186 client.Content = append(client.Content, parameters)
188 if resourceType == "logs" {
189 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
190 if client.Logs == nil {
191 client.Logs = make(map[string]*bytes.Buffer)
193 if client.Logs[et] == nil {
194 client.Logs[et] = &bytes.Buffer{}
196 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
199 if resourceType == "collections" && output != nil {
200 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
201 outmap := output.(*arvados.Collection)
202 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
208 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
210 case method == "GET" && resourceType == "containers" && action == "auth":
211 return json.Unmarshal([]byte(`{
212 "kind": "arvados#api_client_authorization",
213 "uuid": "`+fakeAuthUUID+`",
214 "api_token": "`+fakeAuthToken+`"
217 return fmt.Errorf("Not found")
221 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
222 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
224 "command": ["sleep", "1"],
225 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
228 "mounts": {"/tmp": {"kind": "tmp"} },
229 "output_path": "/tmp",
231 "runtime_constraints": {}
233 return ioutil.NopCloser(bytes.NewReader(j)), nil
236 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
237 if resourceType == "collections" {
239 output.(*arvados.Collection).ManifestText = hwManifest
240 } else if uuid == otherPDH {
241 output.(*arvados.Collection).ManifestText = otherManifest
242 } else if uuid == normalizedWithSubdirsPDH {
243 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
244 } else if uuid == denormalizedWithSubdirsPDH {
245 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
248 if resourceType == "containers" {
249 (*output.(*arvados.Container)) = client.Container
254 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
256 defer client.Mutex.Unlock()
258 client.Content = append(client.Content, parameters)
259 if resourceType == "containers" {
260 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
261 client.WasSetRunning = true
267 var discoveryMap = map[string]interface{}{
268 "defaultTrashLifetime": float64(1209600),
269 "crunchLimitLogBytesPerJob": float64(67108864),
270 "crunchLogThrottleBytes": float64(65536),
271 "crunchLogThrottlePeriod": float64(60),
272 "crunchLogThrottleLines": float64(1024),
273 "crunchLogPartialLineThrottlePeriod": float64(5),
274 "crunchLogBytesPerEvent": float64(4096),
275 "crunchLogSecondsBetweenEvents": float64(1),
278 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
279 return discoveryMap[key], nil
282 // CalledWith returns the parameters from the first API call whose
283 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
284 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
285 // no call matches, it returns nil.
286 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
288 for _, content := range client.Content {
289 var v interface{} = content
290 for _, k := range strings.Split(jpath, ".") {
291 if dict, ok := v.(arvadosclient.Dict); !ok {
304 func (client *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
306 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
309 type FileWrapper struct {
314 func (fw FileWrapper) Size() int64 {
318 func (fw FileWrapper) Seek(int64, int) (int64, error) {
319 return 0, errors.New("not implemented")
322 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
323 if filename == hwImageId+".tar" {
324 rdr := ioutil.NopCloser(&bytes.Buffer{})
326 return FileWrapper{rdr, 1321984}, nil
327 } else if filename == "/file1_in_main.txt" {
328 rdr := ioutil.NopCloser(strings.NewReader("foo"))
330 return FileWrapper{rdr, 3}, nil
335 func (s *TestSuite) TestLoadImage(c *C) {
336 kc := &KeepTestClient{}
337 docker := NewTestDockerClient(0)
338 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
340 _, err := cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
342 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
345 cr.Container.ContainerImage = hwPDH
347 // (1) Test loading image from keep
348 c.Check(kc.Called, Equals, false)
349 c.Check(cr.ContainerConfig.Image, Equals, "")
355 cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
358 c.Check(kc.Called, Equals, true)
359 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
361 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
364 // (2) Test using image that's already loaded
366 cr.ContainerConfig.Image = ""
370 c.Check(kc.Called, Equals, false)
371 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
375 type ArvErrorTestClient struct{}
377 func (ArvErrorTestClient) Create(resourceType string,
378 parameters arvadosclient.Dict,
379 output interface{}) error {
383 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
384 return errors.New("ArvError")
387 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
388 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
389 return nil, errors.New("ArvError")
392 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
393 return errors.New("ArvError")
396 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
400 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
401 return discoveryMap[key], nil
404 type KeepErrorTestClient struct{}
406 func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
407 return "", 0, errors.New("KeepError")
410 func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
411 return nil, errors.New("KeepError")
414 type KeepReadErrorTestClient struct{}
416 func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
420 type ErrorReader struct{}
422 func (ErrorReader) Read(p []byte) (n int, err error) {
423 return 0, errors.New("ErrorReader")
426 func (ErrorReader) Close() error {
430 func (ErrorReader) Size() int64 {
434 func (ErrorReader) Seek(int64, int) (int64, error) {
435 return 0, errors.New("ErrorReader")
438 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
439 return ErrorReader{}, nil
442 func (s *TestSuite) TestLoadImageArvError(c *C) {
444 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
445 cr.Container.ContainerImage = hwPDH
447 err := cr.LoadImage()
448 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
451 func (s *TestSuite) TestLoadImageKeepError(c *C) {
453 docker := NewTestDockerClient(0)
454 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
455 cr.Container.ContainerImage = hwPDH
457 err := cr.LoadImage()
458 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
461 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
462 // (3) Collection doesn't contain image
463 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
464 cr.Container.ContainerImage = otherPDH
466 err := cr.LoadImage()
467 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
470 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
471 // (4) Collection doesn't contain image
472 docker := NewTestDockerClient(0)
473 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
474 cr.Container.ContainerImage = hwPDH
476 err := cr.LoadImage()
480 type ClosableBuffer struct {
484 func (*ClosableBuffer) Close() error {
488 type TestLogs struct {
489 Stdout ClosableBuffer
490 Stderr ClosableBuffer
493 func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
494 if logstr == "stdout" {
497 if logstr == "stderr" {
503 func dockerLog(fd byte, msg string) []byte {
505 header := make([]byte, 8+len(by))
507 header[7] = byte(len(by))
512 func (s *TestSuite) TestRunContainer(c *C) {
513 docker := NewTestDockerClient(0)
514 docker.fn = func(t *TestDockerClient) {
515 t.logWriter.Write(dockerLog(1, "Hello world\n"))
518 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
521 cr.NewLogWriter = logs.NewTestLoggingWriter
522 cr.Container.ContainerImage = hwPDH
523 cr.Container.Command = []string{"./hw"}
524 err := cr.LoadImage()
527 err = cr.CreateContainer()
530 err = cr.StartContainer()
533 err = cr.WaitFinish()
536 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
537 c.Check(logs.Stderr.String(), Equals, "")
540 func (s *TestSuite) TestCommitLogs(c *C) {
541 api := &ArvTestClient{}
542 kc := &KeepTestClient{}
543 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
544 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
546 cr.CrunchLog.Print("Hello world!")
547 cr.CrunchLog.Print("Goodbye")
548 cr.finalState = "Complete"
550 err := cr.CommitLogs()
553 c.Check(api.Calls, Equals, 2)
554 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
555 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
556 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
557 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
560 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
561 api := &ArvTestClient{}
562 kc := &KeepTestClient{}
563 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
565 err := cr.UpdateContainerRunning()
568 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
571 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
572 api := &ArvTestClient{}
573 kc := &KeepTestClient{}
574 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
576 cr.LogsPDH = new(string)
577 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
579 cr.ExitCode = new(int)
581 cr.finalState = "Complete"
583 err := cr.UpdateContainerFinal()
586 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
587 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
588 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
591 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
592 api := &ArvTestClient{}
593 kc := &KeepTestClient{}
594 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
596 cr.finalState = "Cancelled"
598 err := cr.UpdateContainerFinal()
601 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
602 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
603 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
606 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
607 // dress rehearsal of the Run() function, starting from a JSON container record.
608 func FullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, realTemp string) {
609 rec := arvados.Container{}
610 err := json.Unmarshal([]byte(record), &rec)
613 docker := NewTestDockerClient(exitCode)
615 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
617 api = &ArvTestClient{Container: rec}
619 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
620 cr.statInterval = 100 * time.Millisecond
621 am := &ArvMountCmdLine{}
622 cr.RunArvMount = am.ArvMountTest
624 realTemp, err = ioutil.TempDir("", "crunchrun_test1-")
626 defer os.RemoveAll(realTemp)
628 docker.realTemp = realTemp
631 cr.MkTempDir = func(_ string, prefix string) (string, error) {
633 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
634 err := os.Mkdir(d, os.ModePerm)
635 if err != nil && strings.Contains(err.Error(), ": file exists") {
636 // Test case must have pre-populated the tempdir
642 if extraMounts != nil && len(extraMounts) > 0 {
643 err := cr.SetupArvMountPoint("keep")
646 for _, m := range extraMounts {
647 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
652 if api.CalledWith("container.state", "Complete") != nil {
655 c.Check(api.WasSetRunning, Equals, true)
657 c.Check(api.Content[api.Calls-1]["container"].(arvadosclient.Dict)["log"], NotNil)
660 for k, v := range api.Logs {
669 func (s *TestSuite) TestFullRunHello(c *C) {
670 api, _, _ := FullRunHelper(c, `{
671 "command": ["echo", "hello world"],
672 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
675 "mounts": {"/tmp": {"kind": "tmp"} },
676 "output_path": "/tmp",
678 "runtime_constraints": {}
679 }`, nil, 0, func(t *TestDockerClient) {
680 t.logWriter.Write(dockerLog(1, "hello world\n"))
684 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
685 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
686 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
690 func (s *TestSuite) TestCrunchstat(c *C) {
691 api, _, _ := FullRunHelper(c, `{
692 "command": ["sleep", "1"],
693 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
696 "mounts": {"/tmp": {"kind": "tmp"} },
697 "output_path": "/tmp",
699 "runtime_constraints": {}
700 }`, nil, 0, func(t *TestDockerClient) {
701 time.Sleep(time.Second)
705 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
706 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
708 // We didn't actually start a container, so crunchstat didn't
709 // find accounting files and therefore didn't log any stats.
710 // It should have logged a "can't find accounting files"
711 // message after one poll interval, though, so we can confirm
713 c.Assert(api.Logs["crunchstat"], NotNil)
714 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
716 // The "files never appeared" log assures us that we called
717 // (*crunchstat.Reporter)Stop(), and that we set it up with
718 // the correct container ID "abcde":
719 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
722 func (s *TestSuite) TestNodeInfoLog(c *C) {
723 api, _, _ := FullRunHelper(c, `{
724 "command": ["sleep", "1"],
725 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
728 "mounts": {"/tmp": {"kind": "tmp"} },
729 "output_path": "/tmp",
731 "runtime_constraints": {}
733 func(t *TestDockerClient) {
734 time.Sleep(time.Second)
738 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
739 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
741 c.Assert(api.Logs["node-info"], NotNil)
742 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Host Information.*`)
743 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*CPU Information.*`)
744 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Memory Information.*`)
745 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk Space.*`)
746 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk INodes.*`)
749 func (s *TestSuite) TestContainerRecordLog(c *C) {
750 api, _, _ := FullRunHelper(c, `{
751 "command": ["sleep", "1"],
752 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
755 "mounts": {"/tmp": {"kind": "tmp"} },
756 "output_path": "/tmp",
758 "runtime_constraints": {}
760 func(t *TestDockerClient) {
761 time.Sleep(time.Second)
765 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
766 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
768 c.Assert(api.Logs["container"], NotNil)
769 c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
772 func (s *TestSuite) TestFullRunStderr(c *C) {
773 api, _, _ := FullRunHelper(c, `{
774 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
775 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
778 "mounts": {"/tmp": {"kind": "tmp"} },
779 "output_path": "/tmp",
781 "runtime_constraints": {}
782 }`, nil, 1, func(t *TestDockerClient) {
783 t.logWriter.Write(dockerLog(1, "hello\n"))
784 t.logWriter.Write(dockerLog(2, "world\n"))
788 final := api.CalledWith("container.state", "Complete")
789 c.Assert(final, NotNil)
790 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
791 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
793 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
794 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
797 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
798 api, _, _ := FullRunHelper(c, `{
800 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
803 "mounts": {"/tmp": {"kind": "tmp"} },
804 "output_path": "/tmp",
806 "runtime_constraints": {}
807 }`, nil, 0, func(t *TestDockerClient) {
808 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
812 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
813 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
814 c.Log(api.Logs["stdout"])
815 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
818 func (s *TestSuite) TestFullRunSetCwd(c *C) {
819 api, _, _ := FullRunHelper(c, `{
821 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
824 "mounts": {"/tmp": {"kind": "tmp"} },
825 "output_path": "/tmp",
827 "runtime_constraints": {}
828 }`, nil, 0, func(t *TestDockerClient) {
829 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
833 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
834 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
835 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
838 func (s *TestSuite) TestStopOnSignal(c *C) {
839 s.testStopContainer(c, func(cr *ContainerRunner) {
842 time.Sleep(time.Millisecond)
844 cr.SigChan <- syscall.SIGINT
849 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
850 s.testStopContainer(c, func(cr *ContainerRunner) {
851 cr.ArvMountExit = make(chan error)
853 cr.ArvMountExit <- exec.Command("true").Run()
854 close(cr.ArvMountExit)
859 func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
861 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
862 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
865 "mounts": {"/tmp": {"kind": "tmp"} },
866 "output_path": "/tmp",
868 "runtime_constraints": {}
871 rec := arvados.Container{}
872 err := json.Unmarshal([]byte(record), &rec)
875 docker := NewTestDockerClient(0)
876 docker.fn = func(t *TestDockerClient) {
878 t.logWriter.Write(dockerLog(1, "foo\n"))
881 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
883 api := &ArvTestClient{Container: rec}
884 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
885 cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
888 done := make(chan error)
893 case <-time.After(20 * time.Second):
894 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
899 for k, v := range api.Logs {
904 c.Check(api.CalledWith("container.log", nil), NotNil)
905 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
906 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
909 func (s *TestSuite) TestFullRunSetEnv(c *C) {
910 api, _, _ := FullRunHelper(c, `{
911 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
912 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
914 "environment": {"FROBIZ": "bilbo"},
915 "mounts": {"/tmp": {"kind": "tmp"} },
916 "output_path": "/tmp",
918 "runtime_constraints": {}
919 }`, nil, 0, func(t *TestDockerClient) {
920 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
924 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
925 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
926 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
929 type ArvMountCmdLine struct {
934 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
940 func stubCert(temp string) string {
941 path := temp + "/ca-certificates.crt"
942 crt, _ := os.Create(path)
944 arvadosclient.CertFiles = []string{path}
948 func (s *TestSuite) TestSetupMounts(c *C) {
949 api := &ArvTestClient{}
950 kc := &KeepTestClient{}
951 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
952 am := &ArvMountCmdLine{}
953 cr.RunArvMount = am.ArvMountTest
955 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
957 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
959 stubCertPath := stubCert(certTemp)
961 defer os.RemoveAll(realTemp)
962 defer os.RemoveAll(certTemp)
965 cr.MkTempDir = func(_ string, prefix string) (string, error) {
967 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
968 err := os.Mkdir(d, os.ModePerm)
969 if err != nil && strings.Contains(err.Error(), ": file exists") {
970 // Test case must have pre-populated the tempdir
976 checkEmpty := func() {
977 filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
978 c.Check(path, Equals, realTemp)
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"
991 err := cr.SetupMounts()
993 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
994 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
1001 cr.ArvMountPoint = ""
1002 cr.Container.Mounts = make(map[string]arvados.Mount)
1003 cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"}
1004 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1005 cr.OutputPath = "/out"
1007 err := cr.SetupMounts()
1009 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1010 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/out", realTemp + "/3:/tmp"})
1017 cr.ArvMountPoint = ""
1018 cr.Container.Mounts = make(map[string]arvados.Mount)
1019 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1020 cr.OutputPath = "/tmp"
1023 cr.Container.RuntimeConstraints.API = &apiflag
1025 err := cr.SetupMounts()
1027 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1028 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
1037 cr.ArvMountPoint = ""
1038 cr.Container.Mounts = map[string]arvados.Mount{
1039 "/keeptmp": {Kind: "collection", Writable: true},
1041 cr.OutputPath = "/keeptmp"
1043 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1045 err := cr.SetupMounts()
1047 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1048 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
1055 cr.ArvMountPoint = ""
1056 cr.Container.Mounts = map[string]arvados.Mount{
1057 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1058 "/keepout": {Kind: "collection", Writable: true},
1060 cr.OutputPath = "/keepout"
1062 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1063 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1065 err := cr.SetupMounts()
1067 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1068 sort.StringSlice(cr.Binds).Sort()
1069 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1070 realTemp + "/keep1/tmp0:/keepout"})
1077 cr.ArvMountPoint = ""
1078 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1079 cr.Container.Mounts = map[string]arvados.Mount{
1080 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1081 "/keepout": {Kind: "collection", Writable: true},
1083 cr.OutputPath = "/keepout"
1085 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1086 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1088 err := cr.SetupMounts()
1090 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1091 sort.StringSlice(cr.Binds).Sort()
1092 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1093 realTemp + "/keep1/tmp0:/keepout"})
1098 for _, test := range []struct {
1102 {in: "foo", out: `"foo"`},
1103 {in: nil, out: `null`},
1104 {in: map[string]int{"foo": 123}, out: `{"foo":123}`},
1107 cr.ArvMountPoint = ""
1108 cr.Container.Mounts = map[string]arvados.Mount{
1109 "/mnt/test.json": {Kind: "json", Content: test.in},
1111 err := cr.SetupMounts()
1113 sort.StringSlice(cr.Binds).Sort()
1114 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
1115 content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
1117 c.Check(content, DeepEquals, []byte(test.out))
1122 // Read-only mount points are allowed underneath output_dir mount point
1125 cr.ArvMountPoint = ""
1126 cr.Container.Mounts = make(map[string]arvados.Mount)
1127 cr.Container.Mounts = map[string]arvados.Mount{
1128 "/tmp": {Kind: "tmp"},
1129 "/tmp/foo": {Kind: "collection"},
1131 cr.OutputPath = "/tmp"
1133 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1135 err := cr.SetupMounts()
1137 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1138 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
1143 // Writable mount points are not allowed underneath output_dir mount point
1146 cr.ArvMountPoint = ""
1147 cr.Container.Mounts = make(map[string]arvados.Mount)
1148 cr.Container.Mounts = map[string]arvados.Mount{
1149 "/tmp": {Kind: "tmp"},
1150 "/tmp/foo": {Kind: "collection", Writable: true},
1152 cr.OutputPath = "/tmp"
1154 err := cr.SetupMounts()
1155 c.Check(err, NotNil)
1156 c.Check(err, ErrorMatches, `Writable mount points are not permitted underneath the output_path.*`)
1161 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1164 cr.ArvMountPoint = ""
1165 cr.Container.Mounts = make(map[string]arvados.Mount)
1166 cr.Container.Mounts = map[string]arvados.Mount{
1167 "/tmp": {Kind: "tmp"},
1168 "/tmp/foo": {Kind: "json"},
1170 cr.OutputPath = "/tmp"
1172 err := cr.SetupMounts()
1173 c.Check(err, NotNil)
1174 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1179 // Only mount point of kind 'collection' is allowed for stdin
1182 cr.ArvMountPoint = ""
1183 cr.Container.Mounts = make(map[string]arvados.Mount)
1184 cr.Container.Mounts = map[string]arvados.Mount{
1185 "stdin": {Kind: "tmp"},
1188 err := cr.SetupMounts()
1189 c.Check(err, NotNil)
1190 c.Check(err, ErrorMatches, `Unsupported mount kind 'tmp' for stdin.*`)
1196 func (s *TestSuite) TestStdout(c *C) {
1198 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1199 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1201 "environment": {"FROBIZ": "bilbo"},
1202 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1203 "output_path": "/tmp",
1205 "runtime_constraints": {}
1208 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1209 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1213 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1214 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1215 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1218 // Used by the TestStdoutWithWrongPath*()
1219 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1220 rec := arvados.Container{}
1221 err = json.Unmarshal([]byte(record), &rec)
1224 docker := NewTestDockerClient(0)
1226 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1228 api = &ArvTestClient{Container: rec}
1229 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1230 am := &ArvMountCmdLine{}
1231 cr.RunArvMount = am.ArvMountTest
1237 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1238 _, _, err := StdoutErrorRunHelper(c, `{
1239 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1240 "output_path": "/tmp"
1241 }`, func(t *TestDockerClient) {})
1243 c.Check(err, NotNil)
1244 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1247 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1248 _, _, err := StdoutErrorRunHelper(c, `{
1249 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1250 "output_path": "/tmp"
1251 }`, func(t *TestDockerClient) {})
1253 c.Check(err, NotNil)
1254 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1257 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1258 _, _, err := StdoutErrorRunHelper(c, `{
1259 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1260 "output_path": "/tmp"
1261 }`, func(t *TestDockerClient) {})
1263 c.Check(err, NotNil)
1264 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1267 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1268 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1269 defer os.Unsetenv("ARVADOS_API_HOST")
1270 api, _, _ := FullRunHelper(c, `{
1271 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1272 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1275 "mounts": {"/tmp": {"kind": "tmp"} },
1276 "output_path": "/tmp",
1278 "runtime_constraints": {"API": true}
1279 }`, nil, 0, func(t *TestDockerClient) {
1280 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1284 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1285 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1286 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1287 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1290 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1291 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1292 defer os.Unsetenv("ARVADOS_API_HOST")
1293 api, _, _ := FullRunHelper(c, `{
1294 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1295 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1298 "mounts": {"/tmp": {"kind": "tmp"} },
1299 "output_path": "/tmp",
1301 "runtime_constraints": {"API": true}
1302 }`, nil, 0, func(t *TestDockerClient) {
1303 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1307 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1308 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1309 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1312 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(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": {"kind": "collection",
1321 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1322 "exclude_from_output": true
1324 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1326 "output_path": "/tmp",
1328 "runtime_constraints": {}
1331 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1333 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1334 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1338 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1339 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1340 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1343 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1345 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1346 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1348 "environment": {"FROBIZ": "bilbo"},
1350 "/tmp": {"kind": "tmp"},
1351 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1352 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1353 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1354 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1355 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1357 "output_path": "/tmp",
1359 "runtime_constraints": {}
1362 extraMounts := []string{
1363 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1364 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1365 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1368 api, runner, realtemp := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1369 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1373 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/2:/tmp",
1374 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1375 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1376 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1377 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1380 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1381 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1382 for _, v := range api.Content {
1383 if v["collection"] != nil {
1384 c.Check(v["ensure_unique_name"], Equals, true)
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 9:18:bar 9:18:sub1file2
1391 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1392 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1393 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1400 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1402 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1403 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1405 "environment": {"FROBIZ": "bilbo"},
1407 "/tmp": {"kind": "tmp"},
1408 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1409 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1411 "output_path": "/tmp",
1413 "runtime_constraints": {}
1416 extraMounts := []string{
1417 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1420 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1421 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1425 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1426 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1427 for _, v := range api.Content {
1428 if v["collection"] != nil {
1429 collection := v["collection"].(arvadosclient.Dict)
1430 if strings.Index(collection["name"].(string), "output") == 0 {
1431 manifest := collection["manifest_text"].(string)
1433 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1434 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1441 func (s *TestSuite) TestOutputSymlinkToInput(c *C) {
1443 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1444 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1446 "environment": {"FROBIZ": "bilbo"},
1448 "/tmp": {"kind": "tmp"},
1449 "/keep/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path": "/subdir1/file2_in_subdir1.txt"},
1450 "/keep/foo2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367"}
1452 "output_path": "/tmp",
1454 "runtime_constraints": {}
1457 extraMounts := []string{
1458 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1461 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1462 os.Symlink("/keep/foo/sub1file2", t.realTemp+"/2/baz")
1463 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz2")
1464 os.Symlink("/keep/foo2/subdir1", t.realTemp+"/2/baz3")
1465 os.Mkdir(t.realTemp+"/2/baz4", 0700)
1466 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz4/baz5")
1470 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1471 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1472 for _, v := range api.Content {
1473 if v["collection"] != nil {
1474 collection := v["collection"].(arvadosclient.Dict)
1475 if strings.Index(collection["name"].(string), "output") == 0 {
1476 manifest := collection["manifest_text"].(string)
1477 c.Check(manifest, Equals, `. 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz 9:18:baz2
1478 ./baz3 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1479 ./baz3/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1480 ./baz4 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz5
1487 func (s *TestSuite) TestOutputError(c *C) {
1489 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1490 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1492 "environment": {"FROBIZ": "bilbo"},
1494 "/tmp": {"kind": "tmp"}
1496 "output_path": "/tmp",
1498 "runtime_constraints": {}
1501 extraMounts := []string{}
1503 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1504 os.Symlink("/etc/hosts", t.realTemp+"/2/baz")
1508 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1511 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1513 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1514 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1516 "environment": {"FROBIZ": "bilbo"},
1518 "/tmp": {"kind": "tmp"},
1519 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1520 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1522 "output_path": "/tmp",
1524 "runtime_constraints": {}
1527 extraMounts := []string{
1528 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1531 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1532 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1536 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1537 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1538 for _, v := range api.Content {
1539 if v["collection"] != nil {
1540 collection := v["collection"].(arvadosclient.Dict)
1541 if strings.Index(collection["name"].(string), "output") == 0 {
1542 manifest := collection["manifest_text"].(string)
1543 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1550 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1552 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1553 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1555 "environment": {"FROBIZ": "bilbo"},
1557 "/tmp": {"kind": "tmp"},
1558 "stdin": {"kind": "json", "content": "foo"},
1559 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1561 "output_path": "/tmp",
1563 "runtime_constraints": {}
1566 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1567 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1571 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1572 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1573 for _, v := range api.Content {
1574 if v["collection"] != nil {
1575 collection := v["collection"].(arvadosclient.Dict)
1576 if strings.Index(collection["name"].(string), "output") == 0 {
1577 manifest := collection["manifest_text"].(string)
1578 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1585 func (s *TestSuite) TestStderrMount(c *C) {
1586 api, _, _ := FullRunHelper(c, `{
1587 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
1588 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1591 "mounts": {"/tmp": {"kind": "tmp"},
1592 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
1593 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
1594 "output_path": "/tmp",
1596 "runtime_constraints": {}
1597 }`, nil, 1, func(t *TestDockerClient) {
1598 t.logWriter.Write(dockerLog(1, "hello\n"))
1599 t.logWriter.Write(dockerLog(2, "oops\n"))
1603 final := api.CalledWith("container.state", "Complete")
1604 c.Assert(final, NotNil)
1605 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1606 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1608 c.Check(api.CalledWith("collection.manifest_text", "./a b1946ac92492d2347c6235b4d2611184+6 0:6:out.txt\n./b 38af5c54926b620264ab1501150cf189+5 0:5:err.txt\n"), NotNil)