1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
25 "git.arvados.org/arvados.git/sdk/go/arvados"
26 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
27 "git.arvados.org/arvados.git/sdk/go/arvadostest"
28 "git.arvados.org/arvados.git/sdk/go/manifest"
29 "golang.org/x/net/context"
34 // Gocheck boilerplate
35 func TestCrunchExec(t *testing.T) {
39 var _ = Suite(&TestSuite{})
41 type TestSuite struct {
42 client *arvados.Client
44 runner *ContainerRunner
45 executor *stubExecutor
48 testDispatcherKeepClient KeepTestClient
49 testContainerKeepClient KeepTestClient
52 func (s *TestSuite) SetUpTest(c *C) {
53 s.client = arvados.NewClientFromEnv()
54 s.executor = &stubExecutor{}
56 s.api = &ArvTestClient{}
57 s.runner, err = NewContainerRunner(s.client, s.api, &s.testDispatcherKeepClient, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
59 s.runner.executor = s.executor
60 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
61 return s.api, &s.testContainerKeepClient, s.client, nil
63 s.runner.RunArvMount = func(cmd []string, tok string) (*exec.Cmd, error) {
64 s.runner.ArvMountPoint = s.keepmount
65 for i, opt := range cmd {
66 if opt == "--mount-tmp" {
67 err := os.Mkdir(s.keepmount+"/"+cmd[i+1], 0700)
71 s.keepmountTmp = append(s.keepmountTmp, cmd[i+1])
76 s.keepmount = c.MkDir()
77 err = os.Mkdir(s.keepmount+"/by_id", 0755)
80 err = os.Mkdir(s.keepmount+"/by_id/"+arvadostest.DockerImage112PDH, 0755)
82 err = ioutil.WriteFile(s.keepmount+"/by_id/"+arvadostest.DockerImage112PDH+"/"+arvadostest.DockerImage112Filename, []byte("#notarealtarball"), 0644)
83 err = os.Mkdir(s.keepmount+"/by_id/"+fakeInputCollectionPDH, 0755)
85 err = ioutil.WriteFile(s.keepmount+"/by_id/"+fakeInputCollectionPDH+"/input.json", []byte(`{"input":true}`), 0644)
87 s.runner.ArvMountPoint = s.keepmount
90 type ArvTestClient struct {
93 Content []arvadosclient.Dict
96 Logs map[string]*bytes.Buffer
102 type KeepTestClient struct {
105 StorageClasses []string
108 type stubExecutor struct {
114 created containerSpec
116 waitSleep time.Duration
125 func (e *stubExecutor) LoadImage(imageId string, tarball string, container arvados.Container, keepMount string,
126 containerClient *arvados.Client) error {
130 func (e *stubExecutor) Runtime() string { return "stub" }
131 func (e *stubExecutor) Create(spec containerSpec) error { e.created = spec; return e.createErr }
132 func (e *stubExecutor) Start() error { e.exit = make(chan int, 1); go e.runFunc(); return e.startErr }
133 func (e *stubExecutor) CgroupID() string { return "cgroupid" }
134 func (e *stubExecutor) Stop() error { e.stopped = true; go func() { e.exit <- -1 }(); return e.stopErr }
135 func (e *stubExecutor) Close() { e.closed = true }
136 func (e *stubExecutor) Wait(context.Context) (int, error) {
137 return <-e.exit, e.waitErr
139 func (e *stubExecutor) InjectCommand(ctx context.Context, _, _ string, _ bool, _ []string) (*exec.Cmd, error) {
140 return nil, errors.New("unimplemented")
142 func (e *stubExecutor) IPAddress() (string, error) { return "", errors.New("unimplemented") }
144 const fakeInputCollectionPDH = "ffffffffaaaaaaaa88888888eeeeeeee+1234"
146 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
147 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
148 var hwImageID = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
150 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
151 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
153 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
154 ./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
155 ./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
158 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
160 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"
161 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
163 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
164 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
166 func (client *ArvTestClient) Create(resourceType string,
167 parameters arvadosclient.Dict,
168 output interface{}) error {
171 defer client.Mutex.Unlock()
174 client.Content = append(client.Content, parameters)
176 if resourceType == "logs" {
177 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
178 if client.Logs == nil {
179 client.Logs = make(map[string]*bytes.Buffer)
181 if client.Logs[et] == nil {
182 client.Logs[et] = &bytes.Buffer{}
184 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
187 if resourceType == "collections" && output != nil {
188 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
189 outmap := output.(*arvados.Collection)
190 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5.Sum([]byte(mt)), len(mt))
191 outmap.UUID = fmt.Sprintf("zzzzz-4zz18-%15.15x", md5.Sum([]byte(mt)))
197 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
199 case method == "GET" && resourceType == "containers" && action == "auth":
200 return json.Unmarshal([]byte(`{
201 "kind": "arvados#api_client_authorization",
202 "uuid": "`+fakeAuthUUID+`",
203 "api_token": "`+fakeAuthToken+`"
205 case method == "GET" && resourceType == "containers" && action == "secret_mounts":
206 if client.secretMounts != nil {
207 return json.Unmarshal(client.secretMounts, output)
209 return json.Unmarshal([]byte(`{"secret_mounts":{}}`), output)
211 return fmt.Errorf("Not found")
215 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
216 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
218 if method == "GET" && resourceType == "nodes" && uuid == "" && action == "" {
220 "kind": "arvados#nodeList",
222 "uuid": "zzzzz-7ekkf-2z3mc76g2q73aio",
223 "hostname": "compute2",
224 "properties": {"total_cpu_cores": 16}
226 } else if method == "GET" && resourceType == "containers" && action == "" && !client.callraw {
228 j, err = json.Marshal(map[string]interface{}{
229 "items": []interface{}{client.Container},
230 "kind": "arvados#nodeList",
233 j, err = json.Marshal(client.Container)
237 "command": ["sleep", "1"],
238 "container_image": "` + arvadostest.DockerImage112PDH + `",
241 "mounts": {"/tmp": {"kind": "tmp"}, "/json": {"kind": "json", "content": {"number": 123456789123456789}}},
242 "output_path": "/tmp",
244 "runtime_constraints": {}
247 return ioutil.NopCloser(bytes.NewReader(j)), err
250 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
251 if resourceType == "collections" {
253 output.(*arvados.Collection).ManifestText = hwManifest
254 } else if uuid == otherPDH {
255 output.(*arvados.Collection).ManifestText = otherManifest
256 } else if uuid == normalizedWithSubdirsPDH {
257 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
258 } else if uuid == denormalizedWithSubdirsPDH {
259 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
262 if resourceType == "containers" {
263 (*output.(*arvados.Container)) = client.Container
268 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
270 defer client.Mutex.Unlock()
272 client.Content = append(client.Content, parameters)
273 if resourceType == "containers" {
274 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
275 client.WasSetRunning = true
277 } else if resourceType == "collections" {
278 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
279 output.(*arvados.Collection).UUID = uuid
280 output.(*arvados.Collection).PortableDataHash = fmt.Sprintf("%x", md5.Sum([]byte(mt)))
285 var discoveryMap = map[string]interface{}{
286 "defaultTrashLifetime": float64(1209600),
287 "crunchLimitLogBytesPerJob": float64(67108864),
288 "crunchLogThrottleBytes": float64(65536),
289 "crunchLogThrottlePeriod": float64(60),
290 "crunchLogThrottleLines": float64(1024),
291 "crunchLogPartialLineThrottlePeriod": float64(5),
292 "crunchLogBytesPerEvent": float64(4096),
293 "crunchLogSecondsBetweenEvents": float64(1),
296 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
297 return discoveryMap[key], nil
300 // CalledWith returns the parameters from the first API call whose
301 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
302 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
303 // no call matches, it returns nil.
304 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
306 for _, content := range client.Content {
307 var v interface{} = content
308 for _, k := range strings.Split(jpath, ".") {
309 if dict, ok := v.(arvadosclient.Dict); !ok {
322 func (client *KeepTestClient) LocalLocator(locator string) (string, error) {
326 func (client *KeepTestClient) BlockWrite(_ context.Context, opts arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) {
327 client.Content = opts.Data
328 return arvados.BlockWriteResponse{
329 Locator: fmt.Sprintf("%x+%d", md5.Sum(opts.Data), len(opts.Data)),
333 func (client *KeepTestClient) ReadAt(string, []byte, int) (int, error) {
334 return 0, errors.New("not implemented")
337 func (client *KeepTestClient) ClearBlockCache() {
340 func (client *KeepTestClient) Close() {
344 func (client *KeepTestClient) SetStorageClasses(sc []string) {
345 client.StorageClasses = sc
348 type FileWrapper struct {
353 func (fw FileWrapper) Readdir(n int) ([]os.FileInfo, error) {
354 return nil, errors.New("not implemented")
357 func (fw FileWrapper) Seek(int64, int) (int64, error) {
358 return 0, errors.New("not implemented")
361 func (fw FileWrapper) Size() int64 {
365 func (fw FileWrapper) Stat() (os.FileInfo, error) {
366 return nil, errors.New("not implemented")
369 func (fw FileWrapper) Truncate(int64) error {
370 return errors.New("not implemented")
373 func (fw FileWrapper) Write([]byte) (int, error) {
374 return 0, errors.New("not implemented")
377 func (fw FileWrapper) Sync() error {
378 return errors.New("not implemented")
381 func (fw FileWrapper) Snapshot() (*arvados.Subtree, error) {
382 return nil, errors.New("not implemented")
385 func (fw FileWrapper) Splice(*arvados.Subtree) error {
386 return 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 s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH
404 s.runner.Container.Mounts = map[string]arvados.Mount{
405 "/out": {Kind: "tmp", Writable: true},
407 s.runner.Container.OutputPath = "/out"
409 _, err := s.runner.SetupMounts()
412 imageID, err := s.runner.LoadImage()
414 c.Check(s.executor.loaded, Matches, ".*"+regexp.QuoteMeta(arvadostest.DockerImage112Filename))
415 c.Check(imageID, Equals, strings.TrimSuffix(arvadostest.DockerImage112Filename, ".tar"))
417 s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH
418 s.executor.imageLoaded = false
419 s.executor.loaded = ""
420 s.executor.loadErr = errors.New("bork")
421 imageID, err = s.runner.LoadImage()
422 c.Check(err, ErrorMatches, ".*bork")
423 c.Check(s.executor.loaded, Matches, ".*"+regexp.QuoteMeta(arvadostest.DockerImage112Filename))
425 s.runner.Container.ContainerImage = fakeInputCollectionPDH
426 s.executor.imageLoaded = false
427 s.executor.loaded = ""
428 s.executor.loadErr = nil
429 imageID, err = s.runner.LoadImage()
430 c.Check(err, ErrorMatches, "image collection does not include a \\.tar image file")
431 c.Check(s.executor.loaded, Equals, "")
434 type ArvErrorTestClient struct{}
436 func (ArvErrorTestClient) Create(resourceType string,
437 parameters arvadosclient.Dict,
438 output interface{}) error {
442 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
443 if method == "GET" && resourceType == "containers" && action == "auth" {
446 return errors.New("ArvError")
449 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
450 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
451 return nil, errors.New("ArvError")
454 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
455 return errors.New("ArvError")
458 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
462 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
463 return discoveryMap[key], nil
466 type KeepErrorTestClient struct {
470 func (*KeepErrorTestClient) ManifestFileReader(manifest.Manifest, string) (arvados.File, error) {
471 return nil, errors.New("KeepError")
474 func (*KeepErrorTestClient) BlockWrite(context.Context, arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) {
475 return arvados.BlockWriteResponse{}, errors.New("KeepError")
478 func (*KeepErrorTestClient) LocalLocator(string) (string, error) {
479 return "", errors.New("KeepError")
482 type KeepReadErrorTestClient struct {
486 func (*KeepReadErrorTestClient) ReadAt(string, []byte, int) (int, error) {
487 return 0, errors.New("KeepError")
490 type ErrorReader struct {
494 func (ErrorReader) Read(p []byte) (n int, err error) {
495 return 0, errors.New("ErrorReader")
498 func (ErrorReader) Seek(int64, int) (int64, error) {
499 return 0, errors.New("ErrorReader")
502 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
503 return ErrorReader{}, nil
506 type ClosableBuffer struct {
510 func (*ClosableBuffer) Close() error {
514 type TestLogs struct {
515 Stdout ClosableBuffer
516 Stderr ClosableBuffer
519 func (tl *TestLogs) NewTestLoggingWriter(logstr string) (io.WriteCloser, error) {
520 if logstr == "stdout" {
521 return &tl.Stdout, nil
523 if logstr == "stderr" {
524 return &tl.Stderr, nil
526 return nil, errors.New("???")
529 func dockerLog(fd byte, msg string) []byte {
531 header := make([]byte, 8+len(by))
533 header[7] = byte(len(by))
538 func (s *TestSuite) TestRunContainer(c *C) {
539 s.executor.runFunc = func() {
540 fmt.Fprintf(s.executor.created.Stdout, "Hello world\n")
545 s.runner.NewLogWriter = logs.NewTestLoggingWriter
546 s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH
547 s.runner.Container.Command = []string{"./hw"}
548 s.runner.Container.OutputStorageClasses = []string{"default"}
550 imageID, err := s.runner.LoadImage()
553 err = s.runner.CreateContainer(imageID, nil)
556 err = s.runner.StartContainer()
559 err = s.runner.WaitFinish()
562 c.Check(logs.Stdout.String(), Matches, ".*Hello world\n")
563 c.Check(logs.Stderr.String(), Equals, "")
566 func (s *TestSuite) TestCommitLogs(c *C) {
567 api := &ArvTestClient{}
568 kc := &KeepTestClient{}
570 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
572 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
574 cr.CrunchLog.Print("Hello world!")
575 cr.CrunchLog.Print("Goodbye")
576 cr.finalState = "Complete"
578 err = cr.CommitLogs()
581 c.Check(api.Calls, Equals, 2)
582 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
583 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
584 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
585 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
588 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
589 api := &ArvTestClient{}
590 kc := &KeepTestClient{}
592 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
595 err = cr.UpdateContainerRunning()
598 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
601 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
602 api := &ArvTestClient{}
603 kc := &KeepTestClient{}
605 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
608 cr.LogsPDH = new(string)
609 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
611 cr.ExitCode = new(int)
613 cr.finalState = "Complete"
615 err = cr.UpdateContainerFinal()
618 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
619 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
620 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
623 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
624 api := &ArvTestClient{}
625 kc := &KeepTestClient{}
627 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
630 cr.finalState = "Cancelled"
632 err = cr.UpdateContainerFinal()
635 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
636 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
637 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
640 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
641 // dress rehearsal of the Run() function, starting from a JSON container record.
642 func (s *TestSuite) fullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func()) (*ArvTestClient, *ContainerRunner, string) {
643 err := json.Unmarshal([]byte(record), &s.api.Container)
645 initialState := s.api.Container.State
648 SecretMounts map[string]arvados.Mount `json:"secret_mounts"`
650 err = json.Unmarshal([]byte(record), &sm)
652 secretMounts, err := json.Marshal(sm)
654 c.Logf("SecretMounts decoded %v json %q", sm, secretMounts)
656 s.executor.runFunc = func() {
658 s.executor.exit <- exitCode
661 s.runner.statInterval = 100 * time.Millisecond
662 s.runner.containerWatchdogInterval = time.Second
664 realTemp := c.MkDir()
666 s.runner.MkTempDir = func(_, prefix string) (string, error) {
668 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
669 err := os.Mkdir(d, os.ModePerm)
670 if err != nil && strings.Contains(err.Error(), ": file exists") {
671 // Test case must have pre-populated the tempdir
676 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
677 return &ArvTestClient{secretMounts: secretMounts}, &s.testContainerKeepClient, nil, nil
680 if extraMounts != nil && len(extraMounts) > 0 {
681 err := s.runner.SetupArvMountPoint("keep")
684 for _, m := range extraMounts {
685 os.MkdirAll(s.runner.ArvMountPoint+"/by_id/"+m, os.ModePerm)
690 if s.api.CalledWith("container.state", "Complete") != nil {
693 if s.executor.loadErr == nil && s.executor.createErr == nil && initialState != "Running" {
694 c.Check(s.api.WasSetRunning, Equals, true)
695 var lastupdate arvadosclient.Dict
696 for _, content := range s.api.Content {
697 if content["container"] != nil {
698 lastupdate = content["container"].(arvadosclient.Dict)
701 if lastupdate["log"] == nil {
702 c.Errorf("no container update with non-nil log -- updates were: %v", s.api.Content)
707 for k, v := range s.api.Logs {
713 return s.api, s.runner, realTemp
716 func (s *TestSuite) TestFullRunHello(c *C) {
717 s.runner.enableMemoryLimit = true
718 s.runner.networkMode = "default"
719 s.fullRunHelper(c, `{
720 "command": ["echo", "hello world"],
721 "container_image": "`+arvadostest.DockerImage112PDH+`",
723 "environment": {"foo":"bar","baz":"waz"},
724 "mounts": {"/tmp": {"kind": "tmp"} },
725 "output_path": "/tmp",
727 "runtime_constraints": {"vcpus":1,"ram":1000000},
729 "output_storage_classes": ["default"]
731 c.Check(s.executor.created.Command, DeepEquals, []string{"echo", "hello world"})
732 c.Check(s.executor.created.Image, Equals, "sha256:d8309758b8fe2c81034ffc8a10c36460b77db7bc5e7b448c4e5b684f9d95a678")
733 c.Check(s.executor.created.Env, DeepEquals, map[string]string{"foo": "bar", "baz": "waz"})
734 c.Check(s.executor.created.VCPUs, Equals, 1)
735 c.Check(s.executor.created.RAM, Equals, int64(1000000))
736 c.Check(s.executor.created.NetworkMode, Equals, "default")
737 c.Check(s.executor.created.EnableNetwork, Equals, false)
738 c.Check(s.executor.created.CUDADeviceCount, Equals, 0)
739 fmt.Fprintln(s.executor.created.Stdout, "hello world")
742 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
743 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
744 c.Check(s.api.Logs["stdout"].String(), Matches, ".*hello world\n")
745 c.Check(s.testDispatcherKeepClient.StorageClasses, DeepEquals, []string{"default"})
746 c.Check(s.testContainerKeepClient.StorageClasses, DeepEquals, []string{"default"})
749 func (s *TestSuite) TestRunAlreadyRunning(c *C) {
751 s.fullRunHelper(c, `{
752 "command": ["sleep", "3"],
753 "container_image": "`+arvadostest.DockerImage112PDH+`",
756 "mounts": {"/tmp": {"kind": "tmp"} },
757 "output_path": "/tmp",
759 "runtime_constraints": {},
760 "scheduling_parameters":{"max_run_time": 1},
765 c.Check(s.api.CalledWith("container.state", "Cancelled"), IsNil)
766 c.Check(s.api.CalledWith("container.state", "Complete"), IsNil)
767 c.Check(ran, Equals, false)
770 func (s *TestSuite) TestRunTimeExceeded(c *C) {
771 s.fullRunHelper(c, `{
772 "command": ["sleep", "3"],
773 "container_image": "`+arvadostest.DockerImage112PDH+`",
776 "mounts": {"/tmp": {"kind": "tmp"} },
777 "output_path": "/tmp",
779 "runtime_constraints": {},
780 "scheduling_parameters":{"max_run_time": 1},
783 time.Sleep(3 * time.Second)
786 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
787 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*maximum run time exceeded.*")
790 func (s *TestSuite) TestContainerWaitFails(c *C) {
791 s.fullRunHelper(c, `{
792 "command": ["sleep", "3"],
793 "container_image": "`+arvadostest.DockerImage112PDH+`",
795 "mounts": {"/tmp": {"kind": "tmp"} },
796 "output_path": "/tmp",
800 s.executor.waitErr = errors.New("Container is not running")
803 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
804 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Container is not running.*")
807 func (s *TestSuite) TestCrunchstat(c *C) {
808 s.fullRunHelper(c, `{
809 "command": ["sleep", "1"],
810 "container_image": "`+arvadostest.DockerImage112PDH+`",
813 "mounts": {"/tmp": {"kind": "tmp"} },
814 "output_path": "/tmp",
816 "runtime_constraints": {},
819 time.Sleep(time.Second)
822 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
823 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
825 // We didn't actually start a container, so crunchstat didn't
826 // find accounting files and therefore didn't log any stats.
827 // It should have logged a "can't find accounting files"
828 // message after one poll interval, though, so we can confirm
830 c.Assert(s.api.Logs["crunchstat"], NotNil)
831 c.Check(s.api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
833 // The "files never appeared" log assures us that we called
834 // (*crunchstat.Reporter)Stop(), and that we set it up with
835 // the correct container ID "abcde":
836 c.Check(s.api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for cgroupid\n`)
839 func (s *TestSuite) TestNodeInfoLog(c *C) {
840 os.Setenv("SLURMD_NODENAME", "compute2")
841 s.fullRunHelper(c, `{
842 "command": ["sleep", "1"],
843 "container_image": "`+arvadostest.DockerImage112PDH+`",
846 "mounts": {"/tmp": {"kind": "tmp"} },
847 "output_path": "/tmp",
849 "runtime_constraints": {},
853 time.Sleep(time.Second)
856 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
857 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
859 c.Assert(s.api.Logs["node"], NotNil)
860 json := s.api.Logs["node"].String()
861 c.Check(json, Matches, `(?ms).*"uuid": *"zzzzz-7ekkf-2z3mc76g2q73aio".*`)
862 c.Check(json, Matches, `(?ms).*"total_cpu_cores": *16.*`)
863 c.Check(json, Not(Matches), `(?ms).*"info":.*`)
865 c.Assert(s.api.Logs["node-info"], NotNil)
866 json = s.api.Logs["node-info"].String()
867 c.Check(json, Matches, `(?ms).*Host Information.*`)
868 c.Check(json, Matches, `(?ms).*CPU Information.*`)
869 c.Check(json, Matches, `(?ms).*Memory Information.*`)
870 c.Check(json, Matches, `(?ms).*Disk Space.*`)
871 c.Check(json, Matches, `(?ms).*Disk INodes.*`)
874 func (s *TestSuite) TestLogVersionAndRuntime(c *C) {
875 s.fullRunHelper(c, `{
876 "command": ["sleep", "1"],
877 "container_image": "`+arvadostest.DockerImage112PDH+`",
880 "mounts": {"/tmp": {"kind": "tmp"} },
881 "output_path": "/tmp",
883 "runtime_constraints": {},
889 c.Assert(s.api.Logs["crunch-run"], NotNil)
890 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*crunch-run \S+ \(go\S+\) start.*`)
891 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*crunch-run process has uid=\d+\(.+\) gid=\d+\(.+\) groups=\d+\(.+\)(,\d+\(.+\))*\n.*`)
892 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Executing container 'zzzzz-zzzzz-zzzzzzzzzzzzzzz' using stub runtime.*`)
895 func (s *TestSuite) TestContainerRecordLog(c *C) {
896 s.fullRunHelper(c, `{
897 "command": ["sleep", "1"],
898 "container_image": "`+arvadostest.DockerImage112PDH+`",
901 "mounts": {"/tmp": {"kind": "tmp"} },
902 "output_path": "/tmp",
904 "runtime_constraints": {},
908 time.Sleep(time.Second)
911 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
912 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
914 c.Assert(s.api.Logs["container"], NotNil)
915 c.Check(s.api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
918 func (s *TestSuite) TestFullRunStderr(c *C) {
919 s.fullRunHelper(c, `{
920 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
921 "container_image": "`+arvadostest.DockerImage112PDH+`",
924 "mounts": {"/tmp": {"kind": "tmp"} },
925 "output_path": "/tmp",
927 "runtime_constraints": {},
930 fmt.Fprintln(s.executor.created.Stdout, "hello")
931 fmt.Fprintln(s.executor.created.Stderr, "world")
934 final := s.api.CalledWith("container.state", "Complete")
935 c.Assert(final, NotNil)
936 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
937 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
939 c.Check(s.api.Logs["stdout"].String(), Matches, ".*hello\n")
940 c.Check(s.api.Logs["stderr"].String(), Matches, ".*world\n")
943 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
944 s.fullRunHelper(c, `{
946 "container_image": "`+arvadostest.DockerImage112PDH+`",
949 "mounts": {"/tmp": {"kind": "tmp"} },
950 "output_path": "/tmp",
952 "runtime_constraints": {},
955 fmt.Fprintf(s.executor.created.Stdout, "workdir=%q", s.executor.created.WorkingDir)
958 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
959 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
960 c.Log(s.api.Logs["stdout"])
961 c.Check(s.api.Logs["stdout"].String(), Matches, `.*workdir=""\n`)
964 func (s *TestSuite) TestFullRunSetCwd(c *C) {
965 s.fullRunHelper(c, `{
967 "container_image": "`+arvadostest.DockerImage112PDH+`",
970 "mounts": {"/tmp": {"kind": "tmp"} },
971 "output_path": "/tmp",
973 "runtime_constraints": {},
976 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.WorkingDir)
979 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
980 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
981 c.Check(s.api.Logs["stdout"].String(), Matches, ".*/bin\n")
984 func (s *TestSuite) TestFullRunSetOutputStorageClasses(c *C) {
985 s.fullRunHelper(c, `{
987 "container_image": "`+arvadostest.DockerImage112PDH+`",
990 "mounts": {"/tmp": {"kind": "tmp"} },
991 "output_path": "/tmp",
993 "runtime_constraints": {},
995 "output_storage_classes": ["foo", "bar"]
997 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.WorkingDir)
1000 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1001 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1002 c.Check(s.api.Logs["stdout"].String(), Matches, ".*/bin\n")
1003 c.Check(s.testDispatcherKeepClient.StorageClasses, DeepEquals, []string{"foo", "bar"})
1004 c.Check(s.testContainerKeepClient.StorageClasses, DeepEquals, []string{"foo", "bar"})
1007 func (s *TestSuite) TestEnableCUDADeviceCount(c *C) {
1008 s.fullRunHelper(c, `{
1010 "container_image": "`+arvadostest.DockerImage112PDH+`",
1013 "mounts": {"/tmp": {"kind": "tmp"} },
1014 "output_path": "/tmp",
1016 "runtime_constraints": {"cuda": {"device_count": 2}},
1018 "output_storage_classes": ["foo", "bar"]
1019 }`, nil, 0, func() {
1020 fmt.Fprintln(s.executor.created.Stdout, "ok")
1022 c.Check(s.executor.created.CUDADeviceCount, Equals, 2)
1025 func (s *TestSuite) TestEnableCUDAHardwareCapability(c *C) {
1026 s.fullRunHelper(c, `{
1028 "container_image": "`+arvadostest.DockerImage112PDH+`",
1031 "mounts": {"/tmp": {"kind": "tmp"} },
1032 "output_path": "/tmp",
1034 "runtime_constraints": {"cuda": {"hardware_capability": "foo"}},
1036 "output_storage_classes": ["foo", "bar"]
1037 }`, nil, 0, func() {
1038 fmt.Fprintln(s.executor.created.Stdout, "ok")
1040 c.Check(s.executor.created.CUDADeviceCount, Equals, 0)
1043 func (s *TestSuite) TestStopOnSignal(c *C) {
1044 s.executor.runFunc = func() {
1045 s.executor.created.Stdout.Write([]byte("foo\n"))
1046 s.runner.SigChan <- syscall.SIGINT
1048 s.testStopContainer(c)
1051 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
1052 s.executor.runFunc = func() {
1053 s.executor.created.Stdout.Write([]byte("foo\n"))
1054 s.runner.ArvMountExit <- nil
1055 close(s.runner.ArvMountExit)
1057 s.runner.ArvMountExit = make(chan error)
1058 s.testStopContainer(c)
1061 func (s *TestSuite) testStopContainer(c *C) {
1063 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
1064 "container_image": "` + arvadostest.DockerImage112PDH + `",
1067 "mounts": {"/tmp": {"kind": "tmp"} },
1068 "output_path": "/tmp",
1070 "runtime_constraints": {},
1074 err := json.Unmarshal([]byte(record), &s.api.Container)
1075 c.Assert(err, IsNil)
1077 s.runner.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
1078 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
1079 return &ArvTestClient{}, &KeepTestClient{}, nil, nil
1082 done := make(chan error)
1084 done <- s.runner.Run()
1087 case <-time.After(20 * time.Second):
1088 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
1089 c.Fatal("timed out")
1093 for k, v := range s.api.Logs {
1095 c.Log(v.String(), "\n")
1098 c.Check(s.api.CalledWith("container.log", nil), NotNil)
1099 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
1100 c.Check(s.api.Logs["stdout"].String(), Matches, "(?ms).*foo\n$")
1103 func (s *TestSuite) TestFullRunSetEnv(c *C) {
1104 s.fullRunHelper(c, `{
1105 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1106 "container_image": "`+arvadostest.DockerImage112PDH+`",
1108 "environment": {"FROBIZ": "bilbo"},
1109 "mounts": {"/tmp": {"kind": "tmp"} },
1110 "output_path": "/tmp",
1112 "runtime_constraints": {},
1114 }`, nil, 0, func() {
1115 fmt.Fprintf(s.executor.created.Stdout, "%v", s.executor.created.Env)
1118 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1119 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1120 c.Check(s.api.Logs["stdout"].String(), Matches, `.*map\[FROBIZ:bilbo\]\n`)
1123 type ArvMountCmdLine struct {
1128 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
1134 func stubCert(temp string) string {
1135 path := temp + "/ca-certificates.crt"
1136 crt, _ := os.Create(path)
1138 arvadosclient.CertFiles = []string{path}
1142 func (s *TestSuite) TestSetupMounts(c *C) {
1144 am := &ArvMountCmdLine{}
1145 cr.RunArvMount = am.ArvMountTest
1146 cr.ContainerArvClient = &ArvTestClient{}
1147 cr.ContainerKeepClient = &KeepTestClient{}
1148 cr.Container.OutputStorageClasses = []string{"default"}
1150 realTemp := c.MkDir()
1151 certTemp := c.MkDir()
1152 stubCertPath := stubCert(certTemp)
1153 cr.parentTemp = realTemp
1156 cr.MkTempDir = func(_ string, prefix string) (string, error) {
1158 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
1159 err := os.Mkdir(d, os.ModePerm)
1160 if err != nil && strings.Contains(err.Error(), ": file exists") {
1161 // Test case must have pre-populated the tempdir
1167 checkEmpty := func() {
1168 // Should be deleted.
1169 _, err := os.Stat(realTemp)
1170 c.Assert(os.IsNotExist(err), Equals, true)
1172 // Now recreate it for the next test.
1173 c.Assert(os.Mkdir(realTemp, 0777), IsNil)
1178 cr.ArvMountPoint = ""
1179 cr.Container.Mounts = make(map[string]arvados.Mount)
1180 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1181 cr.Container.OutputPath = "/tmp"
1182 cr.statInterval = 5 * time.Second
1183 bindmounts, err := cr.SetupMounts()
1185 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1186 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1187 "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1188 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/tmp": {realTemp + "/tmp2", false}})
1189 os.RemoveAll(cr.ArvMountPoint)
1196 cr.ArvMountPoint = ""
1197 cr.Container.Mounts = make(map[string]arvados.Mount)
1198 cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"}
1199 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1200 cr.Container.OutputPath = "/out"
1201 cr.Container.OutputStorageClasses = []string{"foo", "bar"}
1203 bindmounts, err := cr.SetupMounts()
1205 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1206 "--read-write", "--storage-classes", "foo,bar", "--crunchstat-interval=5",
1207 "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1208 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/out": {realTemp + "/tmp2", false}, "/tmp": {realTemp + "/tmp3", false}})
1209 os.RemoveAll(cr.ArvMountPoint)
1216 cr.ArvMountPoint = ""
1217 cr.Container.Mounts = make(map[string]arvados.Mount)
1218 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1219 cr.Container.OutputPath = "/tmp"
1220 cr.Container.RuntimeConstraints.API = true
1221 cr.Container.OutputStorageClasses = []string{"default"}
1223 bindmounts, err := cr.SetupMounts()
1225 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1226 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1227 "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1228 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/tmp": {realTemp + "/tmp2", false}, "/etc/arvados/ca-certificates.crt": {stubCertPath, true}})
1229 os.RemoveAll(cr.ArvMountPoint)
1233 cr.Container.RuntimeConstraints.API = false
1238 cr.ArvMountPoint = ""
1239 cr.Container.Mounts = map[string]arvados.Mount{
1240 "/keeptmp": {Kind: "collection", Writable: true},
1242 cr.Container.OutputPath = "/keeptmp"
1244 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1246 bindmounts, err := cr.SetupMounts()
1248 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1249 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1250 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1251 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/keeptmp": {realTemp + "/keep1/tmp0", false}})
1252 os.RemoveAll(cr.ArvMountPoint)
1259 cr.ArvMountPoint = ""
1260 cr.Container.Mounts = map[string]arvados.Mount{
1261 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1262 "/keepout": {Kind: "collection", Writable: true},
1264 cr.Container.OutputPath = "/keepout"
1266 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1267 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1269 bindmounts, err := cr.SetupMounts()
1271 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1272 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1273 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1274 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1275 "/keepinp": {realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", true},
1276 "/keepout": {realTemp + "/keep1/tmp0", false},
1278 os.RemoveAll(cr.ArvMountPoint)
1285 cr.ArvMountPoint = ""
1286 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1287 cr.Container.Mounts = map[string]arvados.Mount{
1288 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1289 "/keepout": {Kind: "collection", Writable: true},
1291 cr.Container.OutputPath = "/keepout"
1293 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1294 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1296 bindmounts, err := cr.SetupMounts()
1298 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1299 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1300 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1301 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1302 "/keepinp": {realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", true},
1303 "/keepout": {realTemp + "/keep1/tmp0", false},
1305 os.RemoveAll(cr.ArvMountPoint)
1310 for _, test := range []struct {
1314 {in: "foo", out: `"foo"`},
1315 {in: nil, out: `null`},
1316 {in: map[string]int64{"foo": 123456789123456789}, out: `{"foo":123456789123456789}`},
1319 cr.ArvMountPoint = ""
1320 cr.Container.Mounts = map[string]arvados.Mount{
1321 "/mnt/test.json": {Kind: "json", Content: test.in},
1323 bindmounts, err := cr.SetupMounts()
1325 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1326 "/mnt/test.json": {realTemp + "/json2/mountdata.json", true},
1328 content, err := ioutil.ReadFile(realTemp + "/json2/mountdata.json")
1330 c.Check(content, DeepEquals, []byte(test.out))
1331 os.RemoveAll(cr.ArvMountPoint)
1336 for _, test := range []struct {
1340 {in: "foo", out: `foo`},
1341 {in: nil, out: "error"},
1342 {in: map[string]int64{"foo": 123456789123456789}, out: "error"},
1345 cr.ArvMountPoint = ""
1346 cr.Container.Mounts = map[string]arvados.Mount{
1347 "/mnt/test.txt": {Kind: "text", Content: test.in},
1349 bindmounts, err := cr.SetupMounts()
1350 if test.out == "error" {
1351 c.Check(err.Error(), Equals, "content for mount \"/mnt/test.txt\" must be a string")
1354 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1355 "/mnt/test.txt": {realTemp + "/text2/mountdata.text", true},
1357 content, err := ioutil.ReadFile(realTemp + "/text2/mountdata.text")
1359 c.Check(content, DeepEquals, []byte(test.out))
1361 os.RemoveAll(cr.ArvMountPoint)
1366 // Read-only mount points are allowed underneath output_dir mount point
1369 cr.ArvMountPoint = ""
1370 cr.Container.Mounts = make(map[string]arvados.Mount)
1371 cr.Container.Mounts = map[string]arvados.Mount{
1372 "/tmp": {Kind: "tmp"},
1373 "/tmp/foo": {Kind: "collection"},
1375 cr.Container.OutputPath = "/tmp"
1377 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1379 bindmounts, err := cr.SetupMounts()
1381 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1382 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1383 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1384 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1385 "/tmp": {realTemp + "/tmp2", false},
1386 "/tmp/foo": {realTemp + "/keep1/tmp0", true},
1388 os.RemoveAll(cr.ArvMountPoint)
1393 // Writable mount points copied to output_dir mount point
1396 cr.ArvMountPoint = ""
1397 cr.Container.Mounts = make(map[string]arvados.Mount)
1398 cr.Container.Mounts = map[string]arvados.Mount{
1399 "/tmp": {Kind: "tmp"},
1400 "/tmp/foo": {Kind: "collection",
1401 PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53",
1403 "/tmp/bar": {Kind: "collection",
1404 PortableDataHash: "59389a8f9ee9d399be35462a0f92541d+53",
1408 cr.Container.OutputPath = "/tmp"
1410 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1411 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz", os.ModePerm)
1413 rf, _ := os.Create(realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz/quux")
1414 rf.Write([]byte("bar"))
1417 _, err := cr.SetupMounts()
1419 _, err = os.Stat(cr.HostOutputDir + "/foo")
1421 _, err = os.Stat(cr.HostOutputDir + "/bar/quux")
1423 os.RemoveAll(cr.ArvMountPoint)
1428 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1431 cr.ArvMountPoint = ""
1432 cr.Container.Mounts = make(map[string]arvados.Mount)
1433 cr.Container.Mounts = map[string]arvados.Mount{
1434 "/tmp": {Kind: "tmp"},
1435 "/tmp/foo": {Kind: "tmp"},
1437 cr.Container.OutputPath = "/tmp"
1439 _, err := cr.SetupMounts()
1440 c.Check(err, NotNil)
1441 c.Check(err, ErrorMatches, `only mount points of kind 'collection', 'text' or 'json' are supported underneath the output_path.*`)
1442 os.RemoveAll(cr.ArvMountPoint)
1447 // Only mount point of kind 'collection' is allowed for stdin
1450 cr.ArvMountPoint = ""
1451 cr.Container.Mounts = make(map[string]arvados.Mount)
1452 cr.Container.Mounts = map[string]arvados.Mount{
1453 "stdin": {Kind: "tmp"},
1456 _, err := cr.SetupMounts()
1457 c.Check(err, NotNil)
1458 c.Check(err, ErrorMatches, `unsupported mount kind 'tmp' for stdin.*`)
1459 os.RemoveAll(cr.ArvMountPoint)
1467 cr.ArvMountPoint = ""
1468 (*GitMountSuite)(nil).useTestGitServer(c)
1469 cr.token = arvadostest.ActiveToken
1470 cr.Container.Mounts = make(map[string]arvados.Mount)
1471 cr.Container.Mounts = map[string]arvados.Mount{
1474 UUID: arvadostest.Repository2UUID,
1475 Commit: "fd3531f42995344f36c30b79f55f27b502f3d344",
1480 UUID: arvadostest.Repository2UUID,
1481 Commit: "5ebfab0522851df01fec11ec55a6d0f4877b542e",
1485 cr.Container.OutputPath = "/tmp"
1487 bindmounts, err := cr.SetupMounts()
1490 for path, mount := range bindmounts {
1491 c.Check(mount.ReadOnly, Equals, !cr.Container.Mounts[path].Writable, Commentf("%s %#v", path, mount))
1494 data, err := ioutil.ReadFile(bindmounts["/tip"].HostPath + "/dir1/dir2/file with mode 0644")
1496 c.Check(string(data), Equals, "\000\001\002\003")
1497 _, err = ioutil.ReadFile(bindmounts["/tip"].HostPath + "/file only on testbranch")
1498 c.Check(err, FitsTypeOf, &os.PathError{})
1499 c.Check(os.IsNotExist(err), Equals, true)
1501 data, err = ioutil.ReadFile(bindmounts["/non-tip"].HostPath + "/dir1/dir2/file with mode 0644")
1503 c.Check(string(data), Equals, "\000\001\002\003")
1504 data, err = ioutil.ReadFile(bindmounts["/non-tip"].HostPath + "/file only on testbranch")
1506 c.Check(string(data), Equals, "testfile\n")
1513 func (s *TestSuite) TestStdout(c *C) {
1515 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1516 "container_image": "` + arvadostest.DockerImage112PDH + `",
1518 "environment": {"FROBIZ": "bilbo"},
1519 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1520 "output_path": "/tmp",
1522 "runtime_constraints": {},
1526 s.fullRunHelper(c, helperRecord, nil, 0, func() {
1527 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1530 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1531 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1532 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1535 // Used by the TestStdoutWithWrongPath*()
1536 func (s *TestSuite) stdoutErrorRunHelper(c *C, record string, fn func()) (*ArvTestClient, *ContainerRunner, error) {
1537 err := json.Unmarshal([]byte(record), &s.api.Container)
1538 c.Assert(err, IsNil)
1539 s.executor.runFunc = fn
1540 s.runner.RunArvMount = (&ArvMountCmdLine{}).ArvMountTest
1541 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
1542 return s.api, &KeepTestClient{}, nil, nil
1544 return s.api, s.runner, s.runner.Run()
1547 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1548 _, _, err := s.stdoutErrorRunHelper(c, `{
1549 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1550 "output_path": "/tmp",
1553 c.Check(err, ErrorMatches, ".*Stdout path does not start with OutputPath.*")
1556 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1557 _, _, err := s.stdoutErrorRunHelper(c, `{
1558 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1559 "output_path": "/tmp",
1562 c.Check(err, ErrorMatches, ".*unsupported mount kind 'tmp' for stdout.*")
1565 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1566 _, _, err := s.stdoutErrorRunHelper(c, `{
1567 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1568 "output_path": "/tmp",
1571 c.Check(err, ErrorMatches, ".*unsupported mount kind 'collection' for stdout.*")
1574 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1575 s.fullRunHelper(c, `{
1576 "command": ["/bin/sh", "-c", "true $ARVADOS_API_HOST"],
1577 "container_image": "`+arvadostest.DockerImage112PDH+`",
1580 "mounts": {"/tmp": {"kind": "tmp"} },
1581 "output_path": "/tmp",
1583 "runtime_constraints": {"API": true},
1585 }`, nil, 0, func() {
1586 c.Check(s.executor.created.Env["ARVADOS_API_HOST"], Equals, os.Getenv("ARVADOS_API_HOST"))
1587 s.executor.exit <- 3
1589 c.Check(s.api.CalledWith("container.exit_code", 3), NotNil)
1590 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1591 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*status code 3\n.*`)
1594 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1595 defer os.Setenv("ARVADOS_API_HOST", os.Getenv("ARVADOS_API_HOST"))
1596 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1597 s.fullRunHelper(c, `{
1598 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1599 "container_image": "`+arvadostest.DockerImage112PDH+`",
1602 "mounts": {"/tmp": {"kind": "tmp"} },
1603 "output_path": "/tmp",
1605 "runtime_constraints": {"API": true},
1607 }`, nil, 0, func() {
1608 s.api.Container.Output = arvadostest.DockerImage112PDH
1611 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1612 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1613 c.Check(s.api.CalledWith("container.output", arvadostest.DockerImage112PDH), NotNil)
1616 func (s *TestSuite) TestArvMountRuntimeStatusWarning(c *C) {
1617 s.runner.RunArvMount = func([]string, string) (*exec.Cmd, error) {
1618 os.Mkdir(s.runner.ArvMountPoint+"/by_id", 0666)
1619 ioutil.WriteFile(s.runner.ArvMountPoint+"/by_id/README", nil, 0666)
1620 return s.runner.ArvMountCmd([]string{"bash", "-c", "echo >&2 Test: Keep write error: I am a teapot; sleep 3"}, "")
1622 s.executor.runFunc = func() {
1623 time.Sleep(time.Second)
1624 s.executor.exit <- 137
1627 "command": ["sleep", "1"],
1628 "container_image": "` + arvadostest.DockerImage112PDH + `",
1631 "mounts": {"/tmp": {"kind": "tmp"} },
1632 "output_path": "/tmp",
1634 "runtime_constraints": {"API": true},
1637 err := json.Unmarshal([]byte(record), &s.api.Container)
1638 c.Assert(err, IsNil)
1639 err = s.runner.Run()
1640 c.Assert(err, IsNil)
1641 c.Check(s.api.CalledWith("container.exit_code", 137), NotNil)
1642 c.Check(s.api.CalledWith("container.runtime_status.warning", "arv-mount: Keep write error"), NotNil)
1643 c.Check(s.api.CalledWith("container.runtime_status.warningDetail", "Test: Keep write error: I am a teapot"), NotNil)
1644 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1645 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Container exited with status code 137 \(signal 9, SIGKILL\).*`)
1648 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1650 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1651 "container_image": "` + arvadostest.DockerImage112PDH + `",
1653 "environment": {"FROBIZ": "bilbo"},
1655 "/tmp": {"kind": "tmp"},
1656 "/tmp/foo": {"kind": "collection",
1657 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1658 "exclude_from_output": true
1660 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1662 "output_path": "/tmp",
1664 "runtime_constraints": {},
1668 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1670 s.fullRunHelper(c, helperRecord, extraMounts, 0, func() {
1671 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1674 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1675 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1676 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1679 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1681 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1682 "container_image": "` + arvadostest.DockerImage112PDH + `",
1684 "environment": {"FROBIZ": "bilbo"},
1686 "/tmp": {"kind": "tmp"},
1687 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1688 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1689 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1690 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1691 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1693 "output_path": "/tmp",
1695 "runtime_constraints": {},
1699 extraMounts := []string{
1700 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1701 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1702 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1705 api, _, realtemp := s.fullRunHelper(c, helperRecord, extraMounts, 0, func() {
1706 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1709 c.Check(s.executor.created.BindMounts, DeepEquals, map[string]bindmount{
1710 "/tmp": {realtemp + "/tmp1", false},
1711 "/tmp/foo/bar": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt", true},
1712 "/tmp/foo/baz/sub2file2": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt", true},
1713 "/tmp/foo/sub1": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1", true},
1714 "/tmp/foo/sub1file2": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt", true},
1717 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1718 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1719 for _, v := range api.Content {
1720 if v["collection"] != nil {
1721 c.Check(v["ensure_unique_name"], Equals, true)
1722 collection := v["collection"].(arvadosclient.Dict)
1723 if strings.Index(collection["name"].(string), "output") == 0 {
1724 manifest := collection["manifest_text"].(string)
1726 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1727 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:bar 36:18:sub1file2
1728 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1729 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1730 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1737 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1739 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1740 "container_image": "` + arvadostest.DockerImage112PDH + `",
1742 "environment": {"FROBIZ": "bilbo"},
1744 "/tmp": {"kind": "tmp"},
1745 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/subdir1/file2_in_subdir1.txt"},
1746 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1748 "output_path": "/tmp",
1750 "runtime_constraints": {},
1754 extraMounts := []string{
1755 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1758 s.fullRunHelper(c, helperRecord, extraMounts, 0, func() {
1759 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1762 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1763 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1764 for _, v := range s.api.Content {
1765 if v["collection"] != nil {
1766 collection := v["collection"].(arvadosclient.Dict)
1767 if strings.Index(collection["name"].(string), "output") == 0 {
1768 manifest := collection["manifest_text"].(string)
1770 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1771 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
1778 func (s *TestSuite) TestOutputError(c *C) {
1780 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1781 "container_image": "` + arvadostest.DockerImage112PDH + `",
1783 "environment": {"FROBIZ": "bilbo"},
1785 "/tmp": {"kind": "tmp"}
1787 "output_path": "/tmp",
1789 "runtime_constraints": {},
1792 s.fullRunHelper(c, helperRecord, nil, 0, func() {
1793 os.Symlink("/etc/hosts", s.runner.HostOutputDir+"/baz")
1796 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
1799 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
1801 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1802 "container_image": "` + arvadostest.DockerImage112PDH + `",
1804 "environment": {"FROBIZ": "bilbo"},
1806 "/tmp": {"kind": "tmp"},
1807 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
1808 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1810 "output_path": "/tmp",
1812 "runtime_constraints": {},
1816 extraMounts := []string{
1817 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
1820 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, 0, func() {
1821 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1824 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1825 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1826 for _, v := range api.Content {
1827 if v["collection"] != nil {
1828 collection := v["collection"].(arvadosclient.Dict)
1829 if strings.Index(collection["name"].(string), "output") == 0 {
1830 manifest := collection["manifest_text"].(string)
1831 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1838 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
1840 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1841 "container_image": "` + arvadostest.DockerImage112PDH + `",
1843 "environment": {"FROBIZ": "bilbo"},
1845 "/tmp": {"kind": "tmp"},
1846 "stdin": {"kind": "json", "content": "foo"},
1847 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1849 "output_path": "/tmp",
1851 "runtime_constraints": {},
1855 api, _, _ := s.fullRunHelper(c, helperRecord, nil, 0, func() {
1856 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1859 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1860 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1861 for _, v := range api.Content {
1862 if v["collection"] != nil {
1863 collection := v["collection"].(arvadosclient.Dict)
1864 if strings.Index(collection["name"].(string), "output") == 0 {
1865 manifest := collection["manifest_text"].(string)
1866 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1873 func (s *TestSuite) TestStderrMount(c *C) {
1874 api, cr, _ := s.fullRunHelper(c, `{
1875 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
1876 "container_image": "`+arvadostest.DockerImage112PDH+`",
1879 "mounts": {"/tmp": {"kind": "tmp"},
1880 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
1881 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
1882 "output_path": "/tmp",
1884 "runtime_constraints": {},
1886 }`, nil, 1, func() {
1887 fmt.Fprintln(s.executor.created.Stdout, "hello")
1888 fmt.Fprintln(s.executor.created.Stderr, "oops")
1891 final := api.CalledWith("container.state", "Complete")
1892 c.Assert(final, NotNil)
1893 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1894 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1896 c.Check(cr.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", "./a b1946ac92492d2347c6235b4d2611184+6 0:6:out.txt\n./b 38af5c54926b620264ab1501150cf189+5 0:5:err.txt\n"), NotNil)
1899 func (s *TestSuite) TestNumberRoundTrip(c *C) {
1900 s.api.callraw = true
1901 err := s.runner.fetchContainerRecord()
1902 c.Assert(err, IsNil)
1903 jsondata, err := json.Marshal(s.runner.Container.Mounts["/json"].Content)
1904 c.Logf("%#v", s.runner.Container)
1906 c.Check(string(jsondata), Equals, `{"number":123456789123456789}`)
1909 func (s *TestSuite) TestFullBrokenDocker(c *C) {
1911 for _, setup := range []func(){
1913 c.Log("// waitErr = ocl runtime error")
1914 s.executor.waitErr = 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\\\"\""`)
1915 nextState = "Cancelled"
1918 c.Log("// loadErr = cannot connect")
1919 s.executor.loadErr = errors.New("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
1920 s.runner.brokenNodeHook = c.MkDir() + "/broken-node-hook"
1921 err := ioutil.WriteFile(s.runner.brokenNodeHook, []byte("#!/bin/sh\nexec echo killme\n"), 0700)
1922 c.Assert(err, IsNil)
1923 nextState = "Queued"
1928 s.fullRunHelper(c, `{
1929 "command": ["echo", "hello world"],
1930 "container_image": "`+arvadostest.DockerImage112PDH+`",
1933 "mounts": {"/tmp": {"kind": "tmp"} },
1934 "output_path": "/tmp",
1936 "runtime_constraints": {},
1938 }`, nil, 0, func() {})
1939 c.Check(s.api.CalledWith("container.state", nextState), NotNil)
1940 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
1941 if s.runner.brokenNodeHook != "" {
1942 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Running broken node hook.*")
1943 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*killme.*")
1944 c.Check(s.api.Logs["crunch-run"].String(), Not(Matches), "(?ms).*Writing /var/lock/crunch-run-broken to mark node as broken.*")
1946 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Writing /var/lock/crunch-run-broken to mark node as broken.*")
1951 func (s *TestSuite) TestBadCommand(c *C) {
1952 for _, startError := range []string{
1953 `panic: standard_init_linux.go:175: exec user process caused "no such file or directory"`,
1954 `Error response from daemon: Cannot start container 41f26cbc43bcc1280f4323efb1830a394ba8660c9d1c2b564ba42bf7f7694845: [8] System error: no such file or directory`,
1955 `Error response from daemon: Cannot start container 58099cd76c834f3dc2a4fb76c8028f049ae6d4fdf0ec373e1f2cfea030670c2d: [8] System error: exec: "foobar": executable file not found in $PATH`,
1958 s.executor.startErr = errors.New(startError)
1959 s.fullRunHelper(c, `{
1960 "command": ["echo", "hello world"],
1961 "container_image": "`+arvadostest.DockerImage112PDH+`",
1964 "mounts": {"/tmp": {"kind": "tmp"} },
1965 "output_path": "/tmp",
1967 "runtime_constraints": {},
1969 }`, nil, 0, func() {})
1970 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
1971 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
1975 func (s *TestSuite) TestSecretTextMountPoint(c *C) {
1977 "command": ["true"],
1978 "container_image": "` + arvadostest.DockerImage112PDH + `",
1981 "/tmp": {"kind": "tmp"},
1982 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
1986 "output_path": "/tmp",
1988 "runtime_constraints": {},
1992 s.fullRunHelper(c, helperRecord, nil, 0, func() {
1993 content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf")
1995 c.Check(string(content), Equals, "mypassword")
1998 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1999 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2000 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". 34819d7beeabb9260a5c854bc85b3e44+10 0:10:secret.conf\n"), NotNil)
2001 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ""), IsNil)
2003 // under secret mounts, not captured in output
2005 "command": ["true"],
2006 "container_image": "` + arvadostest.DockerImage112PDH + `",
2009 "/tmp": {"kind": "tmp"}
2012 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2014 "output_path": "/tmp",
2016 "runtime_constraints": {},
2021 s.fullRunHelper(c, helperRecord, nil, 0, func() {
2022 content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf")
2024 c.Check(string(content), Equals, "mypassword")
2027 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2028 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2029 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". 34819d7beeabb9260a5c854bc85b3e44+10 0:10:secret.conf\n"), IsNil)
2030 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ""), NotNil)
2032 // under secret mounts, output dir is a collection, not captured in output
2034 "command": ["true"],
2035 "container_image": "` + arvadostest.DockerImage112PDH + `",
2038 "/tmp": {"kind": "collection", "writable": true}
2041 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2043 "output_path": "/tmp",
2045 "runtime_constraints": {},
2050 _, _, realtemp := s.fullRunHelper(c, helperRecord, nil, 0, func() {
2051 // secret.conf should be provisioned as a separate
2052 // bind mount, i.e., it should not appear in the
2053 // (fake) fuse filesystem as viewed from the host.
2054 content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf")
2055 if !c.Check(errors.Is(err, os.ErrNotExist), Equals, true) {
2056 c.Logf("secret.conf: content %q, err %#v", content, err)
2058 err = ioutil.WriteFile(s.runner.HostOutputDir+"/.arvados#collection", []byte(`{"manifest_text":". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n"}`), 0700)
2062 content, err := ioutil.ReadFile(realtemp + "/text1/mountdata.text")
2064 c.Check(string(content), Equals, "mypassword")
2065 c.Check(s.executor.created.BindMounts["/tmp/secret.conf"], DeepEquals, bindmount{realtemp + "/text1/mountdata.text", true})
2066 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2067 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2068 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n"), NotNil)
2071 type FakeProcess struct {
2075 func (fp FakeProcess) CmdlineSlice() ([]string, error) {
2076 return fp.cmdLine, nil