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/manifest"
29 dockertypes "github.com/docker/docker/api/types"
30 dockercontainer "github.com/docker/docker/api/types/container"
31 dockernetwork "github.com/docker/docker/api/types/network"
35 // Gocheck boilerplate
36 func TestCrunchExec(t *testing.T) {
40 type TestSuite struct{}
42 // Gocheck boilerplate
43 var _ = Suite(&TestSuite{})
45 type ArvTestClient struct {
48 Content []arvadosclient.Dict
50 Logs map[string]*bytes.Buffer
55 type KeepTestClient struct {
60 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
61 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
62 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
64 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
65 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
67 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
68 ./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
69 ./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
72 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
74 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"
75 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
77 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
78 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
80 type TestDockerClient struct {
82 logReader io.ReadCloser
83 logWriter io.WriteCloser
84 fn func(t *TestDockerClient)
93 func NewTestDockerClient(exitCode int) *TestDockerClient {
94 t := &TestDockerClient{}
95 t.logReader, t.logWriter = io.Pipe()
97 t.stop = make(chan bool)
102 type MockConn struct {
106 func (m *MockConn) Write(b []byte) (int, error) {
110 func NewMockConn() *MockConn {
115 func (t *TestDockerClient) ContainerAttach(ctx context.Context, container string, options dockertypes.ContainerAttachOptions) (dockertypes.HijackedResponse, error) {
116 return dockertypes.HijackedResponse{Conn: NewMockConn(), Reader: bufio.NewReader(t.logReader)}, nil
119 func (t *TestDockerClient) ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error) {
120 if config.WorkingDir != "" {
121 t.cwd = config.WorkingDir
124 return dockercontainer.ContainerCreateCreatedBody{ID: "abcde"}, nil
127 func (t *TestDockerClient) ContainerStart(ctx context.Context, container string, options dockertypes.ContainerStartOptions) error {
128 if container == "abcde" {
132 return errors.New("Invalid container id")
136 func (t *TestDockerClient) ContainerStop(ctx context.Context, container string, timeout *time.Duration) error {
141 func (t *TestDockerClient) ContainerWait(ctx context.Context, container string, condition dockercontainer.WaitCondition) (<-chan dockercontainer.ContainerWaitOKBody, <-chan error) {
142 body := make(chan dockercontainer.ContainerWaitOKBody)
143 err := make(chan error)
145 body <- dockercontainer.ContainerWaitOKBody{StatusCode: int64(t.finish)}
152 func (t *TestDockerClient) ImageInspectWithRaw(ctx context.Context, image string) (dockertypes.ImageInspect, []byte, error) {
153 if t.imageLoaded == image {
154 return dockertypes.ImageInspect{}, nil, nil
156 return dockertypes.ImageInspect{}, nil, errors.New("")
160 func (t *TestDockerClient) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (dockertypes.ImageLoadResponse, error) {
161 _, err := io.Copy(ioutil.Discard, input)
163 return dockertypes.ImageLoadResponse{}, err
165 t.imageLoaded = hwImageId
166 return dockertypes.ImageLoadResponse{Body: ioutil.NopCloser(input)}, nil
170 func (*TestDockerClient) ImageRemove(ctx context.Context, image string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {
174 func (client *ArvTestClient) Create(resourceType string,
175 parameters arvadosclient.Dict,
176 output interface{}) error {
179 defer client.Mutex.Unlock()
182 client.Content = append(client.Content, parameters)
184 if resourceType == "logs" {
185 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
186 if client.Logs == nil {
187 client.Logs = make(map[string]*bytes.Buffer)
189 if client.Logs[et] == nil {
190 client.Logs[et] = &bytes.Buffer{}
192 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
195 if resourceType == "collections" && output != nil {
196 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
197 outmap := output.(*arvados.Collection)
198 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
204 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
206 case method == "GET" && resourceType == "containers" && action == "auth":
207 return json.Unmarshal([]byte(`{
208 "kind": "arvados#api_client_authorization",
209 "uuid": "`+fakeAuthUUID+`",
210 "api_token": "`+fakeAuthToken+`"
213 return fmt.Errorf("Not found")
217 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
218 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
220 "command": ["sleep", "1"],
221 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
224 "mounts": {"/tmp": {"kind": "tmp"} },
225 "output_path": "/tmp",
227 "runtime_constraints": {}
229 return ioutil.NopCloser(bytes.NewReader(j)), nil
232 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
233 if resourceType == "collections" {
235 output.(*arvados.Collection).ManifestText = hwManifest
236 } else if uuid == otherPDH {
237 output.(*arvados.Collection).ManifestText = otherManifest
238 } else if uuid == normalizedWithSubdirsPDH {
239 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
240 } else if uuid == denormalizedWithSubdirsPDH {
241 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
244 if resourceType == "containers" {
245 (*output.(*arvados.Container)) = client.Container
250 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
252 defer client.Mutex.Unlock()
254 client.Content = append(client.Content, parameters)
255 if resourceType == "containers" {
256 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
257 client.WasSetRunning = true
263 var discoveryMap = map[string]interface{}{
264 "defaultTrashLifetime": float64(1209600),
265 "crunchLimitLogBytesPerJob": float64(67108864),
266 "crunchLogThrottleBytes": float64(65536),
267 "crunchLogThrottlePeriod": float64(60),
268 "crunchLogThrottleLines": float64(1024),
269 "crunchLogPartialLineThrottlePeriod": float64(5),
270 "crunchLogBytesPerEvent": float64(4096),
271 "crunchLogSecondsBetweenEvents": float64(1),
274 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
275 return discoveryMap[key], nil
278 // CalledWith returns the parameters from the first API call whose
279 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
280 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
281 // no call matches, it returns nil.
282 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
284 for _, content := range client.Content {
285 var v interface{} = content
286 for _, k := range strings.Split(jpath, ".") {
287 if dict, ok := v.(arvadosclient.Dict); !ok {
300 func (client *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
302 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
305 type FileWrapper struct {
310 func (fw FileWrapper) Size() int64 {
314 func (fw FileWrapper) Seek(int64, int) (int64, error) {
315 return 0, errors.New("not implemented")
318 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
319 if filename == hwImageId+".tar" {
320 rdr := ioutil.NopCloser(&bytes.Buffer{})
322 return FileWrapper{rdr, 1321984}, nil
323 } else if filename == "/file1_in_main.txt" {
324 rdr := ioutil.NopCloser(strings.NewReader("foo"))
326 return FileWrapper{rdr, 3}, nil
331 func (s *TestSuite) TestLoadImage(c *C) {
332 kc := &KeepTestClient{}
333 docker := NewTestDockerClient(0)
334 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
336 _, err := cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
338 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
341 cr.Container.ContainerImage = hwPDH
343 // (1) Test loading image from keep
344 c.Check(kc.Called, Equals, false)
345 c.Check(cr.ContainerConfig.Image, Equals, "")
351 cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
354 c.Check(kc.Called, Equals, true)
355 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
357 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
360 // (2) Test using image that's already loaded
362 cr.ContainerConfig.Image = ""
366 c.Check(kc.Called, Equals, false)
367 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
371 type ArvErrorTestClient struct{}
373 func (ArvErrorTestClient) Create(resourceType string,
374 parameters arvadosclient.Dict,
375 output interface{}) error {
379 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
380 return errors.New("ArvError")
383 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
384 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
385 return nil, errors.New("ArvError")
388 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
389 return errors.New("ArvError")
392 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
396 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
397 return discoveryMap[key], nil
400 type KeepErrorTestClient struct{}
402 func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
403 return "", 0, errors.New("KeepError")
406 func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
407 return nil, errors.New("KeepError")
410 type KeepReadErrorTestClient struct{}
412 func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
416 type ErrorReader struct{}
418 func (ErrorReader) Read(p []byte) (n int, err error) {
419 return 0, errors.New("ErrorReader")
422 func (ErrorReader) Close() error {
426 func (ErrorReader) Size() int64 {
430 func (ErrorReader) Seek(int64, int) (int64, error) {
431 return 0, errors.New("ErrorReader")
434 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
435 return ErrorReader{}, nil
438 func (s *TestSuite) TestLoadImageArvError(c *C) {
440 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
441 cr.Container.ContainerImage = hwPDH
443 err := cr.LoadImage()
444 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
447 func (s *TestSuite) TestLoadImageKeepError(c *C) {
449 docker := NewTestDockerClient(0)
450 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
451 cr.Container.ContainerImage = hwPDH
453 err := cr.LoadImage()
454 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
457 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
458 // (3) Collection doesn't contain image
459 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
460 cr.Container.ContainerImage = otherPDH
462 err := cr.LoadImage()
463 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
466 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
467 // (4) Collection doesn't contain image
468 docker := NewTestDockerClient(0)
469 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
470 cr.Container.ContainerImage = hwPDH
472 err := cr.LoadImage()
476 type ClosableBuffer struct {
480 func (*ClosableBuffer) Close() error {
484 type TestLogs struct {
485 Stdout ClosableBuffer
486 Stderr ClosableBuffer
489 func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
490 if logstr == "stdout" {
493 if logstr == "stderr" {
499 func dockerLog(fd byte, msg string) []byte {
501 header := make([]byte, 8+len(by))
503 header[7] = byte(len(by))
508 func (s *TestSuite) TestRunContainer(c *C) {
509 docker := NewTestDockerClient(0)
510 docker.fn = func(t *TestDockerClient) {
511 t.logWriter.Write(dockerLog(1, "Hello world\n"))
514 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
517 cr.NewLogWriter = logs.NewTestLoggingWriter
518 cr.Container.ContainerImage = hwPDH
519 cr.Container.Command = []string{"./hw"}
520 err := cr.LoadImage()
523 err = cr.CreateContainer()
526 err = cr.StartContainer()
529 err = cr.WaitFinish()
532 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
533 c.Check(logs.Stderr.String(), Equals, "")
536 func (s *TestSuite) TestCommitLogs(c *C) {
537 api := &ArvTestClient{}
538 kc := &KeepTestClient{}
539 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
540 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
542 cr.CrunchLog.Print("Hello world!")
543 cr.CrunchLog.Print("Goodbye")
544 cr.finalState = "Complete"
546 err := cr.CommitLogs()
549 c.Check(api.Calls, Equals, 2)
550 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
551 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
552 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
553 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
556 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
557 api := &ArvTestClient{}
558 kc := &KeepTestClient{}
559 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
561 err := cr.UpdateContainerRunning()
564 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
567 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
568 api := &ArvTestClient{}
569 kc := &KeepTestClient{}
570 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
572 cr.LogsPDH = new(string)
573 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
575 cr.ExitCode = new(int)
577 cr.finalState = "Complete"
579 err := cr.UpdateContainerFinal()
582 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
583 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
584 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
587 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
588 api := &ArvTestClient{}
589 kc := &KeepTestClient{}
590 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
592 cr.finalState = "Cancelled"
594 err := cr.UpdateContainerFinal()
597 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
598 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
599 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
602 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
603 // dress rehearsal of the Run() function, starting from a JSON container record.
604 func FullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, realTemp string) {
605 rec := arvados.Container{}
606 err := json.Unmarshal([]byte(record), &rec)
609 docker := NewTestDockerClient(exitCode)
611 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
613 api = &ArvTestClient{Container: rec}
615 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
616 cr.statInterval = 100 * time.Millisecond
617 am := &ArvMountCmdLine{}
618 cr.RunArvMount = am.ArvMountTest
620 realTemp, err = ioutil.TempDir("", "crunchrun_test1-")
622 defer os.RemoveAll(realTemp)
624 docker.realTemp = realTemp
627 cr.MkTempDir = func(_ string, prefix string) (string, error) {
629 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
630 err := os.Mkdir(d, os.ModePerm)
631 if err != nil && strings.Contains(err.Error(), ": file exists") {
632 // Test case must have pre-populated the tempdir
638 if extraMounts != nil && len(extraMounts) > 0 {
639 err := cr.SetupArvMountPoint("keep")
642 for _, m := range extraMounts {
643 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
648 if api.CalledWith("container.state", "Complete") != nil {
651 c.Check(api.WasSetRunning, Equals, true)
653 c.Check(api.Content[api.Calls-1]["container"].(arvadosclient.Dict)["log"], NotNil)
656 for k, v := range api.Logs {
665 func (s *TestSuite) TestFullRunHello(c *C) {
666 api, _, _ := FullRunHelper(c, `{
667 "command": ["echo", "hello world"],
668 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
671 "mounts": {"/tmp": {"kind": "tmp"} },
672 "output_path": "/tmp",
674 "runtime_constraints": {}
675 }`, nil, 0, func(t *TestDockerClient) {
676 t.logWriter.Write(dockerLog(1, "hello world\n"))
680 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
681 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
682 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
686 func (s *TestSuite) TestCrunchstat(c *C) {
687 api, _, _ := FullRunHelper(c, `{
688 "command": ["sleep", "1"],
689 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
692 "mounts": {"/tmp": {"kind": "tmp"} },
693 "output_path": "/tmp",
695 "runtime_constraints": {}
696 }`, nil, 0, func(t *TestDockerClient) {
697 time.Sleep(time.Second)
701 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
702 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
704 // We didn't actually start a container, so crunchstat didn't
705 // find accounting files and therefore didn't log any stats.
706 // It should have logged a "can't find accounting files"
707 // message after one poll interval, though, so we can confirm
709 c.Assert(api.Logs["crunchstat"], NotNil)
710 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
712 // The "files never appeared" log assures us that we called
713 // (*crunchstat.Reporter)Stop(), and that we set it up with
714 // the correct container ID "abcde":
715 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
718 func (s *TestSuite) TestNodeInfoLog(c *C) {
719 api, _, _ := FullRunHelper(c, `{
720 "command": ["sleep", "1"],
721 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
724 "mounts": {"/tmp": {"kind": "tmp"} },
725 "output_path": "/tmp",
727 "runtime_constraints": {}
729 func(t *TestDockerClient) {
730 time.Sleep(time.Second)
734 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
735 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
737 c.Assert(api.Logs["node-info"], NotNil)
738 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Host Information.*`)
739 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*CPU Information.*`)
740 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Memory Information.*`)
741 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk Space.*`)
742 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk INodes.*`)
745 func (s *TestSuite) TestContainerRecordLog(c *C) {
746 api, _, _ := FullRunHelper(c, `{
747 "command": ["sleep", "1"],
748 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
751 "mounts": {"/tmp": {"kind": "tmp"} },
752 "output_path": "/tmp",
754 "runtime_constraints": {}
756 func(t *TestDockerClient) {
757 time.Sleep(time.Second)
761 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
762 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
764 c.Assert(api.Logs["container"], NotNil)
765 c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
768 func (s *TestSuite) TestFullRunStderr(c *C) {
769 api, _, _ := FullRunHelper(c, `{
770 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
771 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
774 "mounts": {"/tmp": {"kind": "tmp"} },
775 "output_path": "/tmp",
777 "runtime_constraints": {}
778 }`, nil, 1, func(t *TestDockerClient) {
779 t.logWriter.Write(dockerLog(1, "hello\n"))
780 t.logWriter.Write(dockerLog(2, "world\n"))
784 final := api.CalledWith("container.state", "Complete")
785 c.Assert(final, NotNil)
786 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
787 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
789 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
790 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
793 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
794 api, _, _ := FullRunHelper(c, `{
796 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
799 "mounts": {"/tmp": {"kind": "tmp"} },
800 "output_path": "/tmp",
802 "runtime_constraints": {}
803 }`, nil, 0, func(t *TestDockerClient) {
804 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
808 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
809 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
810 c.Log(api.Logs["stdout"])
811 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
814 func (s *TestSuite) TestFullRunSetCwd(c *C) {
815 api, _, _ := FullRunHelper(c, `{
817 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
820 "mounts": {"/tmp": {"kind": "tmp"} },
821 "output_path": "/tmp",
823 "runtime_constraints": {}
824 }`, nil, 0, func(t *TestDockerClient) {
825 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
829 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
830 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
831 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
834 func (s *TestSuite) TestStopOnSignal(c *C) {
835 s.testStopContainer(c, func(cr *ContainerRunner) {
838 time.Sleep(time.Millisecond)
840 cr.SigChan <- syscall.SIGINT
845 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
846 s.testStopContainer(c, func(cr *ContainerRunner) {
847 cr.ArvMountExit = make(chan error)
849 cr.ArvMountExit <- exec.Command("true").Run()
850 close(cr.ArvMountExit)
855 func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
857 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
858 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
861 "mounts": {"/tmp": {"kind": "tmp"} },
862 "output_path": "/tmp",
864 "runtime_constraints": {}
867 rec := arvados.Container{}
868 err := json.Unmarshal([]byte(record), &rec)
871 docker := NewTestDockerClient(0)
872 docker.fn = func(t *TestDockerClient) {
874 t.logWriter.Write(dockerLog(1, "foo\n"))
877 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
879 api := &ArvTestClient{Container: rec}
880 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
881 cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
884 done := make(chan error)
889 case <-time.After(20 * time.Second):
890 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
895 for k, v := range api.Logs {
900 c.Check(api.CalledWith("container.log", nil), NotNil)
901 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
902 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
905 func (s *TestSuite) TestFullRunSetEnv(c *C) {
906 api, _, _ := FullRunHelper(c, `{
907 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
908 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
910 "environment": {"FROBIZ": "bilbo"},
911 "mounts": {"/tmp": {"kind": "tmp"} },
912 "output_path": "/tmp",
914 "runtime_constraints": {}
915 }`, nil, 0, func(t *TestDockerClient) {
916 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
920 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
921 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
922 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
925 type ArvMountCmdLine struct {
930 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
936 func stubCert(temp string) string {
937 path := temp + "/ca-certificates.crt"
938 crt, _ := os.Create(path)
940 arvadosclient.CertFiles = []string{path}
944 func (s *TestSuite) TestSetupMounts(c *C) {
945 api := &ArvTestClient{}
946 kc := &KeepTestClient{}
947 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
948 am := &ArvMountCmdLine{}
949 cr.RunArvMount = am.ArvMountTest
951 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
953 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
955 stubCertPath := stubCert(certTemp)
957 defer os.RemoveAll(realTemp)
958 defer os.RemoveAll(certTemp)
961 cr.MkTempDir = func(_ string, prefix string) (string, error) {
963 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
964 err := os.Mkdir(d, os.ModePerm)
965 if err != nil && strings.Contains(err.Error(), ": file exists") {
966 // Test case must have pre-populated the tempdir
972 checkEmpty := func() {
973 filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
974 c.Check(path, Equals, realTemp)
982 cr.ArvMountPoint = ""
983 cr.Container.Mounts = make(map[string]arvados.Mount)
984 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
985 cr.OutputPath = "/tmp"
987 err := cr.SetupMounts()
989 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
990 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
997 cr.ArvMountPoint = ""
998 cr.Container.Mounts = make(map[string]arvados.Mount)
999 cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"}
1000 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1001 cr.OutputPath = "/out"
1003 err := cr.SetupMounts()
1005 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1006 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/out", realTemp + "/3:/tmp"})
1013 cr.ArvMountPoint = ""
1014 cr.Container.Mounts = make(map[string]arvados.Mount)
1015 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1016 cr.OutputPath = "/tmp"
1019 cr.Container.RuntimeConstraints.API = &apiflag
1021 err := cr.SetupMounts()
1023 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1024 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
1033 cr.ArvMountPoint = ""
1034 cr.Container.Mounts = map[string]arvados.Mount{
1035 "/keeptmp": {Kind: "collection", Writable: true},
1037 cr.OutputPath = "/keeptmp"
1039 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1041 err := cr.SetupMounts()
1043 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1044 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
1051 cr.ArvMountPoint = ""
1052 cr.Container.Mounts = map[string]arvados.Mount{
1053 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1054 "/keepout": {Kind: "collection", Writable: true},
1056 cr.OutputPath = "/keepout"
1058 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1059 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1061 err := cr.SetupMounts()
1063 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1064 sort.StringSlice(cr.Binds).Sort()
1065 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1066 realTemp + "/keep1/tmp0:/keepout"})
1073 cr.ArvMountPoint = ""
1074 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1075 cr.Container.Mounts = map[string]arvados.Mount{
1076 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1077 "/keepout": {Kind: "collection", Writable: true},
1079 cr.OutputPath = "/keepout"
1081 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1082 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1084 err := cr.SetupMounts()
1086 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1087 sort.StringSlice(cr.Binds).Sort()
1088 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1089 realTemp + "/keep1/tmp0:/keepout"})
1094 for _, test := range []struct {
1098 {in: "foo", out: `"foo"`},
1099 {in: nil, out: `null`},
1100 {in: map[string]int{"foo": 123}, out: `{"foo":123}`},
1103 cr.ArvMountPoint = ""
1104 cr.Container.Mounts = map[string]arvados.Mount{
1105 "/mnt/test.json": {Kind: "json", Content: test.in},
1107 err := cr.SetupMounts()
1109 sort.StringSlice(cr.Binds).Sort()
1110 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
1111 content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
1113 c.Check(content, DeepEquals, []byte(test.out))
1118 // Read-only mount points are allowed underneath output_dir mount point
1121 cr.ArvMountPoint = ""
1122 cr.Container.Mounts = make(map[string]arvados.Mount)
1123 cr.Container.Mounts = map[string]arvados.Mount{
1124 "/tmp": {Kind: "tmp"},
1125 "/tmp/foo": {Kind: "collection"},
1127 cr.OutputPath = "/tmp"
1129 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1131 err := cr.SetupMounts()
1133 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1134 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
1139 // Writable mount points are not allowed underneath output_dir mount point
1142 cr.ArvMountPoint = ""
1143 cr.Container.Mounts = make(map[string]arvados.Mount)
1144 cr.Container.Mounts = map[string]arvados.Mount{
1145 "/tmp": {Kind: "tmp"},
1146 "/tmp/foo": {Kind: "collection", Writable: true},
1148 cr.OutputPath = "/tmp"
1150 err := cr.SetupMounts()
1151 c.Check(err, NotNil)
1152 c.Check(err, ErrorMatches, `Writable mount points are not permitted underneath the output_path.*`)
1157 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1160 cr.ArvMountPoint = ""
1161 cr.Container.Mounts = make(map[string]arvados.Mount)
1162 cr.Container.Mounts = map[string]arvados.Mount{
1163 "/tmp": {Kind: "tmp"},
1164 "/tmp/foo": {Kind: "json"},
1166 cr.OutputPath = "/tmp"
1168 err := cr.SetupMounts()
1169 c.Check(err, NotNil)
1170 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1175 // Only mount point of kind 'collection' is allowed for stdin
1178 cr.ArvMountPoint = ""
1179 cr.Container.Mounts = make(map[string]arvados.Mount)
1180 cr.Container.Mounts = map[string]arvados.Mount{
1181 "stdin": {Kind: "tmp"},
1184 err := cr.SetupMounts()
1185 c.Check(err, NotNil)
1186 c.Check(err, ErrorMatches, `Unsupported mount kind 'tmp' for stdin.*`)
1192 func (s *TestSuite) TestStdout(c *C) {
1194 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1195 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1197 "environment": {"FROBIZ": "bilbo"},
1198 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1199 "output_path": "/tmp",
1201 "runtime_constraints": {}
1204 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1205 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1209 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1210 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1211 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1214 // Used by the TestStdoutWithWrongPath*()
1215 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1216 rec := arvados.Container{}
1217 err = json.Unmarshal([]byte(record), &rec)
1220 docker := NewTestDockerClient(0)
1222 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1224 api = &ArvTestClient{Container: rec}
1225 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1226 am := &ArvMountCmdLine{}
1227 cr.RunArvMount = am.ArvMountTest
1233 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1234 _, _, err := StdoutErrorRunHelper(c, `{
1235 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1236 "output_path": "/tmp"
1237 }`, func(t *TestDockerClient) {})
1239 c.Check(err, NotNil)
1240 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1243 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1244 _, _, err := StdoutErrorRunHelper(c, `{
1245 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1246 "output_path": "/tmp"
1247 }`, func(t *TestDockerClient) {})
1249 c.Check(err, NotNil)
1250 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1253 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1254 _, _, err := StdoutErrorRunHelper(c, `{
1255 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1256 "output_path": "/tmp"
1257 }`, func(t *TestDockerClient) {})
1259 c.Check(err, NotNil)
1260 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1263 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1264 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1265 defer os.Unsetenv("ARVADOS_API_HOST")
1266 api, _, _ := FullRunHelper(c, `{
1267 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1268 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1271 "mounts": {"/tmp": {"kind": "tmp"} },
1272 "output_path": "/tmp",
1274 "runtime_constraints": {"API": true}
1275 }`, nil, 0, func(t *TestDockerClient) {
1276 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1280 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1281 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1282 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1283 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1286 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1287 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1288 defer os.Unsetenv("ARVADOS_API_HOST")
1289 api, _, _ := FullRunHelper(c, `{
1290 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1291 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1294 "mounts": {"/tmp": {"kind": "tmp"} },
1295 "output_path": "/tmp",
1297 "runtime_constraints": {"API": true}
1298 }`, nil, 0, func(t *TestDockerClient) {
1299 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1303 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1304 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1305 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1308 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1310 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1311 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1313 "environment": {"FROBIZ": "bilbo"},
1315 "/tmp": {"kind": "tmp"},
1316 "/tmp/foo": {"kind": "collection",
1317 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1318 "exclude_from_output": true
1320 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1322 "output_path": "/tmp",
1324 "runtime_constraints": {}
1327 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1329 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1330 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1334 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1335 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1336 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1339 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1341 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1342 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1344 "environment": {"FROBIZ": "bilbo"},
1346 "/tmp": {"kind": "tmp"},
1347 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1348 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1349 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1350 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1351 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1353 "output_path": "/tmp",
1355 "runtime_constraints": {}
1358 extraMounts := []string{
1359 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1360 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1361 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1364 api, runner, realtemp := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1365 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1369 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/2:/tmp",
1370 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1371 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1372 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1373 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1376 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1377 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1378 for _, v := range api.Content {
1379 if v["collection"] != nil {
1380 c.Check(v["ensure_unique_name"], Equals, true)
1381 collection := v["collection"].(arvadosclient.Dict)
1382 if strings.Index(collection["name"].(string), "output") == 0 {
1383 manifest := collection["manifest_text"].(string)
1385 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1386 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar 9:18:sub1file2
1387 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1388 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1389 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1396 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1398 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1399 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1401 "environment": {"FROBIZ": "bilbo"},
1403 "/tmp": {"kind": "tmp"},
1404 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1405 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1407 "output_path": "/tmp",
1409 "runtime_constraints": {}
1412 extraMounts := []string{
1413 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1416 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1417 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1421 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1422 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1423 for _, v := range api.Content {
1424 if v["collection"] != nil {
1425 collection := v["collection"].(arvadosclient.Dict)
1426 if strings.Index(collection["name"].(string), "output") == 0 {
1427 manifest := collection["manifest_text"].(string)
1429 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1430 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1437 func (s *TestSuite) TestOutputSymlinkToInput(c *C) {
1439 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1440 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1442 "environment": {"FROBIZ": "bilbo"},
1444 "/tmp": {"kind": "tmp"},
1445 "/keep/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path": "/subdir1/file2_in_subdir1.txt"},
1446 "/keep/foo2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367"}
1448 "output_path": "/tmp",
1450 "runtime_constraints": {}
1453 extraMounts := []string{
1454 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1457 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1458 os.Symlink("/keep/foo/sub1file2", t.realTemp+"/2/baz")
1459 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz2")
1460 os.Symlink("/keep/foo2/subdir1", t.realTemp+"/2/baz3")
1461 os.Mkdir(t.realTemp+"/2/baz4", 0700)
1462 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz4/baz5")
1466 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1467 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1468 for _, v := range api.Content {
1469 if v["collection"] != nil {
1470 collection := v["collection"].(arvadosclient.Dict)
1471 if strings.Index(collection["name"].(string), "output") == 0 {
1472 manifest := collection["manifest_text"].(string)
1473 c.Check(manifest, Equals, `. 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz 9:18:baz2
1474 ./baz3 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1475 ./baz3/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1476 ./baz4 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz5
1483 func (s *TestSuite) TestOutputError(c *C) {
1485 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1486 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1488 "environment": {"FROBIZ": "bilbo"},
1490 "/tmp": {"kind": "tmp"}
1492 "output_path": "/tmp",
1494 "runtime_constraints": {}
1497 extraMounts := []string{}
1499 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1500 os.Symlink("/etc/hosts", t.realTemp+"/2/baz")
1504 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1507 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1509 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1510 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1512 "environment": {"FROBIZ": "bilbo"},
1514 "/tmp": {"kind": "tmp"},
1515 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1516 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1518 "output_path": "/tmp",
1520 "runtime_constraints": {}
1523 extraMounts := []string{
1524 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1527 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1528 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1532 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1533 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1534 for _, v := range api.Content {
1535 if v["collection"] != nil {
1536 collection := v["collection"].(arvadosclient.Dict)
1537 if strings.Index(collection["name"].(string), "output") == 0 {
1538 manifest := collection["manifest_text"].(string)
1539 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1546 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1548 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1549 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1551 "environment": {"FROBIZ": "bilbo"},
1553 "/tmp": {"kind": "tmp"},
1554 "stdin": {"kind": "json", "content": "foo"},
1555 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1557 "output_path": "/tmp",
1559 "runtime_constraints": {}
1562 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1563 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1567 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1568 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1569 for _, v := range api.Content {
1570 if v["collection"] != nil {
1571 collection := v["collection"].(arvadosclient.Dict)
1572 if strings.Index(collection["name"].(string), "output") == 0 {
1573 manifest := collection["manifest_text"].(string)
1574 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1581 func (s *TestSuite) TestStderrMount(c *C) {
1582 api, _, _ := FullRunHelper(c, `{
1583 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
1584 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1587 "mounts": {"/tmp": {"kind": "tmp"},
1588 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
1589 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
1590 "output_path": "/tmp",
1592 "runtime_constraints": {}
1593 }`, nil, 1, func(t *TestDockerClient) {
1594 t.logWriter.Write(dockerLog(1, "hello\n"))
1595 t.logWriter.Write(dockerLog(2, "oops\n"))
1599 final := api.CalledWith("container.state", "Complete")
1600 c.Assert(final, NotNil)
1601 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1602 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1604 c.Check(api.CalledWith("collection.manifest_text", "./a b1946ac92492d2347c6235b4d2611184+6 0:6:out.txt\n./b 38af5c54926b620264ab1501150cf189+5 0:5:err.txt\n"), NotNil)