25 "git.curoverse.com/arvados.git/sdk/go/arvados"
26 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
27 "git.curoverse.com/arvados.git/sdk/go/keepclient"
28 "git.curoverse.com/arvados.git/sdk/go/manifest"
30 dockertypes "github.com/docker/docker/api/types"
31 dockercontainer "github.com/docker/docker/api/types/container"
32 dockernetwork "github.com/docker/docker/api/types/network"
36 // Gocheck boilerplate
37 func TestCrunchExec(t *testing.T) {
41 type TestSuite struct{}
43 // Gocheck boilerplate
44 var _ = Suite(&TestSuite{})
46 type ArvTestClient struct {
49 Content []arvadosclient.Dict
51 Logs map[string]*bytes.Buffer
56 type KeepTestClient struct {
61 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
62 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
63 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
65 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
66 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
68 var normalizedManifestWithSubdirs = ". 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 0:9:file1_in_main.txt 9:18:file2_in_main.txt 0:27:zzzzz-8i9sb-bcdefghijkdhvnk.log.txt\n./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt\n./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt\n"
69 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
71 var denormalizedManifestWithSubdirs = ". 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 0:9:file1_in_main.txt 9:18:file2_in_main.txt 0:27:zzzzz-8i9sb-bcdefghijkdhvnk.log.txt 0:10:subdir1/file1_in_subdir1.txt 10:17:subdir1/file2_in_subdir1.txt\n"
72 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
74 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
75 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
77 type TestDockerClient struct {
79 logReader io.ReadCloser
80 logWriter io.WriteCloser
81 fn func(t *TestDockerClient)
89 func NewTestDockerClient(exitCode int) *TestDockerClient {
90 t := &TestDockerClient{}
91 t.logReader, t.logWriter = io.Pipe()
93 t.stop = make(chan bool)
98 type MockConn struct {
102 func (m *MockConn) Write(b []byte) (int, error) {
106 func NewMockConn() *MockConn {
111 func (t *TestDockerClient) ContainerAttach(ctx context.Context, container string, options dockertypes.ContainerAttachOptions) (dockertypes.HijackedResponse, error) {
112 return dockertypes.HijackedResponse{Conn: NewMockConn(), Reader: bufio.NewReader(t.logReader)}, nil
115 func (t *TestDockerClient) ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error) {
116 if config.WorkingDir != "" {
117 t.cwd = config.WorkingDir
120 return dockercontainer.ContainerCreateCreatedBody{ID: "abcde"}, nil
123 func (t *TestDockerClient) ContainerStart(ctx context.Context, container string, options dockertypes.ContainerStartOptions) error {
124 if container == "abcde" {
128 return errors.New("Invalid container id")
132 func (t *TestDockerClient) ContainerStop(ctx context.Context, container string, timeout *time.Duration) error {
137 func (t *TestDockerClient) ContainerWait(ctx context.Context, container string) (int64, error) {
138 return int64(t.finish), nil
141 func (t *TestDockerClient) ImageInspectWithRaw(ctx context.Context, image string) (dockertypes.ImageInspect, []byte, error) {
142 if t.imageLoaded == image {
143 return dockertypes.ImageInspect{}, nil, nil
145 return dockertypes.ImageInspect{}, nil, errors.New("")
149 func (t *TestDockerClient) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (dockertypes.ImageLoadResponse, error) {
150 _, err := io.Copy(ioutil.Discard, input)
152 return dockertypes.ImageLoadResponse{}, err
154 t.imageLoaded = hwImageId
155 return dockertypes.ImageLoadResponse{Body: ioutil.NopCloser(input)}, nil
159 func (*TestDockerClient) ImageRemove(ctx context.Context, image string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {
163 func (client *ArvTestClient) Create(resourceType string,
164 parameters arvadosclient.Dict,
165 output interface{}) error {
168 defer client.Mutex.Unlock()
171 client.Content = append(client.Content, parameters)
173 if resourceType == "logs" {
174 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
175 if client.Logs == nil {
176 client.Logs = make(map[string]*bytes.Buffer)
178 if client.Logs[et] == nil {
179 client.Logs[et] = &bytes.Buffer{}
181 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
184 if resourceType == "collections" && output != nil {
185 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
186 outmap := output.(*arvados.Collection)
187 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
193 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
195 case method == "GET" && resourceType == "containers" && action == "auth":
196 return json.Unmarshal([]byte(`{
197 "kind": "arvados#api_client_authorization",
198 "uuid": "`+fakeAuthUUID+`",
199 "api_token": "`+fakeAuthToken+`"
202 return fmt.Errorf("Not found")
206 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
207 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
209 "command": ["sleep", "1"],
210 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
213 "mounts": {"/tmp": {"kind": "tmp"} },
214 "output_path": "/tmp",
216 "runtime_constraints": {}
218 return ioutil.NopCloser(bytes.NewReader(j)), nil
221 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
222 if resourceType == "collections" {
224 output.(*arvados.Collection).ManifestText = hwManifest
225 } else if uuid == otherPDH {
226 output.(*arvados.Collection).ManifestText = otherManifest
227 } else if uuid == normalizedWithSubdirsPDH {
228 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
229 } else if uuid == denormalizedWithSubdirsPDH {
230 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
233 if resourceType == "containers" {
234 (*output.(*arvados.Container)) = client.Container
239 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
241 defer client.Mutex.Unlock()
243 client.Content = append(client.Content, parameters)
244 if resourceType == "containers" {
245 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
246 client.WasSetRunning = true
252 var discoveryMap = map[string]interface{}{
253 "defaultTrashLifetime": float64(1209600),
254 "crunchLimitLogBytesPerJob": float64(67108864),
255 "crunchLogThrottleBytes": float64(65536),
256 "crunchLogThrottlePeriod": float64(60),
257 "crunchLogThrottleLines": float64(1024),
258 "crunchLogPartialLineThrottlePeriod": float64(5),
259 "crunchLogBytesPerEvent": float64(4096),
260 "crunchLogSecondsBetweenEvents": float64(1),
263 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
264 return discoveryMap[key], nil
267 // CalledWith returns the parameters from the first API call whose
268 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
269 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
270 // no call matches, it returns nil.
271 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
273 for _, content := range client.Content {
274 var v interface{} = content
275 for _, k := range strings.Split(jpath, ".") {
276 if dict, ok := v.(arvadosclient.Dict); !ok {
289 func (client *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
291 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
294 type FileWrapper struct {
299 func (fw FileWrapper) Len() uint64 {
303 func (fw FileWrapper) Seek(int64, int) (int64, error) {
304 return 0, errors.New("not implemented")
307 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
308 if filename == hwImageId+".tar" {
309 rdr := ioutil.NopCloser(&bytes.Buffer{})
311 return FileWrapper{rdr, 1321984}, nil
312 } else if filename == "/file1_in_main.txt" {
313 rdr := ioutil.NopCloser(strings.NewReader("foo"))
315 return FileWrapper{rdr, 3}, nil
320 func (s *TestSuite) TestLoadImage(c *C) {
321 kc := &KeepTestClient{}
322 docker := NewTestDockerClient(0)
323 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
325 _, err := cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
327 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
330 cr.Container.ContainerImage = hwPDH
332 // (1) Test loading image from keep
333 c.Check(kc.Called, Equals, false)
334 c.Check(cr.ContainerConfig.Image, Equals, "")
340 cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
343 c.Check(kc.Called, Equals, true)
344 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
346 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
349 // (2) Test using image that's already loaded
351 cr.ContainerConfig.Image = ""
355 c.Check(kc.Called, Equals, false)
356 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
360 type ArvErrorTestClient struct{}
362 func (ArvErrorTestClient) Create(resourceType string,
363 parameters arvadosclient.Dict,
364 output interface{}) error {
368 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
369 return errors.New("ArvError")
372 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
373 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
374 return nil, errors.New("ArvError")
377 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
378 return errors.New("ArvError")
381 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
385 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
386 return discoveryMap[key], nil
389 type KeepErrorTestClient struct{}
391 func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
392 return "", 0, errors.New("KeepError")
395 func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
396 return nil, errors.New("KeepError")
399 type KeepReadErrorTestClient struct{}
401 func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
405 type ErrorReader struct{}
407 func (ErrorReader) Read(p []byte) (n int, err error) {
408 return 0, errors.New("ErrorReader")
411 func (ErrorReader) Close() error {
415 func (ErrorReader) Len() uint64 {
419 func (ErrorReader) Seek(int64, int) (int64, error) {
420 return 0, errors.New("ErrorReader")
423 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (keepclient.Reader, error) {
424 return ErrorReader{}, nil
427 func (s *TestSuite) TestLoadImageArvError(c *C) {
429 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
430 cr.Container.ContainerImage = hwPDH
432 err := cr.LoadImage()
433 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
436 func (s *TestSuite) TestLoadImageKeepError(c *C) {
438 docker := NewTestDockerClient(0)
439 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
440 cr.Container.ContainerImage = hwPDH
442 err := cr.LoadImage()
443 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
446 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
447 // (3) Collection doesn't contain image
448 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
449 cr.Container.ContainerImage = otherPDH
451 err := cr.LoadImage()
452 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
455 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
456 // (4) Collection doesn't contain image
457 docker := NewTestDockerClient(0)
458 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
459 cr.Container.ContainerImage = hwPDH
461 err := cr.LoadImage()
465 type ClosableBuffer struct {
469 func (*ClosableBuffer) Close() error {
473 type TestLogs struct {
474 Stdout ClosableBuffer
475 Stderr ClosableBuffer
478 func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
479 if logstr == "stdout" {
482 if logstr == "stderr" {
488 func dockerLog(fd byte, msg string) []byte {
490 header := make([]byte, 8+len(by))
492 header[7] = byte(len(by))
497 func (s *TestSuite) TestRunContainer(c *C) {
498 docker := NewTestDockerClient(0)
499 docker.fn = func(t *TestDockerClient) {
500 t.logWriter.Write(dockerLog(1, "Hello world\n"))
503 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
506 cr.NewLogWriter = logs.NewTestLoggingWriter
507 cr.Container.ContainerImage = hwPDH
508 cr.Container.Command = []string{"./hw"}
509 err := cr.LoadImage()
512 err = cr.CreateContainer()
515 err = cr.StartContainer()
518 err = cr.WaitFinish()
521 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
522 c.Check(logs.Stderr.String(), Equals, "")
525 func (s *TestSuite) TestCommitLogs(c *C) {
526 api := &ArvTestClient{}
527 kc := &KeepTestClient{}
528 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
529 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
531 cr.CrunchLog.Print("Hello world!")
532 cr.CrunchLog.Print("Goodbye")
533 cr.finalState = "Complete"
535 err := cr.CommitLogs()
538 c.Check(api.Calls, Equals, 2)
539 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
540 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
541 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
542 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
545 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
546 api := &ArvTestClient{}
547 kc := &KeepTestClient{}
548 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
550 err := cr.UpdateContainerRunning()
553 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
556 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
557 api := &ArvTestClient{}
558 kc := &KeepTestClient{}
559 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
561 cr.LogsPDH = new(string)
562 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
564 cr.ExitCode = new(int)
566 cr.finalState = "Complete"
568 err := cr.UpdateContainerFinal()
571 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
572 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
573 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
576 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
577 api := &ArvTestClient{}
578 kc := &KeepTestClient{}
579 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
581 cr.finalState = "Cancelled"
583 err := cr.UpdateContainerFinal()
586 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
587 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
588 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
591 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
592 // dress rehearsal of the Run() function, starting from a JSON container record.
593 func FullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, realTemp string) {
594 rec := arvados.Container{}
595 err := json.Unmarshal([]byte(record), &rec)
598 docker := NewTestDockerClient(exitCode)
600 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
602 api = &ArvTestClient{Container: rec}
604 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
605 cr.statInterval = 100 * time.Millisecond
606 am := &ArvMountCmdLine{}
607 cr.RunArvMount = am.ArvMountTest
609 realTemp, err = ioutil.TempDir("", "crunchrun_test1-")
611 defer os.RemoveAll(realTemp)
614 cr.MkTempDir = func(_ string, prefix string) (string, error) {
616 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
617 err := os.Mkdir(d, os.ModePerm)
618 if err != nil && strings.Contains(err.Error(), ": file exists") {
619 // Test case must have pre-populated the tempdir
625 if extraMounts != nil && len(extraMounts) > 0 {
626 err := cr.SetupArvMountPoint("keep")
629 for _, m := range extraMounts {
630 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
636 c.Check(api.WasSetRunning, Equals, true)
638 c.Check(api.Content[api.Calls-1]["container"].(arvadosclient.Dict)["log"], NotNil)
641 for k, v := range api.Logs {
650 func (s *TestSuite) TestFullRunHello(c *C) {
651 api, _, _ := FullRunHelper(c, `{
652 "command": ["echo", "hello world"],
653 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
656 "mounts": {"/tmp": {"kind": "tmp"} },
657 "output_path": "/tmp",
659 "runtime_constraints": {}
660 }`, nil, 0, func(t *TestDockerClient) {
661 t.logWriter.Write(dockerLog(1, "hello world\n"))
665 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
666 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
667 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
671 func (s *TestSuite) TestCrunchstat(c *C) {
672 api, _, _ := FullRunHelper(c, `{
673 "command": ["sleep", "1"],
674 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
677 "mounts": {"/tmp": {"kind": "tmp"} },
678 "output_path": "/tmp",
680 "runtime_constraints": {}
681 }`, nil, 0, func(t *TestDockerClient) {
682 time.Sleep(time.Second)
686 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
687 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
689 // We didn't actually start a container, so crunchstat didn't
690 // find accounting files and therefore didn't log any stats.
691 // It should have logged a "can't find accounting files"
692 // message after one poll interval, though, so we can confirm
694 c.Assert(api.Logs["crunchstat"], NotNil)
695 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
697 // The "files never appeared" log assures us that we called
698 // (*crunchstat.Reporter)Stop(), and that we set it up with
699 // the correct container ID "abcde":
700 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
703 func (s *TestSuite) TestNodeInfoLog(c *C) {
704 api, _, _ := FullRunHelper(c, `{
705 "command": ["sleep", "1"],
706 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
709 "mounts": {"/tmp": {"kind": "tmp"} },
710 "output_path": "/tmp",
712 "runtime_constraints": {}
714 func(t *TestDockerClient) {
715 time.Sleep(time.Second)
719 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
720 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
722 c.Assert(api.Logs["node-info"], NotNil)
723 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Host Information.*`)
724 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*CPU Information.*`)
725 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Memory Information.*`)
726 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk Space.*`)
727 c.Check(api.Logs["node-info"].String(), Matches, `(?ms).*Disk INodes.*`)
730 func (s *TestSuite) TestContainerRecordLog(c *C) {
731 api, _, _ := FullRunHelper(c, `{
732 "command": ["sleep", "1"],
733 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
736 "mounts": {"/tmp": {"kind": "tmp"} },
737 "output_path": "/tmp",
739 "runtime_constraints": {}
741 func(t *TestDockerClient) {
742 time.Sleep(time.Second)
746 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
747 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
749 c.Assert(api.Logs["container"], NotNil)
750 c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
753 func (s *TestSuite) TestFullRunStderr(c *C) {
754 api, _, _ := FullRunHelper(c, `{
755 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
756 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
759 "mounts": {"/tmp": {"kind": "tmp"} },
760 "output_path": "/tmp",
762 "runtime_constraints": {}
763 }`, nil, 1, func(t *TestDockerClient) {
764 t.logWriter.Write(dockerLog(1, "hello\n"))
765 t.logWriter.Write(dockerLog(2, "world\n"))
769 final := api.CalledWith("container.state", "Complete")
770 c.Assert(final, NotNil)
771 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
772 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
774 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
775 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
778 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
779 api, _, _ := FullRunHelper(c, `{
781 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
784 "mounts": {"/tmp": {"kind": "tmp"} },
785 "output_path": "/tmp",
787 "runtime_constraints": {}
788 }`, nil, 0, func(t *TestDockerClient) {
789 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
793 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
794 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
795 c.Log(api.Logs["stdout"])
796 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
799 func (s *TestSuite) TestFullRunSetCwd(c *C) {
800 api, _, _ := FullRunHelper(c, `{
802 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
805 "mounts": {"/tmp": {"kind": "tmp"} },
806 "output_path": "/tmp",
808 "runtime_constraints": {}
809 }`, nil, 0, func(t *TestDockerClient) {
810 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
814 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
815 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
816 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
819 func (s *TestSuite) TestStopOnSignal(c *C) {
820 s.testStopContainer(c, func(cr *ContainerRunner) {
823 time.Sleep(time.Millisecond)
825 cr.SigChan <- syscall.SIGINT
830 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
831 s.testStopContainer(c, func(cr *ContainerRunner) {
832 cr.ArvMountExit = make(chan error)
834 cr.ArvMountExit <- exec.Command("true").Run()
835 close(cr.ArvMountExit)
840 func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
842 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
843 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
846 "mounts": {"/tmp": {"kind": "tmp"} },
847 "output_path": "/tmp",
849 "runtime_constraints": {}
852 rec := arvados.Container{}
853 err := json.Unmarshal([]byte(record), &rec)
856 docker := NewTestDockerClient(0)
857 docker.fn = func(t *TestDockerClient) {
859 t.logWriter.Write(dockerLog(1, "foo\n"))
862 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
864 api := &ArvTestClient{Container: rec}
865 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
866 cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
869 done := make(chan error)
874 case <-time.After(20 * time.Second):
875 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
880 for k, v := range api.Logs {
885 c.Check(api.CalledWith("container.log", nil), NotNil)
886 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
887 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "foo\n"), Equals, true)
890 func (s *TestSuite) TestFullRunSetEnv(c *C) {
891 api, _, _ := FullRunHelper(c, `{
892 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
893 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
895 "environment": {"FROBIZ": "bilbo"},
896 "mounts": {"/tmp": {"kind": "tmp"} },
897 "output_path": "/tmp",
899 "runtime_constraints": {}
900 }`, nil, 0, func(t *TestDockerClient) {
901 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
905 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
906 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
907 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
910 type ArvMountCmdLine struct {
915 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
921 func stubCert(temp string) string {
922 path := temp + "/ca-certificates.crt"
923 crt, _ := os.Create(path)
925 arvadosclient.CertFiles = []string{path}
929 func (s *TestSuite) TestSetupMounts(c *C) {
930 api := &ArvTestClient{}
931 kc := &KeepTestClient{}
932 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
933 am := &ArvMountCmdLine{}
934 cr.RunArvMount = am.ArvMountTest
936 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
938 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
940 stubCertPath := stubCert(certTemp)
942 defer os.RemoveAll(realTemp)
943 defer os.RemoveAll(certTemp)
946 cr.MkTempDir = func(_ string, prefix string) (string, error) {
948 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
949 err := os.Mkdir(d, os.ModePerm)
950 if err != nil && strings.Contains(err.Error(), ": file exists") {
951 // Test case must have pre-populated the tempdir
957 checkEmpty := func() {
958 filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
959 c.Check(path, Equals, realTemp)
967 cr.ArvMountPoint = ""
968 cr.Container.Mounts = make(map[string]arvados.Mount)
969 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
970 cr.OutputPath = "/tmp"
972 err := cr.SetupMounts()
974 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
975 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
982 cr.ArvMountPoint = ""
983 cr.Container.Mounts = make(map[string]arvados.Mount)
984 cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"}
985 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
986 cr.OutputPath = "/out"
988 err := cr.SetupMounts()
990 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
991 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/out", realTemp + "/3:/tmp"})
998 cr.ArvMountPoint = ""
999 cr.Container.Mounts = make(map[string]arvados.Mount)
1000 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1001 cr.OutputPath = "/tmp"
1004 cr.Container.RuntimeConstraints.API = &apiflag
1006 err := cr.SetupMounts()
1008 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1009 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
1018 cr.ArvMountPoint = ""
1019 cr.Container.Mounts = map[string]arvados.Mount{
1020 "/keeptmp": {Kind: "collection", Writable: true},
1022 cr.OutputPath = "/keeptmp"
1024 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1026 err := cr.SetupMounts()
1028 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1029 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
1036 cr.ArvMountPoint = ""
1037 cr.Container.Mounts = map[string]arvados.Mount{
1038 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1039 "/keepout": {Kind: "collection", Writable: true},
1041 cr.OutputPath = "/keepout"
1043 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1044 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1046 err := cr.SetupMounts()
1048 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1049 sort.StringSlice(cr.Binds).Sort()
1050 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1051 realTemp + "/keep1/tmp0:/keepout"})
1058 cr.ArvMountPoint = ""
1059 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1060 cr.Container.Mounts = map[string]arvados.Mount{
1061 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1062 "/keepout": {Kind: "collection", Writable: true},
1064 cr.OutputPath = "/keepout"
1066 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1067 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1069 err := cr.SetupMounts()
1071 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1072 sort.StringSlice(cr.Binds).Sort()
1073 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1074 realTemp + "/keep1/tmp0:/keepout"})
1079 for _, test := range []struct {
1083 {in: "foo", out: `"foo"`},
1084 {in: nil, out: `null`},
1085 {in: map[string]int{"foo": 123}, out: `{"foo":123}`},
1088 cr.ArvMountPoint = ""
1089 cr.Container.Mounts = map[string]arvados.Mount{
1090 "/mnt/test.json": {Kind: "json", Content: test.in},
1092 err := cr.SetupMounts()
1094 sort.StringSlice(cr.Binds).Sort()
1095 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
1096 content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
1098 c.Check(content, DeepEquals, []byte(test.out))
1103 // Read-only mount points are allowed underneath output_dir mount point
1106 cr.ArvMountPoint = ""
1107 cr.Container.Mounts = make(map[string]arvados.Mount)
1108 cr.Container.Mounts = map[string]arvados.Mount{
1109 "/tmp": {Kind: "tmp"},
1110 "/tmp/foo": {Kind: "collection"},
1112 cr.OutputPath = "/tmp"
1114 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1116 err := cr.SetupMounts()
1118 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other", "--read-write", "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1119 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
1124 // Writable mount points are not allowed underneath output_dir mount point
1127 cr.ArvMountPoint = ""
1128 cr.Container.Mounts = make(map[string]arvados.Mount)
1129 cr.Container.Mounts = map[string]arvados.Mount{
1130 "/tmp": {Kind: "tmp"},
1131 "/tmp/foo": {Kind: "collection", Writable: true},
1133 cr.OutputPath = "/tmp"
1135 err := cr.SetupMounts()
1136 c.Check(err, NotNil)
1137 c.Check(err, ErrorMatches, `Writable mount points are not permitted underneath the output_path.*`)
1142 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1145 cr.ArvMountPoint = ""
1146 cr.Container.Mounts = make(map[string]arvados.Mount)
1147 cr.Container.Mounts = map[string]arvados.Mount{
1148 "/tmp": {Kind: "tmp"},
1149 "/tmp/foo": {Kind: "json"},
1151 cr.OutputPath = "/tmp"
1153 err := cr.SetupMounts()
1154 c.Check(err, NotNil)
1155 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1160 // Only mount point of kind 'collection' is allowed for stdin
1163 cr.ArvMountPoint = ""
1164 cr.Container.Mounts = make(map[string]arvados.Mount)
1165 cr.Container.Mounts = map[string]arvados.Mount{
1166 "stdin": {Kind: "tmp"},
1169 err := cr.SetupMounts()
1170 c.Check(err, NotNil)
1171 c.Check(err, ErrorMatches, `Unsupported mount kind 'tmp' for stdin.*`)
1177 func (s *TestSuite) TestStdout(c *C) {
1179 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1180 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1182 "environment": {"FROBIZ": "bilbo"},
1183 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1184 "output_path": "/tmp",
1186 "runtime_constraints": {}
1189 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1190 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1194 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1195 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1196 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1199 // Used by the TestStdoutWithWrongPath*()
1200 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1201 rec := arvados.Container{}
1202 err = json.Unmarshal([]byte(record), &rec)
1205 docker := NewTestDockerClient(0)
1207 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1209 api = &ArvTestClient{Container: rec}
1210 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1211 am := &ArvMountCmdLine{}
1212 cr.RunArvMount = am.ArvMountTest
1218 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1219 _, _, err := StdoutErrorRunHelper(c, `{
1220 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1221 "output_path": "/tmp"
1222 }`, func(t *TestDockerClient) {})
1224 c.Check(err, NotNil)
1225 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1228 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1229 _, _, err := StdoutErrorRunHelper(c, `{
1230 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1231 "output_path": "/tmp"
1232 }`, func(t *TestDockerClient) {})
1234 c.Check(err, NotNil)
1235 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1238 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1239 _, _, err := StdoutErrorRunHelper(c, `{
1240 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1241 "output_path": "/tmp"
1242 }`, func(t *TestDockerClient) {})
1244 c.Check(err, NotNil)
1245 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1248 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1249 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1250 defer os.Unsetenv("ARVADOS_API_HOST")
1251 api, _, _ := FullRunHelper(c, `{
1252 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1253 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1256 "mounts": {"/tmp": {"kind": "tmp"} },
1257 "output_path": "/tmp",
1259 "runtime_constraints": {"API": true}
1260 }`, nil, 0, func(t *TestDockerClient) {
1261 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1265 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1266 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1267 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1268 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1271 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1272 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1273 defer os.Unsetenv("ARVADOS_API_HOST")
1274 api, _, _ := FullRunHelper(c, `{
1275 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1276 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1279 "mounts": {"/tmp": {"kind": "tmp"} },
1280 "output_path": "/tmp",
1282 "runtime_constraints": {"API": true}
1283 }`, nil, 0, func(t *TestDockerClient) {
1284 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1288 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1289 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1290 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1293 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1295 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1296 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1298 "environment": {"FROBIZ": "bilbo"},
1300 "/tmp": {"kind": "tmp"},
1301 "/tmp/foo": {"kind": "collection",
1302 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1303 "exclude_from_output": true
1305 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1307 "output_path": "/tmp",
1309 "runtime_constraints": {}
1312 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1314 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1315 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1319 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1320 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1321 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1324 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1326 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1327 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1329 "environment": {"FROBIZ": "bilbo"},
1331 "/tmp": {"kind": "tmp"},
1332 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1333 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1334 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1335 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1336 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1338 "output_path": "/tmp",
1340 "runtime_constraints": {}
1343 extraMounts := []string{
1344 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1345 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1346 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1349 api, runner, realtemp := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1350 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1354 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/2:/tmp",
1355 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1356 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1357 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1358 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1361 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1362 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1363 for _, v := range api.Content {
1364 if v["collection"] != nil {
1365 c.Check(v["ensure_unique_name"], Equals, true)
1366 collection := v["collection"].(arvadosclient.Dict)
1367 if strings.Index(collection["name"].(string), "output") == 0 {
1368 manifest := collection["manifest_text"].(string)
1370 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1371 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar 9:18:sub1file2
1372 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1373 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1374 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1381 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1383 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1384 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1386 "environment": {"FROBIZ": "bilbo"},
1388 "/tmp": {"kind": "tmp"},
1389 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1390 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1392 "output_path": "/tmp",
1394 "runtime_constraints": {}
1397 extraMounts := []string{
1398 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1401 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1402 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1406 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1407 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1408 for _, v := range api.Content {
1409 if v["collection"] != nil {
1410 collection := v["collection"].(arvadosclient.Dict)
1411 if strings.Index(collection["name"].(string), "output") == 0 {
1412 manifest := collection["manifest_text"].(string)
1414 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1415 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1422 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1424 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1425 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1427 "environment": {"FROBIZ": "bilbo"},
1429 "/tmp": {"kind": "tmp"},
1430 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1431 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1433 "output_path": "/tmp",
1435 "runtime_constraints": {}
1438 extraMounts := []string{
1439 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1442 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1443 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1447 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1448 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1449 for _, v := range api.Content {
1450 if v["collection"] != nil {
1451 collection := v["collection"].(arvadosclient.Dict)
1452 if strings.Index(collection["name"].(string), "output") == 0 {
1453 manifest := collection["manifest_text"].(string)
1454 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1461 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1463 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1464 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1466 "environment": {"FROBIZ": "bilbo"},
1468 "/tmp": {"kind": "tmp"},
1469 "stdin": {"kind": "json", "content": "foo"},
1470 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1472 "output_path": "/tmp",
1474 "runtime_constraints": {}
1477 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1478 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1482 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1483 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1484 for _, v := range api.Content {
1485 if v["collection"] != nil {
1486 collection := v["collection"].(arvadosclient.Dict)
1487 if strings.Index(collection["name"].(string), "output") == 0 {
1488 manifest := collection["manifest_text"].(string)
1489 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1496 func (s *TestSuite) TestStderrMount(c *C) {
1497 api, _, _ := FullRunHelper(c, `{
1498 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
1499 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1502 "mounts": {"/tmp": {"kind": "tmp"},
1503 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
1504 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
1505 "output_path": "/tmp",
1507 "runtime_constraints": {}
1508 }`, nil, 1, func(t *TestDockerClient) {
1509 t.logWriter.Write(dockerLog(1, "hello\n"))
1510 t.logWriter.Write(dockerLog(2, "oops\n"))
1514 final := api.CalledWith("container.state", "Complete")
1515 c.Assert(final, NotNil)
1516 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1517 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1519 c.Check(api.CalledWith("collection.manifest_text", "./a b1946ac92492d2347c6235b4d2611184+6 0:6:out.txt\n./b 38af5c54926b620264ab1501150cf189+5 0:5:err.txt\n"), NotNil)