1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
29 "git.curoverse.com/arvados.git/sdk/go/arvados"
30 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
31 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
32 "git.curoverse.com/arvados.git/sdk/go/manifest"
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 type TestSuite struct{}
47 // Gocheck boilerplate
48 var _ = Suite(&TestSuite{})
50 type ArvTestClient struct {
53 Content []arvadosclient.Dict
55 Logs map[string]*bytes.Buffer
61 type KeepTestClient struct {
66 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
67 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
68 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
70 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
71 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
73 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
74 ./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
75 ./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
78 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
80 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"
81 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
83 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
84 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
86 type TestDockerClient struct {
88 logReader io.ReadCloser
89 logWriter io.WriteCloser
90 fn func(t *TestDockerClient)
99 func NewTestDockerClient(exitCode int) *TestDockerClient {
100 t := &TestDockerClient{}
101 t.logReader, t.logWriter = io.Pipe()
103 t.stop = make(chan bool, 1)
108 type MockConn struct {
112 func (m *MockConn) Write(b []byte) (int, error) {
116 func NewMockConn() *MockConn {
121 func (t *TestDockerClient) ContainerAttach(ctx context.Context, container string, options dockertypes.ContainerAttachOptions) (dockertypes.HijackedResponse, error) {
122 return dockertypes.HijackedResponse{Conn: NewMockConn(), Reader: bufio.NewReader(t.logReader)}, nil
125 func (t *TestDockerClient) ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error) {
126 if config.WorkingDir != "" {
127 t.cwd = config.WorkingDir
130 return dockercontainer.ContainerCreateCreatedBody{ID: "abcde"}, nil
133 func (t *TestDockerClient) ContainerStart(ctx context.Context, container string, options dockertypes.ContainerStartOptions) error {
135 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\\\"\""`)
138 return errors.New(`panic: standard_init_linux.go:175: exec user process caused "no such file or directory"`)
141 return errors.New(`Error response from daemon: Cannot start container 41f26cbc43bcc1280f4323efb1830a394ba8660c9d1c2b564ba42bf7f7694845: [8] System error: no such file or directory`)
144 return errors.New(`Error response from daemon: Cannot start container 58099cd76c834f3dc2a4fb76c8028f049ae6d4fdf0ec373e1f2cfea030670c2d: [8] System error: exec: "foobar": executable file not found in $PATH`)
147 if container == "abcde" {
148 // t.fn gets executed in ContainerWait
151 return errors.New("Invalid container id")
155 func (t *TestDockerClient) ContainerStop(ctx context.Context, container string, timeout *time.Duration) error {
160 func (t *TestDockerClient) ContainerWait(ctx context.Context, container string, condition dockercontainer.WaitCondition) (<-chan dockercontainer.ContainerWaitOKBody, <-chan error) {
161 body := make(chan dockercontainer.ContainerWaitOKBody)
162 err := make(chan error)
165 body <- dockercontainer.ContainerWaitOKBody{StatusCode: int64(t.finish)}
172 func (t *TestDockerClient) ImageInspectWithRaw(ctx context.Context, image string) (dockertypes.ImageInspect, []byte, error) {
174 return dockertypes.ImageInspect{}, nil, fmt.Errorf("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
177 if t.imageLoaded == image {
178 return dockertypes.ImageInspect{}, nil, nil
180 return dockertypes.ImageInspect{}, nil, errors.New("")
184 func (t *TestDockerClient) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (dockertypes.ImageLoadResponse, error) {
186 return dockertypes.ImageLoadResponse{}, fmt.Errorf("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
188 _, err := io.Copy(ioutil.Discard, input)
190 return dockertypes.ImageLoadResponse{}, err
192 t.imageLoaded = hwImageId
193 return dockertypes.ImageLoadResponse{Body: ioutil.NopCloser(input)}, nil
197 func (*TestDockerClient) ImageRemove(ctx context.Context, image string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {
201 func (client *ArvTestClient) Create(resourceType string,
202 parameters arvadosclient.Dict,
203 output interface{}) error {
206 defer client.Mutex.Unlock()
209 client.Content = append(client.Content, parameters)
211 if resourceType == "logs" {
212 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
213 if client.Logs == nil {
214 client.Logs = make(map[string]*bytes.Buffer)
216 if client.Logs[et] == nil {
217 client.Logs[et] = &bytes.Buffer{}
219 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
222 if resourceType == "collections" && output != nil {
223 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
224 outmap := output.(*arvados.Collection)
225 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
231 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
233 case method == "GET" && resourceType == "containers" && action == "auth":
234 return json.Unmarshal([]byte(`{
235 "kind": "arvados#api_client_authorization",
236 "uuid": "`+fakeAuthUUID+`",
237 "api_token": "`+fakeAuthToken+`"
239 case method == "GET" && resourceType == "nodes" && uuid == "" && action == "":
240 return json.Unmarshal([]byte(`{
241 "kind": "arvados#nodeList",
243 "uuid": "zzzzz-7ekkf-2z3mc76g2q73aio",
244 "hostname": "compute2",
245 "properties": {"total_cpu_cores": 16}
248 return fmt.Errorf("Not found")
252 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
253 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
255 if method == "GET" && resourceType == "containers" && action == "" && !client.callraw {
256 j, err = json.Marshal(client.Container)
259 "command": ["sleep", "1"],
260 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
263 "mounts": {"/tmp": {"kind": "tmp"}, "/json": {"kind": "json", "content": {"number": 123456789123456789}}},
264 "output_path": "/tmp",
266 "runtime_constraints": {}
269 return ioutil.NopCloser(bytes.NewReader(j)), err
272 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
273 if resourceType == "collections" {
275 output.(*arvados.Collection).ManifestText = hwManifest
276 } else if uuid == otherPDH {
277 output.(*arvados.Collection).ManifestText = otherManifest
278 } else if uuid == normalizedWithSubdirsPDH {
279 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
280 } else if uuid == denormalizedWithSubdirsPDH {
281 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
284 if resourceType == "containers" {
285 (*output.(*arvados.Container)) = client.Container
290 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
292 defer client.Mutex.Unlock()
294 client.Content = append(client.Content, parameters)
295 if resourceType == "containers" {
296 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
297 client.WasSetRunning = true
303 var discoveryMap = map[string]interface{}{
304 "defaultTrashLifetime": float64(1209600),
305 "crunchLimitLogBytesPerJob": float64(67108864),
306 "crunchLogThrottleBytes": float64(65536),
307 "crunchLogThrottlePeriod": float64(60),
308 "crunchLogThrottleLines": float64(1024),
309 "crunchLogPartialLineThrottlePeriod": float64(5),
310 "crunchLogBytesPerEvent": float64(4096),
311 "crunchLogSecondsBetweenEvents": float64(1),
314 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
315 return discoveryMap[key], nil
318 // CalledWith returns the parameters from the first API call whose
319 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
320 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
321 // no call matches, it returns nil.
322 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
324 for _, content := range client.Content {
325 var v interface{} = content
326 for _, k := range strings.Split(jpath, ".") {
327 if dict, ok := v.(arvadosclient.Dict); !ok {
340 func (client *KeepTestClient) PutHB(hash string, buf []byte) (string, int, error) {
342 return fmt.Sprintf("%s+%d", hash, len(buf)), len(buf), nil
345 func (*KeepTestClient) ClearBlockCache() {
348 type FileWrapper struct {
353 func (fw FileWrapper) Readdir(n int) ([]os.FileInfo, error) {
354 return nil, errors.New("not implemented")
357 func (fw FileWrapper) Seek(int64, int) (int64, error) {
358 return 0, errors.New("not implemented")
361 func (fw FileWrapper) Size() int64 {
365 func (fw FileWrapper) Stat() (os.FileInfo, error) {
366 return nil, errors.New("not implemented")
369 func (fw FileWrapper) Truncate(int64) error {
370 return errors.New("not implemented")
373 func (fw FileWrapper) Write([]byte) (int, error) {
374 return 0, errors.New("not implemented")
377 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
378 if filename == hwImageId+".tar" {
379 rdr := ioutil.NopCloser(&bytes.Buffer{})
381 return FileWrapper{rdr, 1321984}, nil
382 } else if filename == "/file1_in_main.txt" {
383 rdr := ioutil.NopCloser(strings.NewReader("foo"))
385 return FileWrapper{rdr, 3}, nil
390 func (s *TestSuite) TestLoadImage(c *C) {
391 kc := &KeepTestClient{}
392 docker := NewTestDockerClient(0)
393 cr := NewContainerRunner(&ArvTestClient{}, kc, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
395 _, err := cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
397 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
400 cr.Container.ContainerImage = hwPDH
402 // (1) Test loading image from keep
403 c.Check(kc.Called, Equals, false)
404 c.Check(cr.ContainerConfig.Image, Equals, "")
410 cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
413 c.Check(kc.Called, Equals, true)
414 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
416 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
419 // (2) Test using image that's already loaded
421 cr.ContainerConfig.Image = ""
425 c.Check(kc.Called, Equals, false)
426 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
430 type ArvErrorTestClient struct{}
432 func (ArvErrorTestClient) Create(resourceType string,
433 parameters arvadosclient.Dict,
434 output interface{}) error {
438 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
439 return errors.New("ArvError")
442 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
443 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
444 return nil, errors.New("ArvError")
447 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
448 return errors.New("ArvError")
451 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
455 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
456 return discoveryMap[key], nil
459 type KeepErrorTestClient struct{}
461 func (KeepErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
462 return "", 0, errors.New("KeepError")
465 func (KeepErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
466 return nil, errors.New("KeepError")
469 func (KeepErrorTestClient) ClearBlockCache() {
472 type KeepReadErrorTestClient struct{}
474 func (KeepReadErrorTestClient) PutHB(hash string, buf []byte) (string, int, error) {
478 func (KeepReadErrorTestClient) ClearBlockCache() {
481 type ErrorReader struct {
485 func (ErrorReader) Read(p []byte) (n int, err error) {
486 return 0, errors.New("ErrorReader")
489 func (ErrorReader) Seek(int64, int) (int64, error) {
490 return 0, errors.New("ErrorReader")
493 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
494 return ErrorReader{}, nil
497 func (s *TestSuite) TestLoadImageArvError(c *C) {
499 cr := NewContainerRunner(ArvErrorTestClient{}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
500 cr.Container.ContainerImage = hwPDH
502 err := cr.LoadImage()
503 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
506 func (s *TestSuite) TestLoadImageKeepError(c *C) {
508 docker := NewTestDockerClient(0)
509 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
510 cr.Container.ContainerImage = hwPDH
512 err := cr.LoadImage()
513 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
516 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
517 // (3) Collection doesn't contain image
518 cr := NewContainerRunner(&ArvTestClient{}, KeepErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
519 cr.Container.ContainerImage = otherPDH
521 err := cr.LoadImage()
522 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
525 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
526 // (4) Collection doesn't contain image
527 docker := NewTestDockerClient(0)
528 cr := NewContainerRunner(&ArvTestClient{}, KeepReadErrorTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
529 cr.Container.ContainerImage = hwPDH
531 err := cr.LoadImage()
535 type ClosableBuffer struct {
539 func (*ClosableBuffer) Close() error {
543 type TestLogs struct {
544 Stdout ClosableBuffer
545 Stderr ClosableBuffer
548 func (tl *TestLogs) NewTestLoggingWriter(logstr string) io.WriteCloser {
549 if logstr == "stdout" {
552 if logstr == "stderr" {
558 func dockerLog(fd byte, msg string) []byte {
560 header := make([]byte, 8+len(by))
562 header[7] = byte(len(by))
567 func (s *TestSuite) TestRunContainer(c *C) {
568 docker := NewTestDockerClient(0)
569 docker.fn = func(t *TestDockerClient) {
570 t.logWriter.Write(dockerLog(1, "Hello world\n"))
573 cr := NewContainerRunner(&ArvTestClient{}, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
576 cr.NewLogWriter = logs.NewTestLoggingWriter
577 cr.Container.ContainerImage = hwPDH
578 cr.Container.Command = []string{"./hw"}
579 err := cr.LoadImage()
582 err = cr.CreateContainer()
585 err = cr.StartContainer()
588 err = cr.WaitFinish()
591 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
592 c.Check(logs.Stderr.String(), Equals, "")
595 func (s *TestSuite) TestCommitLogs(c *C) {
596 api := &ArvTestClient{}
597 kc := &KeepTestClient{}
598 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
599 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
601 cr.CrunchLog.Print("Hello world!")
602 cr.CrunchLog.Print("Goodbye")
603 cr.finalState = "Complete"
605 err := cr.CommitLogs()
608 c.Check(api.Calls, Equals, 2)
609 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
610 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
611 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
612 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
615 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
616 api := &ArvTestClient{}
617 kc := &KeepTestClient{}
618 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
620 err := cr.UpdateContainerRunning()
623 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
626 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
627 api := &ArvTestClient{}
628 kc := &KeepTestClient{}
629 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
631 cr.LogsPDH = new(string)
632 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
634 cr.ExitCode = new(int)
636 cr.finalState = "Complete"
638 err := cr.UpdateContainerFinal()
641 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
642 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
643 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
646 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
647 api := &ArvTestClient{}
648 kc := &KeepTestClient{}
649 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
651 cr.finalState = "Cancelled"
653 err := cr.UpdateContainerFinal()
656 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
657 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
658 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
661 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
662 // dress rehearsal of the Run() function, starting from a JSON container record.
663 func FullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, realTemp string) {
664 rec := arvados.Container{}
665 err := json.Unmarshal([]byte(record), &rec)
668 docker := NewTestDockerClient(exitCode)
670 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
672 api = &ArvTestClient{Container: rec}
674 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
675 cr.statInterval = 100 * time.Millisecond
676 am := &ArvMountCmdLine{}
677 cr.RunArvMount = am.ArvMountTest
679 realTemp, err = ioutil.TempDir("", "crunchrun_test1-")
681 defer os.RemoveAll(realTemp)
683 docker.realTemp = realTemp
686 cr.MkTempDir = func(_ string, prefix string) (string, error) {
688 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
689 err := os.Mkdir(d, os.ModePerm)
690 if err != nil && strings.Contains(err.Error(), ": file exists") {
691 // Test case must have pre-populated the tempdir
697 if extraMounts != nil && len(extraMounts) > 0 {
698 err := cr.SetupArvMountPoint("keep")
701 for _, m := range extraMounts {
702 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
707 if api.CalledWith("container.state", "Complete") != nil {
711 c.Check(api.WasSetRunning, Equals, true)
712 c.Check(api.Content[api.Calls-2]["container"].(arvadosclient.Dict)["log"], NotNil)
716 for k, v := range api.Logs {
725 func (s *TestSuite) TestFullRunHello(c *C) {
726 api, _, _ := FullRunHelper(c, `{
727 "command": ["echo", "hello world"],
728 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
731 "mounts": {"/tmp": {"kind": "tmp"} },
732 "output_path": "/tmp",
734 "runtime_constraints": {}
735 }`, nil, 0, func(t *TestDockerClient) {
736 t.logWriter.Write(dockerLog(1, "hello world\n"))
740 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
741 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
742 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
746 func (s *TestSuite) TestCrunchstat(c *C) {
747 api, _, _ := FullRunHelper(c, `{
748 "command": ["sleep", "1"],
749 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
752 "mounts": {"/tmp": {"kind": "tmp"} },
753 "output_path": "/tmp",
755 "runtime_constraints": {}
756 }`, nil, 0, func(t *TestDockerClient) {
757 time.Sleep(time.Second)
761 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
762 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
764 // We didn't actually start a container, so crunchstat didn't
765 // find accounting files and therefore didn't log any stats.
766 // It should have logged a "can't find accounting files"
767 // message after one poll interval, though, so we can confirm
769 c.Assert(api.Logs["crunchstat"], NotNil)
770 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
772 // The "files never appeared" log assures us that we called
773 // (*crunchstat.Reporter)Stop(), and that we set it up with
774 // the correct container ID "abcde":
775 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
778 func (s *TestSuite) TestNodeInfoLog(c *C) {
779 os.Setenv("SLURMD_NODENAME", "compute2")
780 api, _, _ := FullRunHelper(c, `{
781 "command": ["sleep", "1"],
782 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
785 "mounts": {"/tmp": {"kind": "tmp"} },
786 "output_path": "/tmp",
788 "runtime_constraints": {}
790 func(t *TestDockerClient) {
791 time.Sleep(time.Second)
795 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
796 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
798 c.Assert(api.Logs["node-info"], NotNil)
799 inf := api.Logs["node-info"].String()
800 c.Check(inf, Matches, `(?ms).*Node properties.*zzzzz-7ekkf-2z3mc76g2q73aio.*"total_cpu_cores":16.*`)
801 c.Check(inf, Matches, `(?ms).*Host Information.*`)
802 c.Check(inf, Matches, `(?ms).*CPU Information.*`)
803 c.Check(inf, Matches, `(?ms).*Memory Information.*`)
804 c.Check(inf, Matches, `(?ms).*Disk Space.*`)
805 c.Check(inf, Matches, `(?ms).*Disk INodes.*`)
808 func (s *TestSuite) TestContainerRecordLog(c *C) {
809 api, _, _ := FullRunHelper(c, `{
810 "command": ["sleep", "1"],
811 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
814 "mounts": {"/tmp": {"kind": "tmp"} },
815 "output_path": "/tmp",
817 "runtime_constraints": {}
819 func(t *TestDockerClient) {
820 time.Sleep(time.Second)
824 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
825 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
827 c.Assert(api.Logs["container"], NotNil)
828 c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
831 func (s *TestSuite) TestFullRunStderr(c *C) {
832 api, _, _ := FullRunHelper(c, `{
833 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
834 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
837 "mounts": {"/tmp": {"kind": "tmp"} },
838 "output_path": "/tmp",
840 "runtime_constraints": {}
841 }`, nil, 1, func(t *TestDockerClient) {
842 t.logWriter.Write(dockerLog(1, "hello\n"))
843 t.logWriter.Write(dockerLog(2, "world\n"))
847 final := api.CalledWith("container.state", "Complete")
848 c.Assert(final, NotNil)
849 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
850 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
852 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
853 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
856 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
857 api, _, _ := FullRunHelper(c, `{
859 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
862 "mounts": {"/tmp": {"kind": "tmp"} },
863 "output_path": "/tmp",
865 "runtime_constraints": {}
866 }`, nil, 0, func(t *TestDockerClient) {
867 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
871 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
872 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
873 c.Log(api.Logs["stdout"])
874 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
877 func (s *TestSuite) TestFullRunSetCwd(c *C) {
878 api, _, _ := FullRunHelper(c, `{
880 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
883 "mounts": {"/tmp": {"kind": "tmp"} },
884 "output_path": "/tmp",
886 "runtime_constraints": {}
887 }`, nil, 0, func(t *TestDockerClient) {
888 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
892 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
893 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
894 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
897 func (s *TestSuite) TestStopOnSignal(c *C) {
898 s.testStopContainer(c, func(cr *ContainerRunner) {
901 time.Sleep(time.Millisecond)
903 cr.SigChan <- syscall.SIGINT
908 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
909 s.testStopContainer(c, func(cr *ContainerRunner) {
910 cr.ArvMountExit = make(chan error)
912 cr.ArvMountExit <- exec.Command("true").Run()
913 close(cr.ArvMountExit)
918 func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
920 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
921 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
924 "mounts": {"/tmp": {"kind": "tmp"} },
925 "output_path": "/tmp",
927 "runtime_constraints": {}
930 rec := arvados.Container{}
931 err := json.Unmarshal([]byte(record), &rec)
934 docker := NewTestDockerClient(0)
935 docker.fn = func(t *TestDockerClient) {
937 t.logWriter.Write(dockerLog(1, "foo\n"))
940 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
942 api := &ArvTestClient{Container: rec}
943 cr := NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
944 cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
947 done := make(chan error)
952 case <-time.After(20 * time.Second):
953 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
958 for k, v := range api.Logs {
963 c.Check(api.CalledWith("container.log", nil), NotNil)
964 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
965 c.Check(api.Logs["stdout"].String(), Matches, "(?ms).*foo\n$")
968 func (s *TestSuite) TestFullRunSetEnv(c *C) {
969 api, _, _ := FullRunHelper(c, `{
970 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
971 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
973 "environment": {"FROBIZ": "bilbo"},
974 "mounts": {"/tmp": {"kind": "tmp"} },
975 "output_path": "/tmp",
977 "runtime_constraints": {}
978 }`, nil, 0, func(t *TestDockerClient) {
979 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
983 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
984 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
985 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
988 type ArvMountCmdLine struct {
993 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
999 func stubCert(temp string) string {
1000 path := temp + "/ca-certificates.crt"
1001 crt, _ := os.Create(path)
1003 arvadosclient.CertFiles = []string{path}
1007 func (s *TestSuite) TestSetupMounts(c *C) {
1008 api := &ArvTestClient{}
1009 kc := &KeepTestClient{}
1010 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1011 am := &ArvMountCmdLine{}
1012 cr.RunArvMount = am.ArvMountTest
1014 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
1015 c.Assert(err, IsNil)
1016 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
1017 c.Assert(err, IsNil)
1018 stubCertPath := stubCert(certTemp)
1020 defer os.RemoveAll(realTemp)
1021 defer os.RemoveAll(certTemp)
1024 cr.MkTempDir = func(_ string, prefix string) (string, error) {
1026 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
1027 err := os.Mkdir(d, os.ModePerm)
1028 if err != nil && strings.Contains(err.Error(), ": file exists") {
1029 // Test case must have pre-populated the tempdir
1035 checkEmpty := func() {
1036 filepath.Walk(realTemp, func(path string, _ os.FileInfo, err error) error {
1037 c.Check(path, Equals, realTemp)
1045 cr.ArvMountPoint = ""
1046 cr.Container.Mounts = make(map[string]arvados.Mount)
1047 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1048 cr.OutputPath = "/tmp"
1049 cr.statInterval = 5 * time.Second
1050 err := cr.SetupMounts()
1052 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1053 "--read-write", "--crunchstat-interval=5",
1054 "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1055 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp"})
1056 os.RemoveAll(cr.ArvMountPoint)
1063 cr.ArvMountPoint = ""
1064 cr.Container.Mounts = make(map[string]arvados.Mount)
1065 cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"}
1066 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1067 cr.OutputPath = "/out"
1069 err := cr.SetupMounts()
1071 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1072 "--read-write", "--crunchstat-interval=5",
1073 "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1074 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/out", realTemp + "/3:/tmp"})
1075 os.RemoveAll(cr.ArvMountPoint)
1082 cr.ArvMountPoint = ""
1083 cr.Container.Mounts = make(map[string]arvados.Mount)
1084 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1085 cr.OutputPath = "/tmp"
1088 cr.Container.RuntimeConstraints.API = &apiflag
1090 err := cr.SetupMounts()
1092 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1093 "--read-write", "--crunchstat-interval=5",
1094 "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1095 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
1096 os.RemoveAll(cr.ArvMountPoint)
1105 cr.ArvMountPoint = ""
1106 cr.Container.Mounts = map[string]arvados.Mount{
1107 "/keeptmp": {Kind: "collection", Writable: true},
1109 cr.OutputPath = "/keeptmp"
1111 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1113 err := cr.SetupMounts()
1115 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1116 "--read-write", "--crunchstat-interval=5",
1117 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1118 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
1119 os.RemoveAll(cr.ArvMountPoint)
1126 cr.ArvMountPoint = ""
1127 cr.Container.Mounts = map[string]arvados.Mount{
1128 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1129 "/keepout": {Kind: "collection", Writable: true},
1131 cr.OutputPath = "/keepout"
1133 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1134 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1136 err := cr.SetupMounts()
1138 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1139 "--read-write", "--crunchstat-interval=5",
1140 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1141 sort.StringSlice(cr.Binds).Sort()
1142 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1143 realTemp + "/keep1/tmp0:/keepout"})
1144 os.RemoveAll(cr.ArvMountPoint)
1151 cr.ArvMountPoint = ""
1152 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1153 cr.Container.Mounts = map[string]arvados.Mount{
1154 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1155 "/keepout": {Kind: "collection", Writable: true},
1157 cr.OutputPath = "/keepout"
1159 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1160 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1162 err := cr.SetupMounts()
1164 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1165 "--read-write", "--crunchstat-interval=5",
1166 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1167 sort.StringSlice(cr.Binds).Sort()
1168 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1169 realTemp + "/keep1/tmp0:/keepout"})
1170 os.RemoveAll(cr.ArvMountPoint)
1175 for _, test := range []struct {
1179 {in: "foo", out: `"foo"`},
1180 {in: nil, out: `null`},
1181 {in: map[string]int64{"foo": 123456789123456789}, out: `{"foo":123456789123456789}`},
1184 cr.ArvMountPoint = ""
1185 cr.Container.Mounts = map[string]arvados.Mount{
1186 "/mnt/test.json": {Kind: "json", Content: test.in},
1188 err := cr.SetupMounts()
1190 sort.StringSlice(cr.Binds).Sort()
1191 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2/mountdata.json:/mnt/test.json:ro"})
1192 content, err := ioutil.ReadFile(realTemp + "/2/mountdata.json")
1194 c.Check(content, DeepEquals, []byte(test.out))
1195 os.RemoveAll(cr.ArvMountPoint)
1200 // Read-only mount points are allowed underneath output_dir mount point
1203 cr.ArvMountPoint = ""
1204 cr.Container.Mounts = make(map[string]arvados.Mount)
1205 cr.Container.Mounts = map[string]arvados.Mount{
1206 "/tmp": {Kind: "tmp"},
1207 "/tmp/foo": {Kind: "collection"},
1209 cr.OutputPath = "/tmp"
1211 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1213 err := cr.SetupMounts()
1215 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1216 "--read-write", "--crunchstat-interval=5",
1217 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1218 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
1219 os.RemoveAll(cr.ArvMountPoint)
1224 // Writable mount points are not allowed underneath output_dir mount point
1227 cr.ArvMountPoint = ""
1228 cr.Container.Mounts = make(map[string]arvados.Mount)
1229 cr.Container.Mounts = map[string]arvados.Mount{
1230 "/tmp": {Kind: "tmp"},
1231 "/tmp/foo": {Kind: "collection", Writable: true},
1233 cr.OutputPath = "/tmp"
1235 err := cr.SetupMounts()
1236 c.Check(err, NotNil)
1237 c.Check(err, ErrorMatches, `Writable mount points are not permitted underneath the output_path.*`)
1238 os.RemoveAll(cr.ArvMountPoint)
1243 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1246 cr.ArvMountPoint = ""
1247 cr.Container.Mounts = make(map[string]arvados.Mount)
1248 cr.Container.Mounts = map[string]arvados.Mount{
1249 "/tmp": {Kind: "tmp"},
1250 "/tmp/foo": {Kind: "json"},
1252 cr.OutputPath = "/tmp"
1254 err := cr.SetupMounts()
1255 c.Check(err, NotNil)
1256 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1257 os.RemoveAll(cr.ArvMountPoint)
1262 // Only mount point of kind 'collection' is allowed for stdin
1265 cr.ArvMountPoint = ""
1266 cr.Container.Mounts = make(map[string]arvados.Mount)
1267 cr.Container.Mounts = map[string]arvados.Mount{
1268 "stdin": {Kind: "tmp"},
1271 err := cr.SetupMounts()
1272 c.Check(err, NotNil)
1273 c.Check(err, ErrorMatches, `Unsupported mount kind 'tmp' for stdin.*`)
1274 os.RemoveAll(cr.ArvMountPoint)
1282 cr.ArvMountPoint = ""
1283 (*GitMountSuite)(nil).useTestGitServer(c)
1284 cr.token = arvadostest.ActiveToken
1285 cr.Container.Mounts = make(map[string]arvados.Mount)
1286 cr.Container.Mounts = map[string]arvados.Mount{
1289 UUID: arvadostest.Repository2UUID,
1290 Commit: "fd3531f42995344f36c30b79f55f27b502f3d344",
1295 UUID: arvadostest.Repository2UUID,
1296 Commit: "5ebfab0522851df01fec11ec55a6d0f4877b542e",
1300 cr.OutputPath = "/tmp"
1302 err := cr.SetupMounts()
1305 // dirMap[mountpoint] == tmpdir
1306 dirMap := make(map[string]string)
1307 for _, bind := range cr.Binds {
1308 tokens := strings.Split(bind, ":")
1309 dirMap[tokens[1]] = tokens[0]
1311 if cr.Container.Mounts[tokens[1]].Writable {
1312 c.Check(len(tokens), Equals, 2)
1314 c.Check(len(tokens), Equals, 3)
1315 c.Check(tokens[2], Equals, "ro")
1319 data, err := ioutil.ReadFile(dirMap["/tip"] + "/dir1/dir2/file with mode 0644")
1321 c.Check(string(data), Equals, "\000\001\002\003")
1322 _, err = ioutil.ReadFile(dirMap["/tip"] + "/file only on testbranch")
1323 c.Check(err, FitsTypeOf, &os.PathError{})
1324 c.Check(os.IsNotExist(err), Equals, true)
1326 data, err = ioutil.ReadFile(dirMap["/non-tip"] + "/dir1/dir2/file with mode 0644")
1328 c.Check(string(data), Equals, "\000\001\002\003")
1329 data, err = ioutil.ReadFile(dirMap["/non-tip"] + "/file only on testbranch")
1331 c.Check(string(data), Equals, "testfile\n")
1338 func (s *TestSuite) TestStdout(c *C) {
1340 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1341 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1343 "environment": {"FROBIZ": "bilbo"},
1344 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1345 "output_path": "/tmp",
1347 "runtime_constraints": {}
1350 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1351 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1355 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1356 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1357 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1360 // Used by the TestStdoutWithWrongPath*()
1361 func StdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1362 rec := arvados.Container{}
1363 err = json.Unmarshal([]byte(record), &rec)
1366 docker := NewTestDockerClient(0)
1368 docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1370 api = &ArvTestClient{Container: rec}
1371 cr = NewContainerRunner(api, &KeepTestClient{}, docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1372 am := &ArvMountCmdLine{}
1373 cr.RunArvMount = am.ArvMountTest
1379 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1380 _, _, err := StdoutErrorRunHelper(c, `{
1381 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1382 "output_path": "/tmp"
1383 }`, func(t *TestDockerClient) {})
1385 c.Check(err, NotNil)
1386 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1389 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1390 _, _, err := StdoutErrorRunHelper(c, `{
1391 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1392 "output_path": "/tmp"
1393 }`, func(t *TestDockerClient) {})
1395 c.Check(err, NotNil)
1396 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1399 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1400 _, _, err := StdoutErrorRunHelper(c, `{
1401 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1402 "output_path": "/tmp"
1403 }`, func(t *TestDockerClient) {})
1405 c.Check(err, NotNil)
1406 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1409 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1410 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1411 defer os.Unsetenv("ARVADOS_API_HOST")
1412 api, _, _ := FullRunHelper(c, `{
1413 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1414 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1417 "mounts": {"/tmp": {"kind": "tmp"} },
1418 "output_path": "/tmp",
1420 "runtime_constraints": {"API": true}
1421 }`, nil, 0, func(t *TestDockerClient) {
1422 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1426 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1427 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1428 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1429 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1432 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1433 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1434 defer os.Unsetenv("ARVADOS_API_HOST")
1435 api, _, _ := FullRunHelper(c, `{
1436 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1437 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1440 "mounts": {"/tmp": {"kind": "tmp"} },
1441 "output_path": "/tmp",
1443 "runtime_constraints": {"API": true}
1444 }`, nil, 0, func(t *TestDockerClient) {
1445 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1449 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1450 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1451 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1454 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1456 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1457 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1459 "environment": {"FROBIZ": "bilbo"},
1461 "/tmp": {"kind": "tmp"},
1462 "/tmp/foo": {"kind": "collection",
1463 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1464 "exclude_from_output": true
1466 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1468 "output_path": "/tmp",
1470 "runtime_constraints": {}
1473 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1475 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1476 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1480 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1481 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1482 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1485 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1487 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1488 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1490 "environment": {"FROBIZ": "bilbo"},
1492 "/tmp": {"kind": "tmp"},
1493 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1494 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1495 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1496 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1497 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1499 "output_path": "/tmp",
1501 "runtime_constraints": {}
1504 extraMounts := []string{
1505 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1506 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1507 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1510 api, runner, realtemp := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1511 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1515 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/2:/tmp",
1516 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1517 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1518 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1519 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1522 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1523 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1524 for _, v := range api.Content {
1525 if v["collection"] != nil {
1526 c.Check(v["ensure_unique_name"], Equals, true)
1527 collection := v["collection"].(arvadosclient.Dict)
1528 if strings.Index(collection["name"].(string), "output") == 0 {
1529 manifest := collection["manifest_text"].(string)
1531 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1532 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar 9:18:sub1file2
1533 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1534 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1535 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1542 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1544 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1545 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1547 "environment": {"FROBIZ": "bilbo"},
1549 "/tmp": {"kind": "tmp"},
1550 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1551 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1553 "output_path": "/tmp",
1555 "runtime_constraints": {}
1558 extraMounts := []string{
1559 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1562 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1563 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1567 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1568 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1569 for _, v := range api.Content {
1570 if v["collection"] != nil {
1571 collection := v["collection"].(arvadosclient.Dict)
1572 if strings.Index(collection["name"].(string), "output") == 0 {
1573 manifest := collection["manifest_text"].(string)
1575 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1576 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1583 func (s *TestSuite) TestOutputSymlinkToInput(c *C) {
1585 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1586 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1588 "environment": {"FROBIZ": "bilbo"},
1590 "/tmp": {"kind": "tmp"},
1591 "/keep/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path": "/subdir1/file2_in_subdir1.txt"},
1592 "/keep/foo2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367"}
1594 "output_path": "/tmp",
1596 "runtime_constraints": {}
1599 extraMounts := []string{
1600 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1603 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1604 os.Symlink("/keep/foo/sub1file2", t.realTemp+"/2/baz")
1605 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz2")
1606 os.Symlink("/keep/foo2/subdir1", t.realTemp+"/2/baz3")
1607 os.Mkdir(t.realTemp+"/2/baz4", 0700)
1608 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz4/baz5")
1612 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1613 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1614 for _, v := range api.Content {
1615 if v["collection"] != nil {
1616 collection := v["collection"].(arvadosclient.Dict)
1617 if strings.Index(collection["name"].(string), "output") == 0 {
1618 manifest := collection["manifest_text"].(string)
1619 c.Check(manifest, Equals, `. 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz 9:18:baz2
1620 ./baz3 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1621 ./baz3/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1622 ./baz4 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz5
1629 func (s *TestSuite) TestOutputError(c *C) {
1631 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1632 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1634 "environment": {"FROBIZ": "bilbo"},
1636 "/tmp": {"kind": "tmp"}
1638 "output_path": "/tmp",
1640 "runtime_constraints": {}
1643 extraMounts := []string{}
1645 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1646 os.Symlink("/etc/hosts", t.realTemp+"/2/baz")
1650 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1653 func (s *TestSuite) TestOutputSymlinkToOutput(c *C) {
1655 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1656 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1658 "environment": {"FROBIZ": "bilbo"},
1660 "/tmp": {"kind": "tmp"}
1662 "output_path": "/tmp",
1664 "runtime_constraints": {}
1667 extraMounts := []string{}
1669 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1670 rf, _ := os.Create(t.realTemp + "/2/realfile")
1671 rf.Write([]byte("foo"))
1674 os.Mkdir(t.realTemp+"/2/realdir", 0700)
1675 rf, _ = os.Create(t.realTemp + "/2/realdir/subfile")
1676 rf.Write([]byte("bar"))
1679 os.Symlink("/tmp/realfile", t.realTemp+"/2/file1")
1680 os.Symlink("realfile", t.realTemp+"/2/file2")
1681 os.Symlink("/tmp/file1", t.realTemp+"/2/file3")
1682 os.Symlink("file2", t.realTemp+"/2/file4")
1683 os.Symlink("realdir", t.realTemp+"/2/dir1")
1684 os.Symlink("/tmp/realdir", t.realTemp+"/2/dir2")
1688 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1689 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1690 for _, v := range api.Content {
1691 if v["collection"] != nil {
1692 collection := v["collection"].(arvadosclient.Dict)
1693 if strings.Index(collection["name"].(string), "output") == 0 {
1694 manifest := collection["manifest_text"].(string)
1695 c.Check(manifest, Equals,
1696 `. 7a2c86e102dcc231bd232aad99686dfa+15 0:3:file1 3:3:file2 6:3:file3 9:3:file4 12:3:realfile
1697 ./dir1 37b51d194a7513e45b56f6524f2d51f2+3 0:3:subfile
1698 ./dir2 37b51d194a7513e45b56f6524f2d51f2+3 0:3:subfile
1699 ./realdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:subfile
1706 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1708 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1709 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1711 "environment": {"FROBIZ": "bilbo"},
1713 "/tmp": {"kind": "tmp"},
1714 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1715 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1717 "output_path": "/tmp",
1719 "runtime_constraints": {}
1722 extraMounts := []string{
1723 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1726 api, _, _ := FullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1727 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1731 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1732 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1733 for _, v := range api.Content {
1734 if v["collection"] != nil {
1735 collection := v["collection"].(arvadosclient.Dict)
1736 if strings.Index(collection["name"].(string), "output") == 0 {
1737 manifest := collection["manifest_text"].(string)
1738 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1745 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1747 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1748 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1750 "environment": {"FROBIZ": "bilbo"},
1752 "/tmp": {"kind": "tmp"},
1753 "stdin": {"kind": "json", "content": "foo"},
1754 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1756 "output_path": "/tmp",
1758 "runtime_constraints": {}
1761 api, _, _ := FullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1762 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1766 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1767 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1768 for _, v := range api.Content {
1769 if v["collection"] != nil {
1770 collection := v["collection"].(arvadosclient.Dict)
1771 if strings.Index(collection["name"].(string), "output") == 0 {
1772 manifest := collection["manifest_text"].(string)
1773 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1780 func (s *TestSuite) TestStderrMount(c *C) {
1781 api, _, _ := FullRunHelper(c, `{
1782 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
1783 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1786 "mounts": {"/tmp": {"kind": "tmp"},
1787 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
1788 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
1789 "output_path": "/tmp",
1791 "runtime_constraints": {}
1792 }`, nil, 1, func(t *TestDockerClient) {
1793 t.logWriter.Write(dockerLog(1, "hello\n"))
1794 t.logWriter.Write(dockerLog(2, "oops\n"))
1798 final := api.CalledWith("container.state", "Complete")
1799 c.Assert(final, NotNil)
1800 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1801 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1803 c.Check(api.CalledWith("collection.manifest_text", "./a b1946ac92492d2347c6235b4d2611184+6 0:6:out.txt\n./b 38af5c54926b620264ab1501150cf189+5 0:5:err.txt\n"), NotNil)
1806 func (s *TestSuite) TestNumberRoundTrip(c *C) {
1807 cr := NewContainerRunner(&ArvTestClient{callraw: true}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1808 cr.fetchContainerRecord()
1810 jsondata, err := json.Marshal(cr.Container.Mounts["/json"].Content)
1813 c.Check(string(jsondata), Equals, `{"number":123456789123456789}`)
1816 func (s *TestSuite) TestEvalSymlinks(c *C) {
1817 cr := NewContainerRunner(&ArvTestClient{callraw: true}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1819 realTemp, err := ioutil.TempDir("", "crunchrun_test-")
1820 c.Assert(err, IsNil)
1821 defer os.RemoveAll(realTemp)
1823 cr.HostOutputDir = realTemp
1825 // Absolute path outside output dir
1826 os.Symlink("/etc/passwd", realTemp+"/p1")
1828 // Relative outside output dir
1829 os.Symlink("../zip", realTemp+"/p2")
1831 // Circular references
1832 os.Symlink("p4", realTemp+"/p3")
1833 os.Symlink("p5", realTemp+"/p4")
1834 os.Symlink("p3", realTemp+"/p5")
1836 // Target doesn't exist
1837 os.Symlink("p99", realTemp+"/p6")
1839 for _, v := range []string{"p1", "p2", "p3", "p4", "p5"} {
1840 info, err := os.Lstat(realTemp + "/" + v)
1841 _, _, _, err = cr.derefOutputSymlink(realTemp+"/"+v, info)
1842 c.Assert(err, NotNil)
1846 func (s *TestSuite) TestEvalSymlinkDir(c *C) {
1847 cr := NewContainerRunner(&ArvTestClient{callraw: true}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1849 realTemp, err := ioutil.TempDir("", "crunchrun_test-")
1850 c.Assert(err, IsNil)
1851 defer os.RemoveAll(realTemp)
1853 cr.HostOutputDir = realTemp
1855 // Absolute path outside output dir
1856 os.Symlink(".", realTemp+"/loop")
1859 info, err := os.Lstat(realTemp + "/" + v)
1860 _, err = cr.UploadOutputFile(realTemp+"/"+v, info, err, []string{}, nil, "", "", 0)
1861 c.Assert(err, NotNil)
1864 func (s *TestSuite) TestFullBrokenDocker1(c *C) {
1865 tf, err := ioutil.TempFile("", "brokenNodeHook-")
1866 c.Assert(err, IsNil)
1867 defer os.Remove(tf.Name())
1869 tf.Write([]byte(`#!/bin/sh
1873 os.Chmod(tf.Name(), 0700)
1876 brokenNodeHook = &ech
1878 api, _, _ := FullRunHelper(c, `{
1879 "command": ["echo", "hello world"],
1880 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1883 "mounts": {"/tmp": {"kind": "tmp"} },
1884 "output_path": "/tmp",
1886 "runtime_constraints": {}
1887 }`, nil, 2, func(t *TestDockerClient) {
1888 t.logWriter.Write(dockerLog(1, "hello world\n"))
1892 c.Check(api.CalledWith("container.state", "Queued"), NotNil)
1893 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1894 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Running broken node hook.*")
1895 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*killme.*")
1899 func (s *TestSuite) TestFullBrokenDocker2(c *C) {
1901 brokenNodeHook = &ech
1903 api, _, _ := FullRunHelper(c, `{
1904 "command": ["echo", "hello world"],
1905 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1908 "mounts": {"/tmp": {"kind": "tmp"} },
1909 "output_path": "/tmp",
1911 "runtime_constraints": {}
1912 }`, nil, 2, func(t *TestDockerClient) {
1913 t.logWriter.Write(dockerLog(1, "hello world\n"))
1917 c.Check(api.CalledWith("container.state", "Queued"), NotNil)
1918 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1919 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*No broken node hook.*")
1922 func (s *TestSuite) TestFullBrokenDocker3(c *C) {
1924 brokenNodeHook = &ech
1926 api, _, _ := FullRunHelper(c, `{
1927 "command": ["echo", "hello world"],
1928 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1931 "mounts": {"/tmp": {"kind": "tmp"} },
1932 "output_path": "/tmp",
1934 "runtime_constraints": {}
1935 }`, nil, 3, func(t *TestDockerClient) {
1936 t.logWriter.Write(dockerLog(1, "hello world\n"))
1940 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1941 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1944 func (s *TestSuite) TestBadCommand1(c *C) {
1946 brokenNodeHook = &ech
1948 api, _, _ := FullRunHelper(c, `{
1949 "command": ["echo", "hello world"],
1950 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1953 "mounts": {"/tmp": {"kind": "tmp"} },
1954 "output_path": "/tmp",
1956 "runtime_constraints": {}
1957 }`, nil, 4, func(t *TestDockerClient) {
1958 t.logWriter.Write(dockerLog(1, "hello world\n"))
1962 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1963 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
1966 func (s *TestSuite) TestBadCommand2(c *C) {
1968 brokenNodeHook = &ech
1970 api, _, _ := FullRunHelper(c, `{
1971 "command": ["echo", "hello world"],
1972 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1975 "mounts": {"/tmp": {"kind": "tmp"} },
1976 "output_path": "/tmp",
1978 "runtime_constraints": {}
1979 }`, nil, 5, func(t *TestDockerClient) {
1980 t.logWriter.Write(dockerLog(1, "hello world\n"))
1984 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1985 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
1988 func (s *TestSuite) TestBadCommand3(c *C) {
1990 brokenNodeHook = &ech
1992 api, _, _ := FullRunHelper(c, `{
1993 "command": ["echo", "hello world"],
1994 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1997 "mounts": {"/tmp": {"kind": "tmp"} },
1998 "output_path": "/tmp",
2000 "runtime_constraints": {}
2001 }`, nil, 6, func(t *TestDockerClient) {
2002 t.logWriter.Write(dockerLog(1, "hello world\n"))
2006 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
2007 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")