1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
27 "git.curoverse.com/arvados.git/sdk/go/arvados"
28 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
29 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
30 "git.curoverse.com/arvados.git/sdk/go/manifest"
31 "golang.org/x/net/context"
33 dockertypes "github.com/docker/docker/api/types"
34 dockercontainer "github.com/docker/docker/api/types/container"
35 dockernetwork "github.com/docker/docker/api/types/network"
39 // Gocheck boilerplate
40 func TestCrunchExec(t *testing.T) {
44 // Gocheck boilerplate
45 var _ = Suite(&TestSuite{})
47 type TestSuite struct {
48 client *arvados.Client
49 docker *TestDockerClient
52 func (s *TestSuite) SetUpTest(c *C) {
53 s.client = arvados.NewClientFromEnv()
54 s.docker = NewTestDockerClient()
57 type ArvTestClient struct {
60 Content []arvadosclient.Dict
63 Logs map[string]*bytes.Buffer
69 type KeepTestClient struct {
74 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
75 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
76 var hwImageId = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
78 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
79 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
81 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
82 ./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
83 ./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
86 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
88 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"
89 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
91 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
92 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
94 type TestDockerClient struct {
96 logReader io.ReadCloser
97 logWriter io.WriteCloser
98 fn func(t *TestDockerClient)
108 func NewTestDockerClient() *TestDockerClient {
109 t := &TestDockerClient{}
110 t.logReader, t.logWriter = io.Pipe()
111 t.stop = make(chan bool, 1)
116 type MockConn struct {
120 func (m *MockConn) Write(b []byte) (int, error) {
124 func NewMockConn() *MockConn {
129 func (t *TestDockerClient) ContainerAttach(ctx context.Context, container string, options dockertypes.ContainerAttachOptions) (dockertypes.HijackedResponse, error) {
130 return dockertypes.HijackedResponse{Conn: NewMockConn(), Reader: bufio.NewReader(t.logReader)}, nil
133 func (t *TestDockerClient) ContainerCreate(ctx context.Context, config *dockercontainer.Config, hostConfig *dockercontainer.HostConfig, networkingConfig *dockernetwork.NetworkingConfig, containerName string) (dockercontainer.ContainerCreateCreatedBody, error) {
134 if config.WorkingDir != "" {
135 t.cwd = config.WorkingDir
138 return dockercontainer.ContainerCreateCreatedBody{ID: "abcde"}, nil
141 func (t *TestDockerClient) ContainerStart(ctx context.Context, container string, options dockertypes.ContainerStartOptions) error {
143 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\\\"\""`)
146 return errors.New(`panic: standard_init_linux.go:175: exec user process caused "no such file or directory"`)
149 return errors.New(`Error response from daemon: Cannot start container 41f26cbc43bcc1280f4323efb1830a394ba8660c9d1c2b564ba42bf7f7694845: [8] System error: no such file or directory`)
152 return errors.New(`Error response from daemon: Cannot start container 58099cd76c834f3dc2a4fb76c8028f049ae6d4fdf0ec373e1f2cfea030670c2d: [8] System error: exec: "foobar": executable file not found in $PATH`)
155 if container == "abcde" {
156 // t.fn gets executed in ContainerWait
159 return errors.New("Invalid container id")
163 func (t *TestDockerClient) ContainerRemove(ctx context.Context, container string, options dockertypes.ContainerRemoveOptions) error {
168 func (t *TestDockerClient) ContainerWait(ctx context.Context, container string, condition dockercontainer.WaitCondition) (<-chan dockercontainer.ContainerWaitOKBody, <-chan error) {
170 body := make(chan dockercontainer.ContainerWaitOKBody, 1)
171 err := make(chan error)
174 body <- dockercontainer.ContainerWaitOKBody{StatusCode: int64(t.exitCode)}
179 func (t *TestDockerClient) ImageInspectWithRaw(ctx context.Context, image string) (dockertypes.ImageInspect, []byte, error) {
181 return dockertypes.ImageInspect{}, nil, fmt.Errorf("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
184 if t.imageLoaded == image {
185 return dockertypes.ImageInspect{}, nil, nil
187 return dockertypes.ImageInspect{}, nil, errors.New("")
191 func (t *TestDockerClient) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (dockertypes.ImageLoadResponse, error) {
193 return dockertypes.ImageLoadResponse{}, fmt.Errorf("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
195 _, err := io.Copy(ioutil.Discard, input)
197 return dockertypes.ImageLoadResponse{}, err
199 t.imageLoaded = hwImageId
200 return dockertypes.ImageLoadResponse{Body: ioutil.NopCloser(input)}, nil
204 func (*TestDockerClient) ImageRemove(ctx context.Context, image string, options dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {
208 func (client *ArvTestClient) Create(resourceType string,
209 parameters arvadosclient.Dict,
210 output interface{}) error {
213 defer client.Mutex.Unlock()
216 client.Content = append(client.Content, parameters)
218 if resourceType == "logs" {
219 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
220 if client.Logs == nil {
221 client.Logs = make(map[string]*bytes.Buffer)
223 if client.Logs[et] == nil {
224 client.Logs[et] = &bytes.Buffer{}
226 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
229 if resourceType == "collections" && output != nil {
230 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
231 outmap := output.(*arvados.Collection)
232 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
238 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
240 case method == "GET" && resourceType == "containers" && action == "auth":
241 return json.Unmarshal([]byte(`{
242 "kind": "arvados#api_client_authorization",
243 "uuid": "`+fakeAuthUUID+`",
244 "api_token": "`+fakeAuthToken+`"
246 case method == "GET" && resourceType == "containers" && action == "secret_mounts":
247 if client.secretMounts != nil {
248 return json.Unmarshal(client.secretMounts, output)
250 return json.Unmarshal([]byte(`{"secret_mounts":{}}`), output)
253 return fmt.Errorf("Not found")
257 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
258 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
260 if method == "GET" && resourceType == "nodes" && uuid == "" && action == "" {
262 "kind": "arvados#nodeList",
264 "uuid": "zzzzz-7ekkf-2z3mc76g2q73aio",
265 "hostname": "compute2",
266 "properties": {"total_cpu_cores": 16}
268 } else if method == "GET" && resourceType == "containers" && action == "" && !client.callraw {
270 j, err = json.Marshal(map[string]interface{}{
271 "items": []interface{}{client.Container},
272 "kind": "arvados#nodeList",
275 j, err = json.Marshal(client.Container)
279 "command": ["sleep", "1"],
280 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
283 "mounts": {"/tmp": {"kind": "tmp"}, "/json": {"kind": "json", "content": {"number": 123456789123456789}}},
284 "output_path": "/tmp",
286 "runtime_constraints": {}
289 return ioutil.NopCloser(bytes.NewReader(j)), err
292 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
293 if resourceType == "collections" {
295 output.(*arvados.Collection).ManifestText = hwManifest
296 } else if uuid == otherPDH {
297 output.(*arvados.Collection).ManifestText = otherManifest
298 } else if uuid == normalizedWithSubdirsPDH {
299 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
300 } else if uuid == denormalizedWithSubdirsPDH {
301 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
304 if resourceType == "containers" {
305 (*output.(*arvados.Container)) = client.Container
310 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
312 defer client.Mutex.Unlock()
314 client.Content = append(client.Content, parameters)
315 if resourceType == "containers" {
316 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
317 client.WasSetRunning = true
323 var discoveryMap = map[string]interface{}{
324 "defaultTrashLifetime": float64(1209600),
325 "crunchLimitLogBytesPerJob": float64(67108864),
326 "crunchLogThrottleBytes": float64(65536),
327 "crunchLogThrottlePeriod": float64(60),
328 "crunchLogThrottleLines": float64(1024),
329 "crunchLogPartialLineThrottlePeriod": float64(5),
330 "crunchLogBytesPerEvent": float64(4096),
331 "crunchLogSecondsBetweenEvents": float64(1),
334 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
335 return discoveryMap[key], nil
338 // CalledWith returns the parameters from the first API call whose
339 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
340 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
341 // no call matches, it returns nil.
342 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
344 for _, content := range client.Content {
345 var v interface{} = content
346 for _, k := range strings.Split(jpath, ".") {
347 if dict, ok := v.(arvadosclient.Dict); !ok {
360 func (client *KeepTestClient) PutB(buf []byte) (string, int, error) {
362 return fmt.Sprintf("%x+%d", md5.Sum(buf), len(buf)), len(buf), nil
365 func (client *KeepTestClient) ReadAt(string, []byte, int) (int, error) {
366 return 0, errors.New("not implemented")
369 func (client *KeepTestClient) ClearBlockCache() {
372 func (client *KeepTestClient) Close() {
376 type FileWrapper struct {
381 func (fw FileWrapper) Readdir(n int) ([]os.FileInfo, error) {
382 return nil, errors.New("not implemented")
385 func (fw FileWrapper) Seek(int64, int) (int64, error) {
386 return 0, errors.New("not implemented")
389 func (fw FileWrapper) Size() int64 {
393 func (fw FileWrapper) Stat() (os.FileInfo, error) {
394 return nil, errors.New("not implemented")
397 func (fw FileWrapper) Truncate(int64) error {
398 return errors.New("not implemented")
401 func (fw FileWrapper) Write([]byte) (int, error) {
402 return 0, errors.New("not implemented")
405 func (fw FileWrapper) Sync() error {
406 return errors.New("not implemented")
409 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
410 if filename == hwImageId+".tar" {
411 rdr := ioutil.NopCloser(&bytes.Buffer{})
413 return FileWrapper{rdr, 1321984}, nil
414 } else if filename == "/file1_in_main.txt" {
415 rdr := ioutil.NopCloser(strings.NewReader("foo"))
417 return FileWrapper{rdr, 3}, nil
422 func (s *TestSuite) TestLoadImage(c *C) {
423 kc := &KeepTestClient{}
425 cr, err := NewContainerRunner(s.client, &ArvTestClient{}, kc, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
428 _, err = cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
431 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
434 cr.Container.ContainerImage = hwPDH
436 // (1) Test loading image from keep
437 c.Check(kc.Called, Equals, false)
438 c.Check(cr.ContainerConfig.Image, Equals, "")
444 cr.Docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
447 c.Check(kc.Called, Equals, true)
448 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
450 _, _, err = cr.Docker.ImageInspectWithRaw(nil, hwImageId)
453 // (2) Test using image that's already loaded
455 cr.ContainerConfig.Image = ""
459 c.Check(kc.Called, Equals, false)
460 c.Check(cr.ContainerConfig.Image, Equals, hwImageId)
464 type ArvErrorTestClient struct{}
466 func (ArvErrorTestClient) Create(resourceType string,
467 parameters arvadosclient.Dict,
468 output interface{}) error {
472 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
473 return errors.New("ArvError")
476 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
477 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
478 return nil, errors.New("ArvError")
481 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
482 return errors.New("ArvError")
485 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
489 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
490 return discoveryMap[key], nil
493 type KeepErrorTestClient struct {
497 func (*KeepErrorTestClient) ManifestFileReader(manifest.Manifest, string) (arvados.File, error) {
498 return nil, errors.New("KeepError")
501 func (*KeepErrorTestClient) PutB(buf []byte) (string, int, error) {
502 return "", 0, errors.New("KeepError")
505 type KeepReadErrorTestClient struct {
509 func (*KeepReadErrorTestClient) ReadAt(string, []byte, int) (int, error) {
510 return 0, errors.New("KeepError")
513 type ErrorReader struct {
517 func (ErrorReader) Read(p []byte) (n int, err error) {
518 return 0, errors.New("ErrorReader")
521 func (ErrorReader) Seek(int64, int) (int64, error) {
522 return 0, errors.New("ErrorReader")
525 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
526 return ErrorReader{}, nil
529 func (s *TestSuite) TestLoadImageArvError(c *C) {
531 kc := &KeepTestClient{}
533 cr, err := NewContainerRunner(s.client, ArvErrorTestClient{}, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
535 cr.Container.ContainerImage = hwPDH
538 c.Check(err.Error(), Equals, "While getting container image collection: ArvError")
541 func (s *TestSuite) TestLoadImageKeepError(c *C) {
543 cr, err := NewContainerRunner(s.client, &ArvTestClient{}, &KeepErrorTestClient{}, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
545 cr.Container.ContainerImage = hwPDH
548 c.Assert(err, NotNil)
549 c.Check(err.Error(), Equals, "While creating ManifestFileReader for container image: KeepError")
552 func (s *TestSuite) TestLoadImageCollectionError(c *C) {
553 // (3) Collection doesn't contain image
554 cr, err := NewContainerRunner(s.client, &ArvTestClient{}, &KeepReadErrorTestClient{}, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
556 cr.Container.ContainerImage = otherPDH
559 c.Check(err.Error(), Equals, "First file in the container image collection does not end in .tar")
562 func (s *TestSuite) TestLoadImageKeepReadError(c *C) {
563 // (4) Collection doesn't contain image
564 cr, err := NewContainerRunner(s.client, &ArvTestClient{}, &KeepReadErrorTestClient{}, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
566 cr.Container.ContainerImage = hwPDH
572 type ClosableBuffer struct {
576 func (*ClosableBuffer) Close() error {
580 type TestLogs struct {
581 Stdout ClosableBuffer
582 Stderr ClosableBuffer
585 func (tl *TestLogs) NewTestLoggingWriter(logstr string) (io.WriteCloser, error) {
586 if logstr == "stdout" {
587 return &tl.Stdout, nil
589 if logstr == "stderr" {
590 return &tl.Stderr, nil
592 return nil, errors.New("???")
595 func dockerLog(fd byte, msg string) []byte {
597 header := make([]byte, 8+len(by))
599 header[7] = byte(len(by))
604 func (s *TestSuite) TestRunContainer(c *C) {
605 s.docker.fn = func(t *TestDockerClient) {
606 t.logWriter.Write(dockerLog(1, "Hello world\n"))
609 kc := &KeepTestClient{}
611 cr, err := NewContainerRunner(s.client, &ArvTestClient{}, kc, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
615 cr.NewLogWriter = logs.NewTestLoggingWriter
616 cr.Container.ContainerImage = hwPDH
617 cr.Container.Command = []string{"./hw"}
621 err = cr.CreateContainer()
624 err = cr.StartContainer()
627 err = cr.WaitFinish()
630 c.Check(strings.HasSuffix(logs.Stdout.String(), "Hello world\n"), Equals, true)
631 c.Check(logs.Stderr.String(), Equals, "")
634 func (s *TestSuite) TestCommitLogs(c *C) {
635 api := &ArvTestClient{}
636 kc := &KeepTestClient{}
638 cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
640 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
642 cr.CrunchLog.Print("Hello world!")
643 cr.CrunchLog.Print("Goodbye")
644 cr.finalState = "Complete"
646 err = cr.CommitLogs()
649 c.Check(api.Calls, Equals, 2)
650 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
651 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
652 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
653 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
656 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
657 api := &ArvTestClient{}
658 kc := &KeepTestClient{}
660 cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
663 err = cr.UpdateContainerRunning()
666 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
669 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
670 api := &ArvTestClient{}
671 kc := &KeepTestClient{}
673 cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
676 cr.LogsPDH = new(string)
677 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
679 cr.ExitCode = new(int)
681 cr.finalState = "Complete"
683 err = cr.UpdateContainerFinal()
686 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
687 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
688 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
691 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
692 api := &ArvTestClient{}
693 kc := &KeepTestClient{}
695 cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
698 cr.finalState = "Cancelled"
700 err = cr.UpdateContainerFinal()
703 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
704 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
705 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
708 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
709 // dress rehearsal of the Run() function, starting from a JSON container record.
710 func (s *TestSuite) fullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, realTemp string) {
711 rec := arvados.Container{}
712 err := json.Unmarshal([]byte(record), &rec)
716 SecretMounts map[string]arvados.Mount `json:"secret_mounts"`
718 err = json.Unmarshal([]byte(record), &sm)
720 secretMounts, err := json.Marshal(sm)
721 c.Logf("%s %q", sm, secretMounts)
724 s.docker.exitCode = exitCode
726 s.docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
728 api = &ArvTestClient{Container: rec}
730 kc := &KeepTestClient{}
732 cr, err = NewContainerRunner(s.client, api, kc, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
734 cr.statInterval = 100 * time.Millisecond
735 am := &ArvMountCmdLine{}
736 cr.RunArvMount = am.ArvMountTest
738 realTemp, err = ioutil.TempDir("", "crunchrun_test1-")
740 defer os.RemoveAll(realTemp)
742 s.docker.realTemp = realTemp
745 cr.MkTempDir = func(_ string, prefix string) (string, error) {
747 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
748 err := os.Mkdir(d, os.ModePerm)
749 if err != nil && strings.Contains(err.Error(), ": file exists") {
750 // Test case must have pre-populated the tempdir
755 cr.MkArvClient = func(token string) (IArvadosClient, error) {
756 return &ArvTestClient{secretMounts: secretMounts}, nil
759 if extraMounts != nil && len(extraMounts) > 0 {
760 err := cr.SetupArvMountPoint("keep")
763 for _, m := range extraMounts {
764 os.MkdirAll(cr.ArvMountPoint+"/by_id/"+m, os.ModePerm)
769 if api.CalledWith("container.state", "Complete") != nil {
773 c.Check(api.WasSetRunning, Equals, true)
774 c.Check(api.Content[api.Calls-2]["container"].(arvadosclient.Dict)["log"], NotNil)
778 for k, v := range api.Logs {
787 func (s *TestSuite) TestFullRunHello(c *C) {
788 api, _, _ := s.fullRunHelper(c, `{
789 "command": ["echo", "hello world"],
790 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
793 "mounts": {"/tmp": {"kind": "tmp"} },
794 "output_path": "/tmp",
796 "runtime_constraints": {}
797 }`, nil, 0, func(t *TestDockerClient) {
798 t.logWriter.Write(dockerLog(1, "hello world\n"))
802 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
803 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
804 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello world\n"), Equals, true)
808 func (s *TestSuite) TestCrunchstat(c *C) {
809 api, _, _ := s.fullRunHelper(c, `{
810 "command": ["sleep", "1"],
811 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
814 "mounts": {"/tmp": {"kind": "tmp"} },
815 "output_path": "/tmp",
817 "runtime_constraints": {}
818 }`, nil, 0, func(t *TestDockerClient) {
819 time.Sleep(time.Second)
823 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
824 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
826 // We didn't actually start a container, so crunchstat didn't
827 // find accounting files and therefore didn't log any stats.
828 // It should have logged a "can't find accounting files"
829 // message after one poll interval, though, so we can confirm
831 c.Assert(api.Logs["crunchstat"], NotNil)
832 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
834 // The "files never appeared" log assures us that we called
835 // (*crunchstat.Reporter)Stop(), and that we set it up with
836 // the correct container ID "abcde":
837 c.Check(api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for abcde\n`)
840 func (s *TestSuite) TestNodeInfoLog(c *C) {
841 os.Setenv("SLURMD_NODENAME", "compute2")
842 api, _, _ := s.fullRunHelper(c, `{
843 "command": ["sleep", "1"],
844 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
847 "mounts": {"/tmp": {"kind": "tmp"} },
848 "output_path": "/tmp",
850 "runtime_constraints": {}
852 func(t *TestDockerClient) {
853 time.Sleep(time.Second)
857 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
858 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
860 c.Assert(api.Logs["node"], NotNil)
861 json := api.Logs["node"].String()
862 c.Check(json, Matches, `(?ms).*"uuid": *"zzzzz-7ekkf-2z3mc76g2q73aio".*`)
863 c.Check(json, Matches, `(?ms).*"total_cpu_cores": *16.*`)
864 c.Check(json, Not(Matches), `(?ms).*"info":.*`)
866 c.Assert(api.Logs["node-info"], NotNil)
867 json = api.Logs["node-info"].String()
868 c.Check(json, Matches, `(?ms).*Host Information.*`)
869 c.Check(json, Matches, `(?ms).*CPU Information.*`)
870 c.Check(json, Matches, `(?ms).*Memory Information.*`)
871 c.Check(json, Matches, `(?ms).*Disk Space.*`)
872 c.Check(json, Matches, `(?ms).*Disk INodes.*`)
875 func (s *TestSuite) TestContainerRecordLog(c *C) {
876 api, _, _ := s.fullRunHelper(c, `{
877 "command": ["sleep", "1"],
878 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
881 "mounts": {"/tmp": {"kind": "tmp"} },
882 "output_path": "/tmp",
884 "runtime_constraints": {}
886 func(t *TestDockerClient) {
887 time.Sleep(time.Second)
891 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
892 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
894 c.Assert(api.Logs["container"], NotNil)
895 c.Check(api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
898 func (s *TestSuite) TestFullRunStderr(c *C) {
899 api, _, _ := s.fullRunHelper(c, `{
900 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
901 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
904 "mounts": {"/tmp": {"kind": "tmp"} },
905 "output_path": "/tmp",
907 "runtime_constraints": {}
908 }`, nil, 1, func(t *TestDockerClient) {
909 t.logWriter.Write(dockerLog(1, "hello\n"))
910 t.logWriter.Write(dockerLog(2, "world\n"))
914 final := api.CalledWith("container.state", "Complete")
915 c.Assert(final, NotNil)
916 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
917 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
919 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "hello\n"), Equals, true)
920 c.Check(strings.HasSuffix(api.Logs["stderr"].String(), "world\n"), Equals, true)
923 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
924 api, _, _ := s.fullRunHelper(c, `{
926 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
929 "mounts": {"/tmp": {"kind": "tmp"} },
930 "output_path": "/tmp",
932 "runtime_constraints": {}
933 }`, nil, 0, func(t *TestDockerClient) {
934 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
938 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
939 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
940 c.Log(api.Logs["stdout"])
941 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/\n"), Equals, true)
944 func (s *TestSuite) TestFullRunSetCwd(c *C) {
945 api, _, _ := s.fullRunHelper(c, `{
947 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
950 "mounts": {"/tmp": {"kind": "tmp"} },
951 "output_path": "/tmp",
953 "runtime_constraints": {}
954 }`, nil, 0, func(t *TestDockerClient) {
955 t.logWriter.Write(dockerLog(1, t.cwd+"\n"))
959 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
960 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
961 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "/bin\n"), Equals, true)
964 func (s *TestSuite) TestStopOnSignal(c *C) {
965 s.testStopContainer(c, func(cr *ContainerRunner) {
967 for !s.docker.calledWait {
968 time.Sleep(time.Millisecond)
970 cr.SigChan <- syscall.SIGINT
975 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
976 s.testStopContainer(c, func(cr *ContainerRunner) {
977 cr.ArvMountExit = make(chan error)
979 cr.ArvMountExit <- exec.Command("true").Run()
980 close(cr.ArvMountExit)
985 func (s *TestSuite) testStopContainer(c *C, setup func(cr *ContainerRunner)) {
987 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
988 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
991 "mounts": {"/tmp": {"kind": "tmp"} },
992 "output_path": "/tmp",
994 "runtime_constraints": {}
997 rec := arvados.Container{}
998 err := json.Unmarshal([]byte(record), &rec)
1001 s.docker.fn = func(t *TestDockerClient) {
1003 t.logWriter.Write(dockerLog(1, "foo\n"))
1006 s.docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1008 api := &ArvTestClient{Container: rec}
1009 kc := &KeepTestClient{}
1011 cr, err := NewContainerRunner(s.client, api, kc, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1012 c.Assert(err, IsNil)
1013 cr.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
1014 cr.MkArvClient = func(token string) (IArvadosClient, error) {
1015 return &ArvTestClient{}, nil
1019 done := make(chan error)
1024 case <-time.After(20 * time.Second):
1025 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
1026 c.Fatal("timed out")
1030 for k, v := range api.Logs {
1035 c.Check(api.CalledWith("container.log", nil), NotNil)
1036 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1037 c.Check(api.Logs["stdout"].String(), Matches, "(?ms).*foo\n$")
1040 func (s *TestSuite) TestFullRunSetEnv(c *C) {
1041 api, _, _ := s.fullRunHelper(c, `{
1042 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1043 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1045 "environment": {"FROBIZ": "bilbo"},
1046 "mounts": {"/tmp": {"kind": "tmp"} },
1047 "output_path": "/tmp",
1049 "runtime_constraints": {}
1050 }`, nil, 0, func(t *TestDockerClient) {
1051 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1055 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1056 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1057 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "bilbo\n"), Equals, true)
1060 type ArvMountCmdLine struct {
1065 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
1071 func stubCert(temp string) string {
1072 path := temp + "/ca-certificates.crt"
1073 crt, _ := os.Create(path)
1075 arvadosclient.CertFiles = []string{path}
1079 func (s *TestSuite) TestSetupMounts(c *C) {
1080 api := &ArvTestClient{}
1081 kc := &KeepTestClient{}
1083 cr, err := NewContainerRunner(s.client, api, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1084 c.Assert(err, IsNil)
1085 am := &ArvMountCmdLine{}
1086 cr.RunArvMount = am.ArvMountTest
1088 realTemp, err := ioutil.TempDir("", "crunchrun_test1-")
1089 c.Assert(err, IsNil)
1090 certTemp, err := ioutil.TempDir("", "crunchrun_test2-")
1091 c.Assert(err, IsNil)
1092 stubCertPath := stubCert(certTemp)
1094 cr.parentTemp = realTemp
1096 defer os.RemoveAll(realTemp)
1097 defer os.RemoveAll(certTemp)
1100 cr.MkTempDir = func(_ string, prefix string) (string, error) {
1102 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
1103 err := os.Mkdir(d, os.ModePerm)
1104 if err != nil && strings.Contains(err.Error(), ": file exists") {
1105 // Test case must have pre-populated the tempdir
1111 checkEmpty := func() {
1112 // Should be deleted.
1113 _, err := os.Stat(realTemp)
1114 c.Assert(os.IsNotExist(err), Equals, true)
1116 // Now recreate it for the next test.
1117 c.Assert(os.Mkdir(realTemp, 0777), IsNil)
1122 cr.ArvMountPoint = ""
1123 cr.Container.Mounts = make(map[string]arvados.Mount)
1124 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1125 cr.OutputPath = "/tmp"
1126 cr.statInterval = 5 * time.Second
1127 err := cr.SetupMounts()
1129 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1130 "--read-write", "--crunchstat-interval=5",
1131 "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1132 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/tmp2:/tmp"})
1133 os.RemoveAll(cr.ArvMountPoint)
1140 cr.ArvMountPoint = ""
1141 cr.Container.Mounts = make(map[string]arvados.Mount)
1142 cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"}
1143 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1144 cr.OutputPath = "/out"
1146 err := cr.SetupMounts()
1148 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1149 "--read-write", "--crunchstat-interval=5",
1150 "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1151 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/tmp2:/out", realTemp + "/tmp3:/tmp"})
1152 os.RemoveAll(cr.ArvMountPoint)
1159 cr.ArvMountPoint = ""
1160 cr.Container.Mounts = make(map[string]arvados.Mount)
1161 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1162 cr.OutputPath = "/tmp"
1165 cr.Container.RuntimeConstraints.API = &apiflag
1167 err := cr.SetupMounts()
1169 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1170 "--read-write", "--crunchstat-interval=5",
1171 "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1172 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/tmp2:/tmp", stubCertPath + ":/etc/arvados/ca-certificates.crt:ro"})
1173 os.RemoveAll(cr.ArvMountPoint)
1182 cr.ArvMountPoint = ""
1183 cr.Container.Mounts = map[string]arvados.Mount{
1184 "/keeptmp": {Kind: "collection", Writable: true},
1186 cr.OutputPath = "/keeptmp"
1188 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1190 err := cr.SetupMounts()
1192 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1193 "--read-write", "--crunchstat-interval=5",
1194 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1195 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/tmp0:/keeptmp"})
1196 os.RemoveAll(cr.ArvMountPoint)
1203 cr.ArvMountPoint = ""
1204 cr.Container.Mounts = map[string]arvados.Mount{
1205 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1206 "/keepout": {Kind: "collection", Writable: true},
1208 cr.OutputPath = "/keepout"
1210 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
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 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1218 sort.StringSlice(cr.Binds).Sort()
1219 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1220 realTemp + "/keep1/tmp0:/keepout"})
1221 os.RemoveAll(cr.ArvMountPoint)
1228 cr.ArvMountPoint = ""
1229 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1230 cr.Container.Mounts = map[string]arvados.Mount{
1231 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1232 "/keepout": {Kind: "collection", Writable: true},
1234 cr.OutputPath = "/keepout"
1236 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1237 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1239 err := cr.SetupMounts()
1241 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1242 "--read-write", "--crunchstat-interval=5",
1243 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1244 sort.StringSlice(cr.Binds).Sort()
1245 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53:/keepinp:ro",
1246 realTemp + "/keep1/tmp0:/keepout"})
1247 os.RemoveAll(cr.ArvMountPoint)
1252 for _, test := range []struct {
1256 {in: "foo", out: `"foo"`},
1257 {in: nil, out: `null`},
1258 {in: map[string]int64{"foo": 123456789123456789}, out: `{"foo":123456789123456789}`},
1261 cr.ArvMountPoint = ""
1262 cr.Container.Mounts = map[string]arvados.Mount{
1263 "/mnt/test.json": {Kind: "json", Content: test.in},
1265 err := cr.SetupMounts()
1267 sort.StringSlice(cr.Binds).Sort()
1268 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/json2/mountdata.json:/mnt/test.json:ro"})
1269 content, err := ioutil.ReadFile(realTemp + "/json2/mountdata.json")
1271 c.Check(content, DeepEquals, []byte(test.out))
1272 os.RemoveAll(cr.ArvMountPoint)
1277 for _, test := range []struct {
1281 {in: "foo", out: `foo`},
1282 {in: nil, out: "error"},
1283 {in: map[string]int64{"foo": 123456789123456789}, out: "error"},
1286 cr.ArvMountPoint = ""
1287 cr.Container.Mounts = map[string]arvados.Mount{
1288 "/mnt/test.txt": {Kind: "text", Content: test.in},
1290 err := cr.SetupMounts()
1291 if test.out == "error" {
1292 c.Check(err.Error(), Equals, "content for mount \"/mnt/test.txt\" must be a string")
1295 sort.StringSlice(cr.Binds).Sort()
1296 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/text2/mountdata.text:/mnt/test.txt:ro"})
1297 content, err := ioutil.ReadFile(realTemp + "/text2/mountdata.text")
1299 c.Check(content, DeepEquals, []byte(test.out))
1301 os.RemoveAll(cr.ArvMountPoint)
1306 // Read-only mount points are allowed underneath output_dir mount point
1309 cr.ArvMountPoint = ""
1310 cr.Container.Mounts = make(map[string]arvados.Mount)
1311 cr.Container.Mounts = map[string]arvados.Mount{
1312 "/tmp": {Kind: "tmp"},
1313 "/tmp/foo": {Kind: "collection"},
1315 cr.OutputPath = "/tmp"
1317 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1319 err := cr.SetupMounts()
1321 c.Check(am.Cmd, DeepEquals, []string{"--foreground", "--allow-other",
1322 "--read-write", "--crunchstat-interval=5",
1323 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", realTemp + "/keep1"})
1324 c.Check(cr.Binds, DeepEquals, []string{realTemp + "/tmp2:/tmp", realTemp + "/keep1/tmp0:/tmp/foo:ro"})
1325 os.RemoveAll(cr.ArvMountPoint)
1330 // Writable mount points copied to output_dir mount point
1333 cr.ArvMountPoint = ""
1334 cr.Container.Mounts = make(map[string]arvados.Mount)
1335 cr.Container.Mounts = map[string]arvados.Mount{
1336 "/tmp": {Kind: "tmp"},
1337 "/tmp/foo": {Kind: "collection",
1338 PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53",
1340 "/tmp/bar": {Kind: "collection",
1341 PortableDataHash: "59389a8f9ee9d399be35462a0f92541d+53",
1345 cr.OutputPath = "/tmp"
1347 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1348 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz", os.ModePerm)
1350 rf, _ := os.Create(realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz/quux")
1351 rf.Write([]byte("bar"))
1354 err := cr.SetupMounts()
1356 _, err = os.Stat(cr.HostOutputDir + "/foo")
1358 _, err = os.Stat(cr.HostOutputDir + "/bar/quux")
1360 os.RemoveAll(cr.ArvMountPoint)
1365 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1368 cr.ArvMountPoint = ""
1369 cr.Container.Mounts = make(map[string]arvados.Mount)
1370 cr.Container.Mounts = map[string]arvados.Mount{
1371 "/tmp": {Kind: "tmp"},
1372 "/tmp/foo": {Kind: "tmp"},
1374 cr.OutputPath = "/tmp"
1376 err := cr.SetupMounts()
1377 c.Check(err, NotNil)
1378 c.Check(err, ErrorMatches, `Only mount points of kind 'collection', 'text' or 'json' are supported underneath the output_path.*`)
1379 os.RemoveAll(cr.ArvMountPoint)
1384 // Only mount point of kind 'collection' is allowed for stdin
1387 cr.ArvMountPoint = ""
1388 cr.Container.Mounts = make(map[string]arvados.Mount)
1389 cr.Container.Mounts = map[string]arvados.Mount{
1390 "stdin": {Kind: "tmp"},
1393 err := cr.SetupMounts()
1394 c.Check(err, NotNil)
1395 c.Check(err, ErrorMatches, `Unsupported mount kind 'tmp' for stdin.*`)
1396 os.RemoveAll(cr.ArvMountPoint)
1404 cr.ArvMountPoint = ""
1405 (*GitMountSuite)(nil).useTestGitServer(c)
1406 cr.token = arvadostest.ActiveToken
1407 cr.Container.Mounts = make(map[string]arvados.Mount)
1408 cr.Container.Mounts = map[string]arvados.Mount{
1411 UUID: arvadostest.Repository2UUID,
1412 Commit: "fd3531f42995344f36c30b79f55f27b502f3d344",
1417 UUID: arvadostest.Repository2UUID,
1418 Commit: "5ebfab0522851df01fec11ec55a6d0f4877b542e",
1422 cr.OutputPath = "/tmp"
1424 err := cr.SetupMounts()
1427 // dirMap[mountpoint] == tmpdir
1428 dirMap := make(map[string]string)
1429 for _, bind := range cr.Binds {
1430 tokens := strings.Split(bind, ":")
1431 dirMap[tokens[1]] = tokens[0]
1433 if cr.Container.Mounts[tokens[1]].Writable {
1434 c.Check(len(tokens), Equals, 2)
1436 c.Check(len(tokens), Equals, 3)
1437 c.Check(tokens[2], Equals, "ro")
1441 data, err := ioutil.ReadFile(dirMap["/tip"] + "/dir1/dir2/file with mode 0644")
1443 c.Check(string(data), Equals, "\000\001\002\003")
1444 _, err = ioutil.ReadFile(dirMap["/tip"] + "/file only on testbranch")
1445 c.Check(err, FitsTypeOf, &os.PathError{})
1446 c.Check(os.IsNotExist(err), Equals, true)
1448 data, err = ioutil.ReadFile(dirMap["/non-tip"] + "/dir1/dir2/file with mode 0644")
1450 c.Check(string(data), Equals, "\000\001\002\003")
1451 data, err = ioutil.ReadFile(dirMap["/non-tip"] + "/file only on testbranch")
1453 c.Check(string(data), Equals, "testfile\n")
1460 func (s *TestSuite) TestStdout(c *C) {
1462 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1463 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1465 "environment": {"FROBIZ": "bilbo"},
1466 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1467 "output_path": "/tmp",
1469 "runtime_constraints": {}
1472 api, _, _ := s.fullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1473 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1477 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1478 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1479 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1482 // Used by the TestStdoutWithWrongPath*()
1483 func (s *TestSuite) stdoutErrorRunHelper(c *C, record string, fn func(t *TestDockerClient)) (api *ArvTestClient, cr *ContainerRunner, err error) {
1484 rec := arvados.Container{}
1485 err = json.Unmarshal([]byte(record), &rec)
1489 s.docker.ImageRemove(nil, hwImageId, dockertypes.ImageRemoveOptions{})
1491 api = &ArvTestClient{Container: rec}
1492 kc := &KeepTestClient{}
1494 cr, err = NewContainerRunner(s.client, api, kc, s.docker, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1495 c.Assert(err, IsNil)
1496 am := &ArvMountCmdLine{}
1497 cr.RunArvMount = am.ArvMountTest
1498 cr.MkArvClient = func(token string) (IArvadosClient, error) {
1499 return &ArvTestClient{}, nil
1506 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1507 _, _, err := s.stdoutErrorRunHelper(c, `{
1508 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1509 "output_path": "/tmp"
1510 }`, func(t *TestDockerClient) {})
1512 c.Check(err, NotNil)
1513 c.Check(strings.Contains(err.Error(), "Stdout path does not start with OutputPath"), Equals, true)
1516 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1517 _, _, err := s.stdoutErrorRunHelper(c, `{
1518 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1519 "output_path": "/tmp"
1520 }`, func(t *TestDockerClient) {})
1522 c.Check(err, NotNil)
1523 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'tmp' for stdout"), Equals, true)
1526 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1527 _, _, err := s.stdoutErrorRunHelper(c, `{
1528 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1529 "output_path": "/tmp"
1530 }`, func(t *TestDockerClient) {})
1532 c.Check(err, NotNil)
1533 c.Check(strings.Contains(err.Error(), "Unsupported mount kind 'collection' for stdout"), Equals, true)
1536 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1537 defer os.Setenv("ARVADOS_API_HOST", os.Getenv("ARVADOS_API_HOST"))
1538 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1539 api, _, _ := s.fullRunHelper(c, `{
1540 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1541 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1544 "mounts": {"/tmp": {"kind": "tmp"} },
1545 "output_path": "/tmp",
1547 "runtime_constraints": {"API": true}
1548 }`, nil, 0, func(t *TestDockerClient) {
1549 t.logWriter.Write(dockerLog(1, t.env[1][17:]+"\n"))
1553 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1554 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1555 c.Check(strings.HasSuffix(api.Logs["stdout"].String(), "test.arvados.org\n"), Equals, true)
1556 c.Check(api.CalledWith("container.output", "d41d8cd98f00b204e9800998ecf8427e+0"), NotNil)
1559 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1560 defer os.Setenv("ARVADOS_API_HOST", os.Getenv("ARVADOS_API_HOST"))
1561 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1562 api, _, _ := s.fullRunHelper(c, `{
1563 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1564 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1567 "mounts": {"/tmp": {"kind": "tmp"} },
1568 "output_path": "/tmp",
1570 "runtime_constraints": {"API": true}
1571 }`, nil, 0, func(t *TestDockerClient) {
1572 t.api.Container.Output = "d4ab34d3d4f8a72f5c4973051ae69fab+122"
1576 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1577 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1578 c.Check(api.CalledWith("container.output", "d4ab34d3d4f8a72f5c4973051ae69fab+122"), NotNil)
1581 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1583 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1584 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1586 "environment": {"FROBIZ": "bilbo"},
1588 "/tmp": {"kind": "tmp"},
1589 "/tmp/foo": {"kind": "collection",
1590 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1591 "exclude_from_output": true
1593 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1595 "output_path": "/tmp",
1597 "runtime_constraints": {}
1600 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1602 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1603 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1607 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1608 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1609 c.Check(api.CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1612 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1614 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1615 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1617 "environment": {"FROBIZ": "bilbo"},
1619 "/tmp": {"kind": "tmp"},
1620 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1621 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1622 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1623 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1624 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1626 "output_path": "/tmp",
1628 "runtime_constraints": {}
1631 extraMounts := []string{
1632 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1633 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1634 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1637 api, runner, realtemp := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1638 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1642 c.Check(runner.Binds, DeepEquals, []string{realtemp + "/tmp2:/tmp",
1643 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt:/tmp/foo/bar:ro",
1644 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt:/tmp/foo/baz/sub2file2:ro",
1645 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1:/tmp/foo/sub1:ro",
1646 realtemp + "/keep1/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt:/tmp/foo/sub1file2:ro",
1649 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1650 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1651 for _, v := range api.Content {
1652 if v["collection"] != nil {
1653 c.Check(v["ensure_unique_name"], Equals, true)
1654 collection := v["collection"].(arvadosclient.Dict)
1655 if strings.Index(collection["name"].(string), "output") == 0 {
1656 manifest := collection["manifest_text"].(string)
1658 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1659 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:bar 36:18:sub1file2
1660 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1661 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1662 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1669 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1671 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1672 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1674 "environment": {"FROBIZ": "bilbo"},
1676 "/tmp": {"kind": "tmp"},
1677 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/subdir1/file2_in_subdir1.txt"},
1678 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1680 "output_path": "/tmp",
1682 "runtime_constraints": {}
1685 extraMounts := []string{
1686 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1689 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1690 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1694 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1695 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1696 for _, v := range api.Content {
1697 if v["collection"] != nil {
1698 collection := v["collection"].(arvadosclient.Dict)
1699 if strings.Index(collection["name"].(string), "output") == 0 {
1700 manifest := collection["manifest_text"].(string)
1702 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1703 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1710 func (s *TestSuite) TestOutputError(c *C) {
1712 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1713 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1715 "environment": {"FROBIZ": "bilbo"},
1717 "/tmp": {"kind": "tmp"}
1719 "output_path": "/tmp",
1721 "runtime_constraints": {}
1724 extraMounts := []string{}
1726 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1727 os.Symlink("/etc/hosts", t.realTemp+"/tmp2/baz")
1731 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1734 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1736 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1737 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1739 "environment": {"FROBIZ": "bilbo"},
1741 "/tmp": {"kind": "tmp"},
1742 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1743 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1745 "output_path": "/tmp",
1747 "runtime_constraints": {}
1750 extraMounts := []string{
1751 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1754 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func(t *TestDockerClient) {
1755 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1759 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1760 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1761 for _, v := range api.Content {
1762 if v["collection"] != nil {
1763 collection := v["collection"].(arvadosclient.Dict)
1764 if strings.Index(collection["name"].(string), "output") == 0 {
1765 manifest := collection["manifest_text"].(string)
1766 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1773 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1775 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1776 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1778 "environment": {"FROBIZ": "bilbo"},
1780 "/tmp": {"kind": "tmp"},
1781 "stdin": {"kind": "json", "content": "foo"},
1782 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1784 "output_path": "/tmp",
1786 "runtime_constraints": {}
1789 api, _, _ := s.fullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
1790 t.logWriter.Write(dockerLog(1, t.env[0][7:]+"\n"))
1794 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1795 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1796 for _, v := range api.Content {
1797 if v["collection"] != nil {
1798 collection := v["collection"].(arvadosclient.Dict)
1799 if strings.Index(collection["name"].(string), "output") == 0 {
1800 manifest := collection["manifest_text"].(string)
1801 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1808 func (s *TestSuite) TestStderrMount(c *C) {
1809 api, _, _ := s.fullRunHelper(c, `{
1810 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
1811 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1814 "mounts": {"/tmp": {"kind": "tmp"},
1815 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
1816 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
1817 "output_path": "/tmp",
1819 "runtime_constraints": {}
1820 }`, nil, 1, func(t *TestDockerClient) {
1821 t.logWriter.Write(dockerLog(1, "hello\n"))
1822 t.logWriter.Write(dockerLog(2, "oops\n"))
1826 final := api.CalledWith("container.state", "Complete")
1827 c.Assert(final, NotNil)
1828 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1829 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1831 c.Check(api.CalledWith("collection.manifest_text", "./a b1946ac92492d2347c6235b4d2611184+6 0:6:out.txt\n./b 38af5c54926b620264ab1501150cf189+5 0:5:err.txt\n"), NotNil)
1834 func (s *TestSuite) TestNumberRoundTrip(c *C) {
1835 kc := &KeepTestClient{}
1837 cr, err := NewContainerRunner(s.client, &ArvTestClient{callraw: true}, kc, nil, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
1838 c.Assert(err, IsNil)
1839 cr.fetchContainerRecord()
1841 jsondata, err := json.Marshal(cr.Container.Mounts["/json"].Content)
1844 c.Check(string(jsondata), Equals, `{"number":123456789123456789}`)
1847 func (s *TestSuite) TestFullBrokenDocker1(c *C) {
1848 tf, err := ioutil.TempFile("", "brokenNodeHook-")
1849 c.Assert(err, IsNil)
1850 defer os.Remove(tf.Name())
1852 tf.Write([]byte(`#!/bin/sh
1856 os.Chmod(tf.Name(), 0700)
1859 brokenNodeHook = &ech
1861 api, _, _ := s.fullRunHelper(c, `{
1862 "command": ["echo", "hello world"],
1863 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1866 "mounts": {"/tmp": {"kind": "tmp"} },
1867 "output_path": "/tmp",
1869 "runtime_constraints": {}
1870 }`, nil, 2, func(t *TestDockerClient) {
1871 t.logWriter.Write(dockerLog(1, "hello world\n"))
1875 c.Check(api.CalledWith("container.state", "Queued"), NotNil)
1876 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1877 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Running broken node hook.*")
1878 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*killme.*")
1882 func (s *TestSuite) TestFullBrokenDocker2(c *C) {
1884 brokenNodeHook = &ech
1886 api, _, _ := s.fullRunHelper(c, `{
1887 "command": ["echo", "hello world"],
1888 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1891 "mounts": {"/tmp": {"kind": "tmp"} },
1892 "output_path": "/tmp",
1894 "runtime_constraints": {}
1895 }`, nil, 2, func(t *TestDockerClient) {
1896 t.logWriter.Write(dockerLog(1, "hello world\n"))
1900 c.Check(api.CalledWith("container.state", "Queued"), NotNil)
1901 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1902 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*No broken node hook.*")
1905 func (s *TestSuite) TestFullBrokenDocker3(c *C) {
1907 brokenNodeHook = &ech
1909 api, _, _ := s.fullRunHelper(c, `{
1910 "command": ["echo", "hello world"],
1911 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1914 "mounts": {"/tmp": {"kind": "tmp"} },
1915 "output_path": "/tmp",
1917 "runtime_constraints": {}
1918 }`, nil, 3, func(t *TestDockerClient) {
1919 t.logWriter.Write(dockerLog(1, "hello world\n"))
1923 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1924 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1927 func (s *TestSuite) TestBadCommand1(c *C) {
1929 brokenNodeHook = &ech
1931 api, _, _ := s.fullRunHelper(c, `{
1932 "command": ["echo", "hello world"],
1933 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1936 "mounts": {"/tmp": {"kind": "tmp"} },
1937 "output_path": "/tmp",
1939 "runtime_constraints": {}
1940 }`, nil, 4, func(t *TestDockerClient) {
1941 t.logWriter.Write(dockerLog(1, "hello world\n"))
1945 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1946 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
1949 func (s *TestSuite) TestBadCommand2(c *C) {
1951 brokenNodeHook = &ech
1953 api, _, _ := s.fullRunHelper(c, `{
1954 "command": ["echo", "hello world"],
1955 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1958 "mounts": {"/tmp": {"kind": "tmp"} },
1959 "output_path": "/tmp",
1961 "runtime_constraints": {}
1962 }`, nil, 5, func(t *TestDockerClient) {
1963 t.logWriter.Write(dockerLog(1, "hello world\n"))
1967 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1968 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
1971 func (s *TestSuite) TestBadCommand3(c *C) {
1973 brokenNodeHook = &ech
1975 api, _, _ := s.fullRunHelper(c, `{
1976 "command": ["echo", "hello world"],
1977 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
1980 "mounts": {"/tmp": {"kind": "tmp"} },
1981 "output_path": "/tmp",
1983 "runtime_constraints": {}
1984 }`, nil, 6, func(t *TestDockerClient) {
1985 t.logWriter.Write(dockerLog(1, "hello world\n"))
1989 c.Check(api.CalledWith("container.state", "Cancelled"), NotNil)
1990 c.Check(api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
1993 func (s *TestSuite) TestSecretTextMountPoint(c *C) {
1994 // under normal mounts, gets captured in output, oops
1996 "command": ["true"],
1997 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
2000 "/tmp": {"kind": "tmp"},
2001 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2005 "output_path": "/tmp",
2007 "runtime_constraints": {}
2010 api, _, _ := s.fullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
2011 content, err := ioutil.ReadFile(t.realTemp + "/tmp2/secret.conf")
2013 c.Check(content, DeepEquals, []byte("mypassword"))
2017 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
2018 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
2019 c.Check(api.CalledWith("collection.manifest_text", ". 34819d7beeabb9260a5c854bc85b3e44+10 0:10:secret.conf\n"), NotNil)
2020 c.Check(api.CalledWith("collection.manifest_text", ""), IsNil)
2022 // under secret mounts, not captured in output
2024 "command": ["true"],
2025 "container_image": "d4ab34d3d4f8a72f5c4973051ae69fab+122",
2028 "/tmp": {"kind": "tmp"}
2031 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2033 "output_path": "/tmp",
2035 "runtime_constraints": {}
2038 api, _, _ = s.fullRunHelper(c, helperRecord, nil, 0, func(t *TestDockerClient) {
2039 content, err := ioutil.ReadFile(t.realTemp + "/tmp2/secret.conf")
2041 c.Check(content, DeepEquals, []byte("mypassword"))
2045 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
2046 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
2047 c.Check(api.CalledWith("collection.manifest_text", ". 34819d7beeabb9260a5c854bc85b3e44+10 0:10:secret.conf\n"), IsNil)
2048 c.Check(api.CalledWith("collection.manifest_text", ""), NotNil)