1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
28 "git.curoverse.com/arvados.git/sdk/go/arvados"
29 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
30 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
31 "git.curoverse.com/arvados.git/sdk/go/manifest"
32 "golang.org/x/net/context"
34 dockertypes "github.com/docker/docker/api/types"
35 dockercontainer "github.com/docker/docker/api/types/container"
36 dockernetwork "github.com/docker/docker/api/types/network"
40 // Gocheck boilerplate
41 func TestCrunchExec(t *testing.T) {
45 // Gocheck boilerplate
46 var _ = Suite(&TestSuite{})
48 type TestSuite struct {
49 docker *TestDockerClient
52 func (s *TestSuite) SetUpTest(c *C) {
53 s.docker = NewTestDockerClient()
56 type ArvTestClient struct {
59 Content []arvadosclient.Dict
61 Logs map[string]*bytes.Buffer
67 type KeepTestClient struct {
72 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
73 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
74 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
76 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
77 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
79 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
80 ./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
81 ./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
84 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
86 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"
87 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
89 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
90 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
92 type TestDockerClient struct {
94 logReader io.ReadCloser
95 logWriter io.WriteCloser
96 fn func(t *TestDockerClient)
106 func NewTestDockerClient() *TestDockerClient {
107 t := &TestDockerClient{}
108 t.logReader, t.logWriter = io.Pipe()
109 t.stop = make(chan bool, 1)
114 type MockConn struct {
118 func (m *MockConn) Write(b []byte) (int, error) {
122 func NewMockConn() *MockConn {
127 func (t *TestDockerClient) ContainerAttach(ctx context.Context, container string, options dockertypes.ContainerAttachOptions) (dockertypes.HijackedResponse, error) {
128 return dockertypes.HijackedResponse{Conn: NewMockConn(), Reader: bufio.NewReader(t.logReader)}, nil
131 func (t *TestDockerClient) ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error) {
132 if config.WorkingDir != "" {
133 t.cwd = config.WorkingDir
136 return dockercontainer.ContainerCreateCreatedBody{ID: "abcde"}, nil
139 func (t *TestDockerClient) ContainerStart(ctx context.Context, container string, options dockertypes.ContainerStartOptions) error {
141 return errors.New(`Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "process_linux.go:359: container init caused \"rootfs_linux.go:54: mounting \\\"/tmp/keep453790790/by_id/99999999999999999999999999999999+99999/myGenome\\\" to rootfs \\\"/tmp/docker/overlay2/9999999999999999999999999999999999999999999999999999999999999999/merged\\\" at \\\"/tmp/docker/overlay2/9999999999999999999999999999999999999999999999999999999999999999/merged/keep/99999999999999999999999999999999+99999/myGenome\\\" caused \\\"no such file or directory\\\"\""`)
144 return errors.New(`panic: standard_init_linux.go:175: exec user process caused "no such file or directory"`)
147 return errors.New(`Error response from daemon: Cannot start container 41f26cbc43bcc1280f4323efb1830a394ba8660c9d1c2b564ba42bf7f7694845: [8] System error: no such file or directory`)
150 return errors.New(`Error response from daemon: Cannot start container 58099cd76c834f3dc2a4fb76c8028f049ae6d4fdf0ec373e1f2cfea030670c2d: [8] System error: exec: "foobar": executable file not found in $PATH`)
153 if container == "abcde" {
154 // t.fn gets executed in ContainerWait
157 return errors.New("Invalid container id")
161 func (t *TestDockerClient) ContainerRemove(ctx context.Context, container string, options dockertypes.ContainerRemoveOptions) error {
166 func (t *TestDockerClient) ContainerWait(ctx context.Context, container string, condition dockercontainer.WaitCondition) (<-chan dockercontainer.ContainerWaitOKBody, <-chan error) {
168 body := make(chan dockercontainer.ContainerWaitOKBody, 1)
169 err := make(chan error)
172 body <- dockercontainer.ContainerWaitOKBody{StatusCode: int64(t.exitCode)}
177 func (t *TestDockerClient) ImageInspectWithRaw(ctx context.Context, image string) (dockertypes.ImageInspect, []byte, error) {
179 return dockertypes.ImageInspect{}, nil, fmt.Errorf("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
182 if t.imageLoaded == image {
183 return dockertypes.ImageInspect{}, nil, nil
185 return dockertypes.ImageInspect{}, nil, errors.New("")
189 func (t *TestDockerClient) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (dockertypes.ImageLoadResponse, error) {
191 return dockertypes.ImageLoadResponse{}, fmt.Errorf("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
193 _, err := io.Copy(ioutil.Discard, input)
195 return dockertypes.ImageLoadResponse{}, err
197 t.imageLoaded = hwImageId
198 return dockertypes.ImageLoadResponse{Body: ioutil.NopCloser(input)}, nil
202 func (*TestDockerClient) ImageRemove(ctx context.Context, image string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {
206 func (client *ArvTestClient) Create(resourceType string,
207 parameters arvadosclient.Dict,
208 output interface{}) error {
211 defer client.Mutex.Unlock()
214 client.Content = append(client.Content, parameters)
216 if resourceType == "logs" {
217 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
218 if client.Logs == nil {
219 client.Logs = make(map[string]*bytes.Buffer)
221 if client.Logs[et] == nil {
222 client.Logs[et] = &bytes.Buffer{}
224 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
227 if resourceType == "collections" && output != nil {
228 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
229 outmap := output.(*arvados.Collection)
230 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
236 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
238 case method == "GET" && resourceType == "containers" && action == "auth":
239 return json.Unmarshal([]byte(`{
240 "kind": "arvados#api_client_authorization",
241 "uuid": "`+fakeAuthUUID+`",
242 "api_token": "`+fakeAuthToken+`"
245 return fmt.Errorf("Not found")
249 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
250 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
252 if method == "GET" && resourceType == "nodes" && uuid == "" && action == "" {
254 "kind": "arvados#nodeList",
256 "uuid": "zzzzz-7ekkf-2z3mc76g2q73aio",
257 "hostname": "compute2",
258 "properties": {"total_cpu_cores": 16}
260 } else if method == "GET" && resourceType == "containers" && action == "" && !client.callraw {
262 j, err = json.Marshal(map[string]interface{}{
263 "items": []interface{}{client.Container},
264 "kind": "arvados#nodeList",
267 j, err = json.Marshal(client.Container)
271 "command": ["sleep", "1"],
272 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
275 "mounts": {"/tmp": {"kind": "tmp"}, "/json": {"kind": "json", "content": {"number": 123456789123456789}}},
276 "output_path": "/tmp",
278 "runtime_constraints": {}
281 return ioutil.NopCloser(bytes.NewReader(j)), err
284 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
285 if resourceType == "collections" {
287 output.(*arvados.Collection).ManifestText = hwManifest
288 } else if uuid == otherPDH {
289 output.(*arvados.Collection).ManifestText = otherManifest
290 } else if uuid == normalizedWithSubdirsPDH {
291 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
292 } else if uuid == denormalizedWithSubdirsPDH {
293 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
296 if resourceType == "containers" {
297 (*output.(*arvados.Container)) = client.Container
302 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
304 defer client.Mutex.Unlock()
306 client.Content = append(client.Content, parameters)
307 if resourceType == "containers" {
308 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
309 client.WasSetRunning = true
315 var discoveryMap = map[string]interface{}{
316 "defaultTrashLifetime": float64(1209600),
317 "crunchLimitLogBytesPerJob": float64(67108864),
318 "crunchLogThrottleBytes": float64(65536),
319 "crunchLogThrottlePeriod": float64(60),
320 "crunchLogThrottleLines": float64(1024),
321 "crunchLogPartialLineThrottlePeriod": float64(5),
322 "crunchLogBytesPerEvent": float64(4096),
323 "crunchLogSecondsBetweenEvents": float64(1),
326 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
327 return discoveryMap[key], nil
330 // CalledWith returns the parameters from the first API call whose
331 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
332 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
333 // no call matches, it returns nil.
334 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
336 for _, content := range client.Content {
337 var v interface{} = content
338 for _, k := range strings.Split(jpath, ".") {
339 if dict, ok := v.(arvadosclient.Dict); !ok {
352 func (client *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
354 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
357 func (*KeepTestClient) ClearBlockCache() {
360 type FileWrapper struct {
365 func (fw FileWrapper) Readdir(n int) ([]os.FileInfo, error) {
366 return nil, errors.New("not implemented")
369 func (fw FileWrapper) Seek(int64, int) (int64, error) {
370 return 0, errors.New("not implemented")
373 func (fw FileWrapper) Size() int64 {
377 func (fw FileWrapper) Stat() (os.FileInfo, error) {
378 return nil, errors.New("not implemented")
381 func (fw FileWrapper) Truncate(int64) error {
382 return errors.New("not implemented")
385 func (fw FileWrapper) Write([]byte) (int, error) {
386 return 0, errors.New("not implemented")
389 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
390 if filename == hwImageId+".tar" {
391 rdr := ioutil.NopCloser(&bytes.Buffer{})
393 return FileWrapper{rdr, 1321984}, nil
394 } else if filename == "/file1_in_main.txt" {
395 rdr := ioutil.NopCloser(strings.NewReader("foo"))
397 return FileWrapper{rdr, 3}, nil
402 func (s *TestSuite) TestLoadImage(c *C) {
403 kc := &KeepTestClient{}
404 cr := NewContainerRunner(&ArvTestClient{}, kc, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
406 _, err := cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
408 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
411 cr.Container.ContainerImage = hwPDH
413 // (1) Test loading image from keep
414 c.Check(kc.Called, Equals, false)
415 c.Check(cr.ContainerConfig.Image, Equals, "")
421 cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
424 c.Check(kc.Called, Equals, true)
425 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
427 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
430 // (2) Test using image that's already loaded
432 cr.ContainerConfig.Image = ""
436 c.Check(kc.Called, Equals, false)
437 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
441 type ArvErrorTestClient struct{}
443 func (ArvErrorTestClient) Create(resourceType string,
444 parameters arvadosclient.Dict,
445 output interface{}) error {
449 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
450 return errors.New("ArvError")
453 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
454 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
455 return nil, errors.New("ArvError")
458 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
459 return errors.New("ArvError")
462 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
466 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
467 return discoveryMap[key], nil
470 type KeepErrorTestClient struct{}
472 func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
473 return "", 0, errors.New("KeepError")
476 func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
477 return nil, errors.New("KeepError")
480 func (KeepErrorTestClient) ClearBlockCache() {
483 type KeepReadErrorTestClient struct{}
485 func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
489 func (KeepReadErrorTestClient) ClearBlockCache() {
492 type ErrorReader struct {
496 func (ErrorReader) Read(p []byte) (n int, err error) {
497 return 0, errors.New("ErrorReader")
500 func (ErrorReader) Seek(int64, int) (int64, error) {
501 return 0, errors.New("ErrorReader")
504 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
505 return ErrorReader{}, nil
508 func (s *TestSuite) TestLoadImageArvError(c *C) {
510 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
511 cr.Container.ContainerImage = hwPDH
513 err := cr.LoadImage()
514 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
517 func (s *TestSuite) TestLoadImageKeepError(c *C) {
519 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
520 cr.Container.ContainerImage = hwPDH
522 err := cr.LoadImage()
523 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
526 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
527 // (3) Collection doesn't contain image
528 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
529 cr.Container.ContainerImage = otherPDH
531 err := cr.LoadImage()
532 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
535 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
536 // (4) Collection doesn't contain image
537 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
538 cr.Container.ContainerImage = hwPDH
540 err := cr.LoadImage()
544 type ClosableBuffer struct {
548 func (*ClosableBuffer) Close() error {
552 type TestLogs struct {
553 Stdout ClosableBuffer
554 Stderr ClosableBuffer
557 func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
558 if logstr == "stdout" {
561 if logstr == "stderr" {
567 func dockerLog(fd byte, msg string) []byte {
569 header := make([]byte, 8+len(by))
571 header[7] = byte(len(by))
576 func (s *TestSuite) TestRunContainer(c *C) {
577 s.docker.fn = func(t *TestDockerClient) {
578 t.logWriter.Write(dockerLog(1, "Hello world\n"))
581 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
584 cr.NewLogWriter = logs.NewTestLoggingWriter
585 cr.Container.ContainerImage = hwPDH
586 cr.Container.Command = []string{"./hw"}
587 err := cr.LoadImage()
590 err = cr.CreateContainer()
593 err = cr.StartContainer()
596 err = cr.WaitFinish()
599 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
600 c.Check(logs.Stderr.String(), Equals, "")
603 func (s *TestSuite) TestCommitLogs(c *C) {
604 api := &ArvTestClient{}
605 kc := &KeepTestClient{}
606 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
607 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
609 cr.CrunchLog.Print("Hello world!")
610 cr.CrunchLog.Print("Goodbye")
611 cr.finalState = "Complete"
613 err := cr.CommitLogs()
616 c.Check(api.Calls, Equals, 2)
617 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
618 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
619 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
620 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
623 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
624 api := &ArvTestClient{}
625 kc := &KeepTestClient{}
626 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
628 err := cr.UpdateContainerRunning()
631 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
634 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
635 api := &ArvTestClient{}
636 kc := &KeepTestClient{}
637 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
639 cr.LogsPDH = new(string)
640 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
642 cr.ExitCode = new(int)
644 cr.finalState = "Complete"
646 err := cr.UpdateContainerFinal()
649 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
650 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
651 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
654 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
655 api := &ArvTestClient{}
656 kc := &KeepTestClient{}
657 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
659 cr.finalState = "Cancelled"
661 err := cr.UpdateContainerFinal()
664 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
665 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
666 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
669 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
670 // dress rehearsal of the Run() function, starting from a JSON container record.
671 func (s *TestSuite) fullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, realTemp string) {
672 rec := arvados.Container{}
673 err := json.Unmarshal([]byte(record), &rec)
676 s.docker.exitCode = exitCode
678 s.docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
680 api = &ArvTestClient{Container: rec}
682 cr = NewContainerRunner(api, &KeepTestClient{}, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
683 cr.statInterval = 100 * time.Millisecond
684 am := &ArvMountCmdLine{}
685 cr.RunArvMount = am.ArvMountTest
687 realTemp, err = ioutil.TempDir("", "crunchrun_test1-")
689 defer os.RemoveAll(realTemp)
691 s.docker.realTemp = realTemp
694 cr.MkTempDir = func(_ string, prefix string) (string, error) {
696 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
697 err := os.Mkdir(d, os.ModePerm)
698 if err != nil && strings.Contains(err.Error(), ": file exists") {
699 // Test case must have pre-populated the tempdir
705 if extraMounts != nil && len(extraMounts) > 0 {
706 err := cr.SetupArvMountPoint("keep")
709 for _, m := range extraMounts {
710 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
715 if api.CalledWith("container.state", "Complete") != nil {
719 c.Check(api.WasSetRunning, Equals, true)
720 c.Check(api.Content[api.Calls-2]["container"].(arvadosclient.Dict)["log"], NotNil)
724 for k, v := range api.Logs {
733 func (s *TestSuite) TestFullRunHello(c *C) {
734 api, _, _ := s.fullRunHelper(c, `{
735 "command": ["echo", "hello world"],
736 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
739 "mounts": {"/tmp": {"kind": "tmp"} },
740 "output_path": "/tmp",
742 "runtime_constraints": {}
743 }`, nil, 0, func(t *TestDockerClient) {
744 t.logWriter.Write(dockerLog(1, "hello world\n"))
748 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
749 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
750 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
754 func (s *TestSuite) TestCrunchstat(c *C) {
755 api, _, _ := s.fullRunHelper(c, `{
756 "command": ["sleep", "1"],
757 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
760 "mounts": {"/tmp": {"kind": "tmp"} },
761 "output_path": "/tmp",
763 "runtime_constraints": {}
764 }`, nil, 0, func(t *TestDockerClient) {
765 time.Sleep(time.Second)
769 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
770 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
772 // We didn't actually start a container, so crunchstat didn't
773 // find accounting files and therefore didn't log any stats.
774 // It should have logged a "can't find accounting files"
775 // message after one poll interval, though, so we can confirm
777 c.Assert(api.Logs["crunchstat"], NotNil)
778 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
780 // The "files never appeared" log assures us that we called
781 // (*crunchstat.Reporter)Stop(), and that we set it up with
782 // the correct container ID "abcde":
783 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
786 func (s *TestSuite) TestNodeInfoLog(c *C) {
787 os.Setenv("SLURMD_NODENAME", "compute2")
788 api, _, _ := s.fullRunHelper(c, `{
789 "command": ["sleep", "1"],
790 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
793 "mounts": {"/tmp": {"kind": "tmp"} },
794 "output_path": "/tmp",
796 "runtime_constraints": {}
798 func(t *TestDockerClient) {
799 time.Sleep(time.Second)
803 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
804 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
806 c.Assert(api.Logs["node"], NotNil)
807 json := api.Logs["node"].String()
808 c.Check(json, Matches, `(?ms).*"uuid": *"zzzzz-7ekkf-2z3mc76g2q73aio".*`)
809 c.Check(json, Matches, `(?ms).*"total_cpu_cores": *16.*`)
810 c.Check(json, Not(Matches), `(?ms).*"info":.*`)
812 c.Assert(api.Logs["node-info"], NotNil)
813 json = api.Logs["node-info"].String()
814 c.Check(json, Matches, `(?ms).*Host Information.*`)
815 c.Check(json, Matches, `(?ms).*CPU Information.*`)
816 c.Check(json, Matches, `(?ms).*Memory Information.*`)
817 c.Check(json, Matches, `(?ms).*Disk Space.*`)
818 c.Check(json, Matches, `(?ms).*Disk INodes.*`)
821 func (s *TestSuite) TestContainerRecordLog(c *C) {
822 api, _, _ := s.fullRunHelper(c, `{
823 "command": ["sleep", "1"],
824 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
827 "mounts": {"/tmp": {"kind": "tmp"} },
828 "output_path": "/tmp",
830 "runtime_constraints": {}
832 func(t *TestDockerClient) {
833 time.Sleep(time.Second)
837 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
838 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
840 c.Assert(api.Logs["container"], NotNil)
841 c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
844 func (s *TestSuite) TestFullRunStderr(c *C) {
845 api, _, _ := s.fullRunHelper(c, `{
846 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
847 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
850 "mounts": {"/tmp": {"kind": "tmp"} },
851 "output_path": "/tmp",
853 "runtime_constraints": {}
854 }`, nil, 1, func(t *TestDockerClient) {
855 t.logWriter.Write(dockerLog(1, "hello\n"))
856 t.logWriter.Write(dockerLog(2, "world\n"))
860 final := api.CalledWith("container.state", "Complete")
861 c.Assert(final, NotNil)
862 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
863 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
865 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
866 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
869 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
870 api, _, _ := s.fullRunHelper(c, `{
872 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
875 "mounts": {"/tmp": {"kind": "tmp"} },
876 "output_path": "/tmp",
878 "runtime_constraints": {}
879 }`, nil, 0, func(t *TestDockerClient) {
880 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
884 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
885 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
886 c.Log(api.Logs["stdout"])
887 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
890 func (s *TestSuite) TestFullRunSetCwd(c *C) {
891 api, _, _ := s.fullRunHelper(c, `{
893 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
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.cwd+"\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(), "/bin\n"), Equals, true)
910 func (s *TestSuite) TestStopOnSignal(c *C) {
911 s.testStopContainer(c, func(cr *ContainerRunner) {
913 for !s.docker.calledWait {
914 time.Sleep(time.Millisecond)
916 cr.SigChan <- syscall.SIGINT
921 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
922 s.testStopContainer(c, func(cr *ContainerRunner) {
923 cr.ArvMountExit = make(chan error)
925 cr.ArvMountExit <- exec.Command("true").Run()
926 close(cr.ArvMountExit)
931 func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
933 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
934 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
937 "mounts": {"/tmp": {"kind": "tmp"} },
938 "output_path": "/tmp",
940 "runtime_constraints": {}
943 rec := arvados.Container{}
944 err := json.Unmarshal([]byte(record), &rec)
947 s.docker.fn = func(t *TestDockerClient) {
949 t.logWriter.Write(dockerLog(1, "foo\n"))
952 s.docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
954 api := &ArvTestClient{Container: rec}
955 cr := NewContainerRunner(api, &KeepTestClient{}, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
956 cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
959 done := make(chan error)
964 case <-time.After(20 * time.Second):
965 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
970 for k, v := range api.Logs {
975 c.Check(api.CalledWith("container.log", nil), NotNil)
976 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
977 c.Check(api.Logs["stdout"].String(), Matches, "(?ms).*foo\n$")
980 func (s *TestSuite) TestFullRunSetEnv(c *C) {
981 api, _, _ := s.fullRunHelper(c, `{
982 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
983 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
985 "environment": {"FROBIZ": "bilbo"},
986 "mounts": {"/tmp": {"kind": "tmp"} },
987 "output_path": "/tmp",
989 "runtime_constraints": {}
990 }`, nil, 0, func(t *TestDockerClient) {
991 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
995 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
996 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
997 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
1000 type ArvMountCmdLine struct {
1005 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
1011 func stubCert(temp string) string {
1012 path := temp + "/ca-certificates.crt"
1013 crt, _ := os.Create(path)
1015 arvadosclient.CertFiles = []string{path}
1019 func (s *TestSuite) TestSetupMounts(c *C) {
1020 api := &ArvTestClient{}
1021 kc := &KeepTestClient{}
1022 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1023 am := &ArvMountCmdLine{}
1024 cr.RunArvMount = am.ArvMountTest
1026 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
1027 c.Assert(err, IsNil)
1028 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
1029 c.Assert(err, IsNil)
1030 stubCertPath := stubCert(certTemp)
1032 defer os.RemoveAll(realTemp)
1033 defer os.RemoveAll(certTemp)
1036 cr.MkTempDir = func(_ string, prefix string) (string, error) {
1038 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
1039 err := os.Mkdir(d, os.ModePerm)
1040 if err != nil && strings.Contains(err.Error(), ": file exists") {
1041 // Test case must have pre-populated the tempdir
1047 checkEmpty := func() {
1048 filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
1049 c.Check(path, Equals, realTemp)
1057 cr.ArvMountPoint = ""
1058 cr.Container.Mounts = make(map[string]arvados.Mount)
1059 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1060 cr.OutputPath = "/tmp"
1061 cr.statInterval = 5 * time.Second
1062 err := cr.SetupMounts()
1064 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1065 "--read-write", "--crunchstat-interval=5",
1066 "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1067 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
1068 os.RemoveAll(cr.ArvMountPoint)
1075 cr.ArvMountPoint = ""
1076 cr.Container.Mounts = make(map[string]arvados.Mount)
1077 cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"}
1078 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1079 cr.OutputPath = "/out"
1081 err := cr.SetupMounts()
1083 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1084 "--read-write", "--crunchstat-interval=5",
1085 "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1086 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/out", realTemp + "/3:/tmp"})
1087 os.RemoveAll(cr.ArvMountPoint)
1094 cr.ArvMountPoint = ""
1095 cr.Container.Mounts = make(map[string]arvados.Mount)
1096 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1097 cr.OutputPath = "/tmp"
1100 cr.Container.RuntimeConstraints.API = &apiflag
1102 err := cr.SetupMounts()
1104 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1105 "--read-write", "--crunchstat-interval=5",
1106 "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1107 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
1108 os.RemoveAll(cr.ArvMountPoint)
1117 cr.ArvMountPoint = ""
1118 cr.Container.Mounts = map[string]arvados.Mount{
1119 "/keeptmp": {Kind: "collection", Writable: true},
1121 cr.OutputPath = "/keeptmp"
1123 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1125 err := cr.SetupMounts()
1127 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1128 "--read-write", "--crunchstat-interval=5",
1129 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1130 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
1131 os.RemoveAll(cr.ArvMountPoint)
1138 cr.ArvMountPoint = ""
1139 cr.Container.Mounts = map[string]arvados.Mount{
1140 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1141 "/keepout": {Kind: "collection", Writable: true},
1143 cr.OutputPath = "/keepout"
1145 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1146 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1148 err := cr.SetupMounts()
1150 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1151 "--read-write", "--crunchstat-interval=5",
1152 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1153 sort.StringSlice(cr.Binds).Sort()
1154 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1155 realTemp + "/keep1/tmp0:/keepout"})
1156 os.RemoveAll(cr.ArvMountPoint)
1163 cr.ArvMountPoint = ""
1164 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1165 cr.Container.Mounts = map[string]arvados.Mount{
1166 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1167 "/keepout": {Kind: "collection", Writable: true},
1169 cr.OutputPath = "/keepout"
1171 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1172 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1174 err := cr.SetupMounts()
1176 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1177 "--read-write", "--crunchstat-interval=5",
1178 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1179 sort.StringSlice(cr.Binds).Sort()
1180 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1181 realTemp + "/keep1/tmp0:/keepout"})
1182 os.RemoveAll(cr.ArvMountPoint)
1187 for _, test := range []struct {
1191 {in: "foo", out: `"foo"`},
1192 {in: nil, out: `null`},
1193 {in: map[string]int64{"foo": 123456789123456789}, out: `{"foo":123456789123456789}`},
1196 cr.ArvMountPoint = ""
1197 cr.Container.Mounts = map[string]arvados.Mount{
1198 "/mnt/test.json": {Kind: "json", Content: test.in},
1200 err := cr.SetupMounts()
1202 sort.StringSlice(cr.Binds).Sort()
1203 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
1204 content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
1206 c.Check(content, DeepEquals, []byte(test.out))
1207 os.RemoveAll(cr.ArvMountPoint)
1212 // Read-only mount points are allowed underneath output_dir mount point
1215 cr.ArvMountPoint = ""
1216 cr.Container.Mounts = make(map[string]arvados.Mount)
1217 cr.Container.Mounts = map[string]arvados.Mount{
1218 "/tmp": {Kind: "tmp"},
1219 "/tmp/foo": {Kind: "collection"},
1221 cr.OutputPath = "/tmp"
1223 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1225 err := cr.SetupMounts()
1227 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1228 "--read-write", "--crunchstat-interval=5",
1229 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1230 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
1231 os.RemoveAll(cr.ArvMountPoint)
1236 // Writable mount points copied to output_dir mount point
1239 cr.ArvMountPoint = ""
1240 cr.Container.Mounts = make(map[string]arvados.Mount)
1241 cr.Container.Mounts = map[string]arvados.Mount{
1242 "/tmp": {Kind: "tmp"},
1243 "/tmp/foo": {Kind: "collection",
1244 PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53",
1246 "/tmp/bar": {Kind: "collection",
1247 PortableDataHash: "59389a8f9ee9d399be35462a0f92541d+53",
1251 cr.OutputPath = "/tmp"
1253 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1254 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz", os.ModePerm)
1256 rf, _ := os.Create(realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz/quux")
1257 rf.Write([]byte("bar"))
1260 err := cr.SetupMounts()
1262 _, err = os.Stat(cr.HostOutputDir + "/foo")
1264 _, err = os.Stat(cr.HostOutputDir + "/bar/quux")
1266 os.RemoveAll(cr.ArvMountPoint)
1271 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1274 cr.ArvMountPoint = ""
1275 cr.Container.Mounts = make(map[string]arvados.Mount)
1276 cr.Container.Mounts = map[string]arvados.Mount{
1277 "/tmp": {Kind: "tmp"},
1278 "/tmp/foo": {Kind: "json"},
1280 cr.OutputPath = "/tmp"
1282 err := cr.SetupMounts()
1283 c.Check(err, NotNil)
1284 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1285 os.RemoveAll(cr.ArvMountPoint)
1290 // Only mount point of kind 'collection' is allowed for stdin
1293 cr.ArvMountPoint = ""
1294 cr.Container.Mounts = make(map[string]arvados.Mount)
1295 cr.Container.Mounts = map[string]arvados.Mount{
1296 "stdin": {Kind: "tmp"},
1299 err := cr.SetupMounts()
1300 c.Check(err, NotNil)
1301 c.Check(err, ErrorMatches, `Unsupported mount kind 'tmp' for stdin.*`)
1302 os.RemoveAll(cr.ArvMountPoint)
1310 cr.ArvMountPoint = ""
1311 (*GitMountSuite)(nil).useTestGitServer(c)
1312 cr.token = arvadostest.ActiveToken
1313 cr.Container.Mounts = make(map[string]arvados.Mount)
1314 cr.Container.Mounts = map[string]arvados.Mount{
1317 UUID: arvadostest.Repository2UUID,
1318 Commit: "fd3531f42995344f36c30b79f55f27b502f3d344",
1323 UUID: arvadostest.Repository2UUID,
1324 Commit: "5ebfab0522851df01fec11ec55a6d0f4877b542e",
1328 cr.OutputPath = "/tmp"
1330 err := cr.SetupMounts()
1333 // dirMap[mountpoint] == tmpdir
1334 dirMap := make(map[string]string)
1335 for _, bind := range cr.Binds {
1336 tokens := strings.Split(bind, ":")
1337 dirMap[tokens[1]] = tokens[0]
1339 if cr.Container.Mounts[tokens[1]].Writable {
1340 c.Check(len(tokens), Equals, 2)
1342 c.Check(len(tokens), Equals, 3)
1343 c.Check(tokens[2], Equals, "ro")
1347 data, err := ioutil.ReadFile(dirMap["/tip"] + "/dir1/dir2/file with mode 0644")
1349 c.Check(string(data), Equals, "\000\001\002\003")
1350 _, err = ioutil.ReadFile(dirMap["/tip"] + "/file only on testbranch")
1351 c.Check(err, FitsTypeOf, &os.PathError{})
1352 c.Check(os.IsNotExist(err), Equals, true)
1354 data, err = ioutil.ReadFile(dirMap["/non-tip"] + "/dir1/dir2/file with mode 0644")
1356 c.Check(string(data), Equals, "\000\001\002\003")
1357 data, err = ioutil.ReadFile(dirMap["/non-tip"] + "/file only on testbranch")
1359 c.Check(string(data), Equals, "testfile\n")
1366 func (s *TestSuite) TestStdout(c *C) {
1368 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1369 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1371 "environment": {"FROBIZ": "bilbo"},
1372 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1373 "output_path": "/tmp",
1375 "runtime_constraints": {}
1378 api, _, _ := s.fullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1379 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1383 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1384 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1385 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1388 // Used by the TestStdoutWithWrongPath*()
1389 func (s *TestSuite) stdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1390 rec := arvados.Container{}
1391 err = json.Unmarshal([]byte(record), &rec)
1395 s.docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1397 api = &ArvTestClient{Container: rec}
1398 cr = NewContainerRunner(api, &KeepTestClient{}, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1399 am := &ArvMountCmdLine{}
1400 cr.RunArvMount = am.ArvMountTest
1406 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1407 _, _, err := s.stdoutErrorRunHelper(c, `{
1408 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1409 "output_path": "/tmp"
1410 }`, func(t *TestDockerClient) {})
1412 c.Check(err, NotNil)
1413 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1416 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1417 _, _, err := s.stdoutErrorRunHelper(c, `{
1418 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1419 "output_path": "/tmp"
1420 }`, func(t *TestDockerClient) {})
1422 c.Check(err, NotNil)
1423 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1426 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1427 _, _, err := s.stdoutErrorRunHelper(c, `{
1428 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1429 "output_path": "/tmp"
1430 }`, func(t *TestDockerClient) {})
1432 c.Check(err, NotNil)
1433 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1436 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1437 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1438 defer os.Unsetenv("ARVADOS_API_HOST")
1439 api, _, _ := s.fullRunHelper(c, `{
1440 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1441 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1444 "mounts": {"/tmp": {"kind": "tmp"} },
1445 "output_path": "/tmp",
1447 "runtime_constraints": {"API": true}
1448 }`, nil, 0, func(t *TestDockerClient) {
1449 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1453 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1454 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1455 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1456 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1459 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1460 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1461 defer os.Unsetenv("ARVADOS_API_HOST")
1462 api, _, _ := s.fullRunHelper(c, `{
1463 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1464 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1467 "mounts": {"/tmp": {"kind": "tmp"} },
1468 "output_path": "/tmp",
1470 "runtime_constraints": {"API": true}
1471 }`, nil, 0, func(t *TestDockerClient) {
1472 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1476 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1477 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1478 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1481 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1483 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1484 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1486 "environment": {"FROBIZ": "bilbo"},
1488 "/tmp": {"kind": "tmp"},
1489 "/tmp/foo": {"kind": "collection",
1490 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1491 "exclude_from_output": true
1493 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1495 "output_path": "/tmp",
1497 "runtime_constraints": {}
1500 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1502 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1503 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1507 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1508 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1509 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1512 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1514 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1515 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1517 "environment": {"FROBIZ": "bilbo"},
1519 "/tmp": {"kind": "tmp"},
1520 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1521 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1522 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1523 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1524 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1526 "output_path": "/tmp",
1528 "runtime_constraints": {}
1531 extraMounts := []string{
1532 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1533 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1534 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1537 api, runner, realtemp := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1538 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1542 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/2:/tmp",
1543 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1544 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1545 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1546 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1549 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1550 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1551 for _, v := range api.Content {
1552 if v["collection"] != nil {
1553 c.Check(v["ensure_unique_name"], Equals, true)
1554 collection := v["collection"].(arvadosclient.Dict)
1555 if strings.Index(collection["name"].(string), "output") == 0 {
1556 manifest := collection["manifest_text"].(string)
1558 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1559 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar 9:18:sub1file2
1560 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1561 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1562 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1569 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1571 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1572 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1574 "environment": {"FROBIZ": "bilbo"},
1576 "/tmp": {"kind": "tmp"},
1577 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1578 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1580 "output_path": "/tmp",
1582 "runtime_constraints": {}
1585 extraMounts := []string{
1586 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1589 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1590 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1594 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1595 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1596 for _, v := range api.Content {
1597 if v["collection"] != nil {
1598 collection := v["collection"].(arvadosclient.Dict)
1599 if strings.Index(collection["name"].(string), "output") == 0 {
1600 manifest := collection["manifest_text"].(string)
1602 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1603 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1610 func (s *TestSuite) TestOutputSymlinkToInput(c *C) {
1612 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1613 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1615 "environment": {"FROBIZ": "bilbo"},
1617 "/tmp": {"kind": "tmp"},
1618 "/keep/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path": "/subdir1/file2_in_subdir1.txt"},
1619 "/keep/foo2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367"}
1621 "output_path": "/tmp",
1623 "runtime_constraints": {}
1626 extraMounts := []string{
1627 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1630 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1631 os.Symlink("/keep/foo/sub1file2", t.realTemp+"/2/baz")
1632 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz2")
1633 os.Symlink("/keep/foo2/subdir1", t.realTemp+"/2/baz3")
1634 os.Mkdir(t.realTemp+"/2/baz4", 0700)
1635 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz4/baz5")
1639 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1640 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1641 for _, v := range api.Content {
1642 if v["collection"] != nil {
1643 collection := v["collection"].(arvadosclient.Dict)
1644 if strings.Index(collection["name"].(string), "output") == 0 {
1645 manifest := collection["manifest_text"].(string)
1646 c.Check(manifest, Equals, `. 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz 9:18:baz2
1647 ./baz3 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1648 ./baz3/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1649 ./baz4 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz5
1656 func (s *TestSuite) TestOutputError(c *C) {
1658 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1659 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1661 "environment": {"FROBIZ": "bilbo"},
1663 "/tmp": {"kind": "tmp"}
1665 "output_path": "/tmp",
1667 "runtime_constraints": {}
1670 extraMounts := []string{}
1672 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1673 os.Symlink("/etc/hosts", t.realTemp+"/2/baz")
1677 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1680 func (s *TestSuite) TestOutputSymlinkToOutput(c *C) {
1682 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1683 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1685 "environment": {"FROBIZ": "bilbo"},
1687 "/tmp": {"kind": "tmp"}
1689 "output_path": "/tmp",
1691 "runtime_constraints": {}
1694 extraMounts := []string{}
1696 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1697 rf, _ := os.Create(t.realTemp + "/2/realfile")
1698 rf.Write([]byte("foo"))
1701 os.Mkdir(t.realTemp+"/2/realdir", 0700)
1702 rf, _ = os.Create(t.realTemp + "/2/realdir/subfile")
1703 rf.Write([]byte("bar"))
1706 os.Symlink("/tmp/realfile", t.realTemp+"/2/file1")
1707 os.Symlink("realfile", t.realTemp+"/2/file2")
1708 os.Symlink("/tmp/file1", t.realTemp+"/2/file3")
1709 os.Symlink("file2", t.realTemp+"/2/file4")
1710 os.Symlink("realdir", t.realTemp+"/2/dir1")
1711 os.Symlink("/tmp/realdir", t.realTemp+"/2/dir2")
1715 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1716 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1717 for _, v := range api.Content {
1718 if v["collection"] != nil {
1719 collection := v["collection"].(arvadosclient.Dict)
1720 if strings.Index(collection["name"].(string), "output") == 0 {
1721 manifest := collection["manifest_text"].(string)
1722 c.Check(manifest, Equals,
1723 `. 7a2c86e102dcc231bd232aad99686dfa+15 0:3:file1 3:3:file2 6:3:file3 9:3:file4 12:3:realfile
1724 ./dir1 37b51d194a7513e45b56f6524f2d51f2+3 0:3:subfile
1725 ./dir2 37b51d194a7513e45b56f6524f2d51f2+3 0:3:subfile
1726 ./realdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:subfile
1733 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1735 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1736 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1738 "environment": {"FROBIZ": "bilbo"},
1740 "/tmp": {"kind": "tmp"},
1741 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1742 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1744 "output_path": "/tmp",
1746 "runtime_constraints": {}
1749 extraMounts := []string{
1750 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1753 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1754 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1758 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1759 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1760 for _, v := range api.Content {
1761 if v["collection"] != nil {
1762 collection := v["collection"].(arvadosclient.Dict)
1763 if strings.Index(collection["name"].(string), "output") == 0 {
1764 manifest := collection["manifest_text"].(string)
1765 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1772 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1774 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1775 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1777 "environment": {"FROBIZ": "bilbo"},
1779 "/tmp": {"kind": "tmp"},
1780 "stdin": {"kind": "json", "content": "foo"},
1781 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1783 "output_path": "/tmp",
1785 "runtime_constraints": {}
1788 api, _, _ := s.fullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1789 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1793 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1794 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1795 for _, v := range api.Content {
1796 if v["collection"] != nil {
1797 collection := v["collection"].(arvadosclient.Dict)
1798 if strings.Index(collection["name"].(string), "output") == 0 {
1799 manifest := collection["manifest_text"].(string)
1800 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1807 func (s *TestSuite) TestStderrMount(c *C) {
1808 api, _, _ := s.fullRunHelper(c, `{
1809 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
1810 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1813 "mounts": {"/tmp": {"kind": "tmp"},
1814 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
1815 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
1816 "output_path": "/tmp",
1818 "runtime_constraints": {}
1819 }`, nil, 1, func(t *TestDockerClient) {
1820 t.logWriter.Write(dockerLog(1, "hello\n"))
1821 t.logWriter.Write(dockerLog(2, "oops\n"))
1825 final := api.CalledWith("container.state", "Complete")
1826 c.Assert(final, NotNil)
1827 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1828 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1830 c.Check(api.CalledWith("collection.manifest_text", "./a b1946ac92492d2347c6235b4d2611184+6 0:6:out.txt\n./b 38af5c54926b620264ab1501150cf189+5 0:5:err.txt\n"), NotNil)
1833 func (s *TestSuite) TestNumberRoundTrip(c *C) {
1834 cr := NewContainerRunner(&ArvTestClient{callraw: true}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1835 cr.fetchContainerRecord()
1837 jsondata, err := json.Marshal(cr.Container.Mounts["/json"].Content)
1840 c.Check(string(jsondata), Equals, `{"number":123456789123456789}`)
1843 func (s *TestSuite) TestEvalSymlinks(c *C) {
1844 cr := NewContainerRunner(&ArvTestClient{callraw: true}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1846 realTemp, err := ioutil.TempDir("", "crunchrun_test-")
1847 c.Assert(err, IsNil)
1848 defer os.RemoveAll(realTemp)
1850 cr.HostOutputDir = realTemp
1852 // Absolute path outside output dir
1853 os.Symlink("/etc/passwd", realTemp+"/p1")
1855 // Relative outside output dir
1856 os.Symlink("../zip", realTemp+"/p2")
1858 // Circular references
1859 os.Symlink("p4", realTemp+"/p3")
1860 os.Symlink("p5", realTemp+"/p4")
1861 os.Symlink("p3", realTemp+"/p5")
1863 // Target doesn't exist
1864 os.Symlink("p99", realTemp+"/p6")
1866 for _, v := range []string{"p1", "p2", "p3", "p4", "p5"} {
1867 info, err := os.Lstat(realTemp + "/" + v)
1868 _, _, _, err = cr.derefOutputSymlink(realTemp+"/"+v, info)
1869 c.Assert(err, NotNil)
1873 func (s *TestSuite) TestEvalSymlinkDir(c *C) {
1874 cr := NewContainerRunner(&ArvTestClient{callraw: true}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1876 realTemp, err := ioutil.TempDir("", "crunchrun_test-")
1877 c.Assert(err, IsNil)
1878 defer os.RemoveAll(realTemp)
1880 cr.HostOutputDir = realTemp
1882 // Absolute path outside output dir
1883 os.Symlink(".", realTemp+"/loop")
1886 info, err := os.Lstat(realTemp + "/" + v)
1887 _, err = cr.UploadOutputFile(realTemp+"/"+v, info, err, []string{}, nil, "", "", 0)
1888 c.Assert(err, NotNil)
1891 func (s *TestSuite) TestFullBrokenDocker1(c *C) {
1892 tf, err := ioutil.TempFile("", "brokenNodeHook-")
1893 c.Assert(err, IsNil)
1894 defer os.Remove(tf.Name())
1896 tf.Write([]byte(`#!/bin/sh
1900 os.Chmod(tf.Name(), 0700)
1903 brokenNodeHook = &ech
1905 api, _, _ := s.fullRunHelper(c, `{
1906 "command": ["echo", "hello world"],
1907 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1910 "mounts": {"/tmp": {"kind": "tmp"} },
1911 "output_path": "/tmp",
1913 "runtime_constraints": {}
1914 }`, nil, 2, func(t *TestDockerClient) {
1915 t.logWriter.Write(dockerLog(1, "hello world\n"))
1919 c.Check(api.CalledWith("container.state", "Queued"), NotNil)
1920 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1921 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Running broken node hook.*")
1922 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*killme.*")
1926 func (s *TestSuite) TestFullBrokenDocker2(c *C) {
1928 brokenNodeHook = &ech
1930 api, _, _ := s.fullRunHelper(c, `{
1931 "command": ["echo", "hello world"],
1932 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1935 "mounts": {"/tmp": {"kind": "tmp"} },
1936 "output_path": "/tmp",
1938 "runtime_constraints": {}
1939 }`, nil, 2, func(t *TestDockerClient) {
1940 t.logWriter.Write(dockerLog(1, "hello world\n"))
1944 c.Check(api.CalledWith("container.state", "Queued"), NotNil)
1945 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1946 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*No broken node hook.*")
1949 func (s *TestSuite) TestFullBrokenDocker3(c *C) {
1951 brokenNodeHook = &ech
1953 api, _, _ := s.fullRunHelper(c, `{
1954 "command": ["echo", "hello world"],
1955 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1958 "mounts": {"/tmp": {"kind": "tmp"} },
1959 "output_path": "/tmp",
1961 "runtime_constraints": {}
1962 }`, nil, 3, func(t *TestDockerClient) {
1963 t.logWriter.Write(dockerLog(1, "hello world\n"))
1967 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1968 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1971 func (s *TestSuite) TestBadCommand1(c *C) {
1973 brokenNodeHook = &ech
1975 api, _, _ := s.fullRunHelper(c, `{
1976 "command": ["echo", "hello world"],
1977 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1980 "mounts": {"/tmp": {"kind": "tmp"} },
1981 "output_path": "/tmp",
1983 "runtime_constraints": {}
1984 }`, nil, 4, func(t *TestDockerClient) {
1985 t.logWriter.Write(dockerLog(1, "hello world\n"))
1989 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1990 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
1993 func (s *TestSuite) TestBadCommand2(c *C) {
1995 brokenNodeHook = &ech
1997 api, _, _ := s.fullRunHelper(c, `{
1998 "command": ["echo", "hello world"],
1999 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
2002 "mounts": {"/tmp": {"kind": "tmp"} },
2003 "output_path": "/tmp",
2005 "runtime_constraints": {}
2006 }`, nil, 5, func(t *TestDockerClient) {
2007 t.logWriter.Write(dockerLog(1, "hello world\n"))
2011 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
2012 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
2015 func (s *TestSuite) TestBadCommand3(c *C) {
2017 brokenNodeHook = &ech
2019 api, _, _ := s.fullRunHelper(c, `{
2020 "command": ["echo", "hello world"],
2021 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
2024 "mounts": {"/tmp": {"kind": "tmp"} },
2025 "output_path": "/tmp",
2027 "runtime_constraints": {}
2028 }`, nil, 6, func(t *TestDockerClient) {
2029 t.logWriter.Write(dockerLog(1, "hello world\n"))
2033 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
2034 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")