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 are not allowed underneath 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", Writable: true},
1245 cr.OutputPath = "/tmp"
1247 err := cr.SetupMounts()
1248 c.Check(err, NotNil)
1249 c.Check(err, ErrorMatches, `Writable mount points are not permitted underneath the output_path.*`)
1250 os.RemoveAll(cr.ArvMountPoint)
1255 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1258 cr.ArvMountPoint = ""
1259 cr.Container.Mounts = make(map[string]arvados.Mount)
1260 cr.Container.Mounts = map[string]arvados.Mount{
1261 "/tmp": {Kind: "tmp"},
1262 "/tmp/foo": {Kind: "json"},
1264 cr.OutputPath = "/tmp"
1266 err := cr.SetupMounts()
1267 c.Check(err, NotNil)
1268 c.Check(err, ErrorMatches, `Only mount points of kind 'collection' are supported underneath the output_path.*`)
1269 os.RemoveAll(cr.ArvMountPoint)
1274 // Only mount point of kind 'collection' is allowed for stdin
1277 cr.ArvMountPoint = ""
1278 cr.Container.Mounts = make(map[string]arvados.Mount)
1279 cr.Container.Mounts = map[string]arvados.Mount{
1280 "stdin": {Kind: "tmp"},
1283 err := cr.SetupMounts()
1284 c.Check(err, NotNil)
1285 c.Check(err, ErrorMatches, `Unsupported mount kind 'tmp' for stdin.*`)
1286 os.RemoveAll(cr.ArvMountPoint)
1294 cr.ArvMountPoint = ""
1295 (*GitMountSuite)(nil).useTestGitServer(c)
1296 cr.token = arvadostest.ActiveToken
1297 cr.Container.Mounts = make(map[string]arvados.Mount)
1298 cr.Container.Mounts = map[string]arvados.Mount{
1301 UUID: arvadostest.Repository2UUID,
1302 Commit: "fd3531f42995344f36c30b79f55f27b502f3d344",
1307 UUID: arvadostest.Repository2UUID,
1308 Commit: "5ebfab0522851df01fec11ec55a6d0f4877b542e",
1312 cr.OutputPath = "/tmp"
1314 err := cr.SetupMounts()
1317 // dirMap[mountpoint] == tmpdir
1318 dirMap := make(map[string]string)
1319 for _, bind := range cr.Binds {
1320 tokens := strings.Split(bind, ":")
1321 dirMap[tokens[1]] = tokens[0]
1323 if cr.Container.Mounts[tokens[1]].Writable {
1324 c.Check(len(tokens), Equals, 2)
1326 c.Check(len(tokens), Equals, 3)
1327 c.Check(tokens[2], Equals, "ro")
1331 data, err := ioutil.ReadFile(dirMap["/tip"] + "/dir1/dir2/file with mode 0644")
1333 c.Check(string(data), Equals, "\000\001\002\003")
1334 _, err = ioutil.ReadFile(dirMap["/tip"] + "/file only on testbranch")
1335 c.Check(err, FitsTypeOf, &os.PathError{})
1336 c.Check(os.IsNotExist(err), Equals, true)
1338 data, err = ioutil.ReadFile(dirMap["/non-tip"] + "/dir1/dir2/file with mode 0644")
1340 c.Check(string(data), Equals, "\000\001\002\003")
1341 data, err = ioutil.ReadFile(dirMap["/non-tip"] + "/file only on testbranch")
1343 c.Check(string(data), Equals, "testfile\n")
1350 func (s *TestSuite) TestStdout(c *C) {
1352 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1353 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1355 "environment": {"FROBIZ": "bilbo"},
1356 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1357 "output_path": "/tmp",
1359 "runtime_constraints": {}
1362 api, _, _ := s.fullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1363 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1367 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1368 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1369 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1372 // Used by the TestStdoutWithWrongPath*()
1373 func (s *TestSuite) stdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1374 rec := arvados.Container{}
1375 err = json.Unmarshal([]byte(record), &rec)
1379 s.docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1381 api = &ArvTestClient{Container: rec}
1382 cr = NewContainerRunner(api, &KeepTestClient{}, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1383 am := &ArvMountCmdLine{}
1384 cr.RunArvMount = am.ArvMountTest
1390 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1391 _, _, err := s.stdoutErrorRunHelper(c, `{
1392 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1393 "output_path": "/tmp"
1394 }`, func(t *TestDockerClient) {})
1396 c.Check(err, NotNil)
1397 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1400 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1401 _, _, err := s.stdoutErrorRunHelper(c, `{
1402 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1403 "output_path": "/tmp"
1404 }`, func(t *TestDockerClient) {})
1406 c.Check(err, NotNil)
1407 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1410 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1411 _, _, err := s.stdoutErrorRunHelper(c, `{
1412 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1413 "output_path": "/tmp"
1414 }`, func(t *TestDockerClient) {})
1416 c.Check(err, NotNil)
1417 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1420 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1421 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1422 defer os.Unsetenv("ARVADOS_API_HOST")
1423 api, _, _ := s.fullRunHelper(c, `{
1424 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1425 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1428 "mounts": {"/tmp": {"kind": "tmp"} },
1429 "output_path": "/tmp",
1431 "runtime_constraints": {"API": true}
1432 }`, nil, 0, func(t *TestDockerClient) {
1433 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1437 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1438 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1439 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1440 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1443 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1444 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1445 defer os.Unsetenv("ARVADOS_API_HOST")
1446 api, _, _ := s.fullRunHelper(c, `{
1447 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1448 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1451 "mounts": {"/tmp": {"kind": "tmp"} },
1452 "output_path": "/tmp",
1454 "runtime_constraints": {"API": true}
1455 }`, nil, 0, func(t *TestDockerClient) {
1456 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1460 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1461 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1462 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1465 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1467 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1468 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1470 "environment": {"FROBIZ": "bilbo"},
1472 "/tmp": {"kind": "tmp"},
1473 "/tmp/foo": {"kind": "collection",
1474 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1475 "exclude_from_output": true
1477 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1479 "output_path": "/tmp",
1481 "runtime_constraints": {}
1484 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1486 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1487 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1491 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1492 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1493 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1496 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1498 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1499 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1501 "environment": {"FROBIZ": "bilbo"},
1503 "/tmp": {"kind": "tmp"},
1504 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1505 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1506 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1507 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1508 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1510 "output_path": "/tmp",
1512 "runtime_constraints": {}
1515 extraMounts := []string{
1516 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1517 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1518 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1521 api, runner, realtemp := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1522 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1526 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/2:/tmp",
1527 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1528 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1529 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1530 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1533 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1534 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1535 for _, v := range api.Content {
1536 if v["collection"] != nil {
1537 c.Check(v["ensure_unique_name"], Equals, true)
1538 collection := v["collection"].(arvadosclient.Dict)
1539 if strings.Index(collection["name"].(string), "output") == 0 {
1540 manifest := collection["manifest_text"].(string)
1542 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1543 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 9:18:bar 9:18:sub1file2
1544 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1545 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1546 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1553 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1555 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1556 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1558 "environment": {"FROBIZ": "bilbo"},
1560 "/tmp": {"kind": "tmp"},
1561 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt"},
1562 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1564 "output_path": "/tmp",
1566 "runtime_constraints": {}
1569 extraMounts := []string{
1570 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1573 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1574 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1578 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1579 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1580 for _, v := range api.Content {
1581 if v["collection"] != nil {
1582 collection := v["collection"].(arvadosclient.Dict)
1583 if strings.Index(collection["name"].(string), "output") == 0 {
1584 manifest := collection["manifest_text"].(string)
1586 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1587 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1594 func (s *TestSuite) TestOutputSymlinkToInput(c *C) {
1596 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1597 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1599 "environment": {"FROBIZ": "bilbo"},
1601 "/tmp": {"kind": "tmp"},
1602 "/keep/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path": "/subdir1/file2_in_subdir1.txt"},
1603 "/keep/foo2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367"}
1605 "output_path": "/tmp",
1607 "runtime_constraints": {}
1610 extraMounts := []string{
1611 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1614 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1615 os.Symlink("/keep/foo/sub1file2", t.realTemp+"/2/baz")
1616 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz2")
1617 os.Symlink("/keep/foo2/subdir1", t.realTemp+"/2/baz3")
1618 os.Mkdir(t.realTemp+"/2/baz4", 0700)
1619 os.Symlink("/keep/foo2/subdir1/file2_in_subdir1.txt", t.realTemp+"/2/baz4/baz5")
1623 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1624 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1625 for _, v := range api.Content {
1626 if v["collection"] != nil {
1627 collection := v["collection"].(arvadosclient.Dict)
1628 if strings.Index(collection["name"].(string), "output") == 0 {
1629 manifest := collection["manifest_text"].(string)
1630 c.Check(manifest, Equals, `. 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz 9:18:baz2
1631 ./baz3 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1632 ./baz3/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1633 ./baz4 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:baz5
1640 func (s *TestSuite) TestOutputError(c *C) {
1642 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1643 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1645 "environment": {"FROBIZ": "bilbo"},
1647 "/tmp": {"kind": "tmp"}
1649 "output_path": "/tmp",
1651 "runtime_constraints": {}
1654 extraMounts := []string{}
1656 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1657 os.Symlink("/etc/hosts", t.realTemp+"/2/baz")
1661 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1664 func (s *TestSuite) TestOutputSymlinkToOutput(c *C) {
1666 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1667 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1669 "environment": {"FROBIZ": "bilbo"},
1671 "/tmp": {"kind": "tmp"}
1673 "output_path": "/tmp",
1675 "runtime_constraints": {}
1678 extraMounts := []string{}
1680 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1681 rf, _ := os.Create(t.realTemp + "/2/realfile")
1682 rf.Write([]byte("foo"))
1685 os.Mkdir(t.realTemp+"/2/realdir", 0700)
1686 rf, _ = os.Create(t.realTemp + "/2/realdir/subfile")
1687 rf.Write([]byte("bar"))
1690 os.Symlink("/tmp/realfile", t.realTemp+"/2/file1")
1691 os.Symlink("realfile", t.realTemp+"/2/file2")
1692 os.Symlink("/tmp/file1", t.realTemp+"/2/file3")
1693 os.Symlink("file2", t.realTemp+"/2/file4")
1694 os.Symlink("realdir", t.realTemp+"/2/dir1")
1695 os.Symlink("/tmp/realdir", t.realTemp+"/2/dir2")
1699 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1700 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1701 for _, v := range api.Content {
1702 if v["collection"] != nil {
1703 collection := v["collection"].(arvadosclient.Dict)
1704 if strings.Index(collection["name"].(string), "output") == 0 {
1705 manifest := collection["manifest_text"].(string)
1706 c.Check(manifest, Equals,
1707 `. 7a2c86e102dcc231bd232aad99686dfa+15 0:3:file1 3:3:file2 6:3:file3 9:3:file4 12:3:realfile
1708 ./dir1 37b51d194a7513e45b56f6524f2d51f2+3 0:3:subfile
1709 ./dir2 37b51d194a7513e45b56f6524f2d51f2+3 0:3:subfile
1710 ./realdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:subfile
1717 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1719 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1720 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1722 "environment": {"FROBIZ": "bilbo"},
1724 "/tmp": {"kind": "tmp"},
1725 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1726 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1728 "output_path": "/tmp",
1730 "runtime_constraints": {}
1733 extraMounts := []string{
1734 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1737 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1738 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1742 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1743 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1744 for _, v := range api.Content {
1745 if v["collection"] != nil {
1746 collection := v["collection"].(arvadosclient.Dict)
1747 if strings.Index(collection["name"].(string), "output") == 0 {
1748 manifest := collection["manifest_text"].(string)
1749 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1756 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1758 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1759 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1761 "environment": {"FROBIZ": "bilbo"},
1763 "/tmp": {"kind": "tmp"},
1764 "stdin": {"kind": "json", "content": "foo"},
1765 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1767 "output_path": "/tmp",
1769 "runtime_constraints": {}
1772 api, _, _ := s.fullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1773 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1777 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1778 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1779 for _, v := range api.Content {
1780 if v["collection"] != nil {
1781 collection := v["collection"].(arvadosclient.Dict)
1782 if strings.Index(collection["name"].(string), "output") == 0 {
1783 manifest := collection["manifest_text"].(string)
1784 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1791 func (s *TestSuite) TestStderrMount(c *C) {
1792 api, _, _ := s.fullRunHelper(c, `{
1793 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
1794 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1797 "mounts": {"/tmp": {"kind": "tmp"},
1798 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
1799 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
1800 "output_path": "/tmp",
1802 "runtime_constraints": {}
1803 }`, nil, 1, func(t *TestDockerClient) {
1804 t.logWriter.Write(dockerLog(1, "hello\n"))
1805 t.logWriter.Write(dockerLog(2, "oops\n"))
1809 final := api.CalledWith("container.state", "Complete")
1810 c.Assert(final, NotNil)
1811 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1812 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1814 c.Check(api.CalledWith("collection.manifest_text", "./a b1946ac92492d2347c6235b4d2611184+6 0:6:out.txt\n./b 38af5c54926b620264ab1501150cf189+5 0:5:err.txt\n"), NotNil)
1817 func (s *TestSuite) TestNumberRoundTrip(c *C) {
1818 cr := NewContainerRunner(&ArvTestClient{callraw: true}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1819 cr.fetchContainerRecord()
1821 jsondata, err := json.Marshal(cr.Container.Mounts["/json"].Content)
1824 c.Check(string(jsondata), Equals, `{"number":123456789123456789}`)
1827 func (s *TestSuite) TestEvalSymlinks(c *C) {
1828 cr := NewContainerRunner(&ArvTestClient{callraw: true}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1830 realTemp, err := ioutil.TempDir("", "crunchrun_test-")
1831 c.Assert(err, IsNil)
1832 defer os.RemoveAll(realTemp)
1834 cr.HostOutputDir = realTemp
1836 // Absolute path outside output dir
1837 os.Symlink("/etc/passwd", realTemp+"/p1")
1839 // Relative outside output dir
1840 os.Symlink("../zip", realTemp+"/p2")
1842 // Circular references
1843 os.Symlink("p4", realTemp+"/p3")
1844 os.Symlink("p5", realTemp+"/p4")
1845 os.Symlink("p3", realTemp+"/p5")
1847 // Target doesn't exist
1848 os.Symlink("p99", realTemp+"/p6")
1850 for _, v := range []string{"p1", "p2", "p3", "p4", "p5"} {
1851 info, err := os.Lstat(realTemp + "/" + v)
1852 _, _, _, err = cr.derefOutputSymlink(realTemp+"/"+v, info)
1853 c.Assert(err, NotNil)
1857 func (s *TestSuite) TestEvalSymlinkDir(c *C) {
1858 cr := NewContainerRunner(&ArvTestClient{callraw: true}, &KeepTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1860 realTemp, err := ioutil.TempDir("", "crunchrun_test-")
1861 c.Assert(err, IsNil)
1862 defer os.RemoveAll(realTemp)
1864 cr.HostOutputDir = realTemp
1866 // Absolute path outside output dir
1867 os.Symlink(".", realTemp+"/loop")
1870 info, err := os.Lstat(realTemp + "/" + v)
1871 _, err = cr.UploadOutputFile(realTemp+"/"+v, info, err, []string{}, nil, "", "", 0)
1872 c.Assert(err, NotNil)
1875 func (s *TestSuite) TestFullBrokenDocker1(c *C) {
1876 tf, err := ioutil.TempFile("", "brokenNodeHook-")
1877 c.Assert(err, IsNil)
1878 defer os.Remove(tf.Name())
1880 tf.Write([]byte(`#!/bin/sh
1884 os.Chmod(tf.Name(), 0700)
1887 brokenNodeHook = &ech
1889 api, _, _ := s.fullRunHelper(c, `{
1890 "command": ["echo", "hello world"],
1891 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1894 "mounts": {"/tmp": {"kind": "tmp"} },
1895 "output_path": "/tmp",
1897 "runtime_constraints": {}
1898 }`, nil, 2, func(t *TestDockerClient) {
1899 t.logWriter.Write(dockerLog(1, "hello world\n"))
1903 c.Check(api.CalledWith("container.state", "Queued"), NotNil)
1904 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1905 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Running broken node hook.*")
1906 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*killme.*")
1910 func (s *TestSuite) TestFullBrokenDocker2(c *C) {
1912 brokenNodeHook = &ech
1914 api, _, _ := s.fullRunHelper(c, `{
1915 "command": ["echo", "hello world"],
1916 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1919 "mounts": {"/tmp": {"kind": "tmp"} },
1920 "output_path": "/tmp",
1922 "runtime_constraints": {}
1923 }`, nil, 2, func(t *TestDockerClient) {
1924 t.logWriter.Write(dockerLog(1, "hello world\n"))
1928 c.Check(api.CalledWith("container.state", "Queued"), NotNil)
1929 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1930 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*No broken node hook.*")
1933 func (s *TestSuite) TestFullBrokenDocker3(c *C) {
1935 brokenNodeHook = &ech
1937 api, _, _ := s.fullRunHelper(c, `{
1938 "command": ["echo", "hello world"],
1939 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1942 "mounts": {"/tmp": {"kind": "tmp"} },
1943 "output_path": "/tmp",
1945 "runtime_constraints": {}
1946 }`, nil, 3, func(t *TestDockerClient) {
1947 t.logWriter.Write(dockerLog(1, "hello world\n"))
1951 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1952 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1955 func (s *TestSuite) TestBadCommand1(c *C) {
1957 brokenNodeHook = &ech
1959 api, _, _ := s.fullRunHelper(c, `{
1960 "command": ["echo", "hello world"],
1961 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1964 "mounts": {"/tmp": {"kind": "tmp"} },
1965 "output_path": "/tmp",
1967 "runtime_constraints": {}
1968 }`, nil, 4, func(t *TestDockerClient) {
1969 t.logWriter.Write(dockerLog(1, "hello world\n"))
1973 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1974 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
1977 func (s *TestSuite) TestBadCommand2(c *C) {
1979 brokenNodeHook = &ech
1981 api, _, _ := s.fullRunHelper(c, `{
1982 "command": ["echo", "hello world"],
1983 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1986 "mounts": {"/tmp": {"kind": "tmp"} },
1987 "output_path": "/tmp",
1989 "runtime_constraints": {}
1990 }`, nil, 5, func(t *TestDockerClient) {
1991 t.logWriter.Write(dockerLog(1, "hello world\n"))
1995 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1996 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
1999 func (s *TestSuite) TestBadCommand3(c *C) {
2001 brokenNodeHook = &ech
2003 api, _, _ := s.fullRunHelper(c, `{
2004 "command": ["echo", "hello world"],
2005 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
2008 "mounts": {"/tmp": {"kind": "tmp"} },
2009 "output_path": "/tmp",
2011 "runtime_constraints": {}
2012 }`, nil, 6, func(t *TestDockerClient) {
2013 t.logWriter.Write(dockerLog(1, "hello world\n"))
2017 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
2018 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")