1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
35 "git.arvados.org/arvados.git/lib/cloud"
36 "git.arvados.org/arvados.git/lib/cmd"
37 "git.arvados.org/arvados.git/sdk/go/arvados"
38 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
39 "git.arvados.org/arvados.git/sdk/go/arvadostest"
40 "git.arvados.org/arvados.git/sdk/go/manifest"
45 // Gocheck boilerplate
46 func TestCrunchExec(t *testing.T) {
50 const logLineStart = `(?m)(.*\n)*\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+Z `
52 var _ = Suite(&TestSuite{})
54 type TestSuite struct {
55 client *arvados.Client
57 runner *ContainerRunner
58 executor *stubExecutor
61 testDispatcherKeepClient KeepTestClient
62 testContainerKeepClient KeepTestClient
63 debian12MemoryCurrent int64
64 debian12SwapCurrent int64
67 func (s *TestSuite) SetUpSuite(c *C) {
68 buf, err := os.ReadFile("../crunchstat/testdata/debian12/sys/fs/cgroup/user.slice/user-1000.slice/session-4.scope/memory.current")
70 _, err = fmt.Sscanf(string(buf), "%d", &s.debian12MemoryCurrent)
73 buf, err = os.ReadFile("../crunchstat/testdata/debian12/sys/fs/cgroup/user.slice/user-1000.slice/session-4.scope/memory.swap.current")
75 _, err = fmt.Sscanf(string(buf), "%d", &s.debian12SwapCurrent)
79 func (s *TestSuite) SetUpTest(c *C) {
80 s.client = arvados.NewClientFromEnv()
81 s.executor = &stubExecutor{}
83 s.api = &ArvTestClient{}
84 s.runner, err = NewContainerRunner(s.client, s.api, &s.testDispatcherKeepClient, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
86 s.runner.executor = s.executor
87 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
88 return s.api, &s.testContainerKeepClient, s.client, nil
90 s.runner.RunArvMount = func(cmd []string, tok string) (*exec.Cmd, error) {
91 s.runner.ArvMountPoint = s.keepmount
92 for i, opt := range cmd {
93 if opt == "--mount-tmp" {
94 err := os.Mkdir(s.keepmount+"/"+cmd[i+1], 0700)
98 s.keepmountTmp = append(s.keepmountTmp, cmd[i+1])
103 s.keepmount = c.MkDir()
104 err = os.Mkdir(s.keepmount+"/by_id", 0755)
107 err = os.Mkdir(s.keepmount+"/by_id/"+arvadostest.DockerImage112PDH, 0755)
109 err = ioutil.WriteFile(s.keepmount+"/by_id/"+arvadostest.DockerImage112PDH+"/"+arvadostest.DockerImage112Filename, []byte("#notarealtarball"), 0644)
110 err = os.Mkdir(s.keepmount+"/by_id/"+fakeInputCollectionPDH, 0755)
112 err = ioutil.WriteFile(s.keepmount+"/by_id/"+fakeInputCollectionPDH+"/input.json", []byte(`{"input":true}`), 0644)
114 s.runner.ArvMountPoint = s.keepmount
115 os.Setenv("InstanceType", `{"ProviderType":"a1.2xlarge","Price":1.2}`)
118 type ArvTestClient struct {
121 Content []arvadosclient.Dict
124 Logs map[string]*bytes.Buffer
130 type KeepTestClient struct {
132 StorageClasses []string
136 type stubExecutor struct {
142 created containerSpec
144 waitSleep time.Duration
153 func (e *stubExecutor) LoadImage(imageId string, tarball string, container arvados.Container, keepMount string,
154 containerClient *arvados.Client) error {
158 func (e *stubExecutor) Runtime() string { return "stub" }
159 func (e *stubExecutor) Version() string { return "stub " + cmd.Version.String() }
160 func (e *stubExecutor) Create(spec containerSpec) error { e.created = spec; return e.createErr }
161 func (e *stubExecutor) Start() error {
162 e.exit = make(chan int, 1)
163 go func() { e.exit <- e.runFunc() }()
166 func (e *stubExecutor) Pid() int { return 1115883 } // matches pid in ../crunchstat/testdata/debian12/proc/
167 func (e *stubExecutor) Stop() error { e.stopped = true; go func() { e.exit <- -1 }(); return e.stopErr }
168 func (e *stubExecutor) Close() { e.closed = true }
169 func (e *stubExecutor) Wait(context.Context) (int, error) {
170 return <-e.exit, e.waitErr
172 func (e *stubExecutor) InjectCommand(ctx context.Context, _, _ string, _ bool, _ []string) (*exec.Cmd, error) {
173 return nil, errors.New("unimplemented")
175 func (e *stubExecutor) IPAddress() (string, error) { return "", errors.New("unimplemented") }
177 const fakeInputCollectionPDH = "ffffffffaaaaaaaa88888888eeeeeeee+1234"
179 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
180 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
181 var hwImageID = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
183 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
184 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
186 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
187 ./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
188 ./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
191 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
193 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"
194 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
196 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
197 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
199 func (client *ArvTestClient) Create(resourceType string,
200 parameters arvadosclient.Dict,
201 output interface{}) error {
204 defer client.Mutex.Unlock()
207 client.Content = append(client.Content, parameters)
209 if resourceType == "logs" {
210 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
211 if client.Logs == nil {
212 client.Logs = make(map[string]*bytes.Buffer)
214 if client.Logs[et] == nil {
215 client.Logs[et] = &bytes.Buffer{}
217 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
220 if resourceType == "collections" && output != nil {
221 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
222 md5sum := md5.Sum([]byte(mt))
223 outmap := output.(*arvados.Collection)
224 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5sum, len(mt))
225 outmap.UUID = fmt.Sprintf("zzzzz-4zz18-%015x", md5sum[:7])
231 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
233 case method == "GET" && resourceType == "containers" && action == "auth":
234 return json.Unmarshal([]byte(`{
235 "kind": "arvados#api_client_authorization",
236 "uuid": "`+fakeAuthUUID+`",
237 "api_token": "`+fakeAuthToken+`"
239 case method == "GET" && resourceType == "containers" && action == "secret_mounts":
240 if client.secretMounts != nil {
241 return json.Unmarshal(client.secretMounts, output)
243 return json.Unmarshal([]byte(`{"secret_mounts":{}}`), output)
245 return fmt.Errorf("Not found")
249 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
250 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
252 if method == "GET" && resourceType == "nodes" && uuid == "" && action == "" {
254 "kind": "arvados#nodeList",
256 "uuid": "zzzzz-7ekkf-2z3mc76g2q73aio",
257 "hostname": "compute2",
258 "properties": {"total_cpu_cores": 16}
260 } else if method == "GET" && resourceType == "containers" && action == "" && !client.callraw {
262 j, err = json.Marshal(map[string]interface{}{
263 "items": []interface{}{client.Container},
264 "kind": "arvados#nodeList",
267 j, err = json.Marshal(client.Container)
271 "command": ["sleep", "1"],
272 "container_image": "` + arvadostest.DockerImage112PDH + `",
275 "mounts": {"/tmp": {"kind": "tmp"}, "/json": {"kind": "json", "content": {"number": 123456789123456789}}},
276 "output_path": "/tmp",
278 "runtime_constraints": {}
281 return ioutil.NopCloser(bytes.NewReader(j)), err
284 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
285 if resourceType == "collections" {
287 output.(*arvados.Collection).ManifestText = hwManifest
288 } else if uuid == otherPDH {
289 output.(*arvados.Collection).ManifestText = otherManifest
290 } else if uuid == normalizedWithSubdirsPDH {
291 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
292 } else if uuid == denormalizedWithSubdirsPDH {
293 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
296 if resourceType == "containers" {
297 (*output.(*arvados.Container)) = client.Container
302 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
304 defer client.Mutex.Unlock()
306 client.Content = append(client.Content, parameters)
307 if resourceType == "containers" {
308 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
309 client.WasSetRunning = true
311 } else if resourceType == "collections" && output != nil {
312 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
313 output.(*arvados.Collection).UUID = uuid
314 output.(*arvados.Collection).PortableDataHash = fmt.Sprintf("%x", md5.Sum([]byte(mt)))
319 var discoveryMap = map[string]interface{}{
320 "defaultTrashLifetime": float64(1209600),
321 "crunchLimitLogBytesPerJob": float64(67108864),
322 "crunchLogThrottleBytes": float64(65536),
323 "crunchLogThrottlePeriod": float64(60),
324 "crunchLogThrottleLines": float64(1024),
325 "crunchLogPartialLineThrottlePeriod": float64(5),
326 "crunchLogBytesPerEvent": float64(4096),
327 "crunchLogSecondsBetweenEvents": float64(1),
330 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
331 return discoveryMap[key], nil
334 // CalledWith returns the parameters from the first API call whose
335 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
336 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
337 // no call matches, it returns nil.
338 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
340 for _, content := range client.Content {
341 var v interface{} = content
342 for _, k := range strings.Split(jpath, ".") {
343 if dict, ok := v.(arvadosclient.Dict); !ok {
356 func (client *KeepTestClient) LocalLocator(locator string) (string, error) {
360 func (client *KeepTestClient) BlockWrite(_ context.Context, opts arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) {
361 locator := fmt.Sprintf("%x+%d", md5.Sum(opts.Data), len(opts.Data))
362 client.blocks.Store(locator, append([]byte(nil), opts.Data...))
363 return arvados.BlockWriteResponse{
368 func (client *KeepTestClient) ReadAt(locator string, dst []byte, offset int) (int, error) {
369 loaded, ok := client.blocks.Load(locator)
371 return 0, os.ErrNotExist
373 data := loaded.([]byte)
374 if offset >= len(data) {
377 return copy(dst, data[offset:]), nil
380 func (client *KeepTestClient) Close() {
381 client.blocks.Range(func(locator, value interface{}) bool {
382 client.blocks.Delete(locator)
387 func (client *KeepTestClient) SetStorageClasses(sc []string) {
388 client.StorageClasses = sc
391 type FileWrapper struct {
396 func (fw FileWrapper) Readdir(n int) ([]os.FileInfo, error) {
397 return nil, errors.New("not implemented")
400 func (fw FileWrapper) Seek(int64, int) (int64, error) {
401 return 0, errors.New("not implemented")
404 func (fw FileWrapper) Size() int64 {
408 func (fw FileWrapper) Stat() (os.FileInfo, error) {
409 return nil, errors.New("not implemented")
412 func (fw FileWrapper) Truncate(int64) error {
413 return errors.New("not implemented")
416 func (fw FileWrapper) Write([]byte) (int, error) {
417 return 0, errors.New("not implemented")
420 func (fw FileWrapper) Sync() error {
421 return errors.New("not implemented")
424 func (fw FileWrapper) Snapshot() (*arvados.Subtree, error) {
425 return nil, errors.New("not implemented")
428 func (fw FileWrapper) Splice(*arvados.Subtree) error {
429 return errors.New("not implemented")
432 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
433 if filename == hwImageID+".tar" {
434 rdr := ioutil.NopCloser(&bytes.Buffer{})
436 return FileWrapper{rdr, 1321984}, nil
437 } else if filename == "/file1_in_main.txt" {
438 rdr := ioutil.NopCloser(strings.NewReader("foo"))
440 return FileWrapper{rdr, 3}, nil
445 type apiStubServer struct {
446 server *httptest.Server
447 proxy *httputil.ReverseProxy
448 intercept func(http.ResponseWriter, *http.Request) bool
450 container arvados.Container
451 logs map[string]string
454 func apiStub() (*arvados.Client, *apiStubServer) {
455 client := arvados.NewClientFromEnv()
456 apistub := &apiStubServer{}
457 apistub.server = httptest.NewTLSServer(apistub)
458 apistub.proxy = httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "https", Host: client.APIHost})
460 apistub.proxy.Transport = arvados.InsecureHTTPClient.Transport
462 client.APIHost = apistub.server.Listener.Addr().String()
463 return client, apistub
466 func (apistub *apiStubServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
467 if apistub.intercept != nil && apistub.intercept(w, r) {
470 if r.Method == "POST" && r.URL.Path == "/arvados/v1/logs" {
473 EventType string `json:"event_type"`
479 json.NewDecoder(r.Body).Decode(&body)
480 apistub.logs[body.Log.EventType] += body.Log.Properties.Text
483 if r.Method == "GET" && r.URL.Path == "/arvados/v1/collections/"+hwPDH {
484 json.NewEncoder(w).Encode(arvados.Collection{ManifestText: hwManifest})
487 if r.Method == "GET" && r.URL.Path == "/arvados/v1/collections/"+otherPDH {
488 json.NewEncoder(w).Encode(arvados.Collection{ManifestText: otherManifest})
491 if r.Method == "GET" && r.URL.Path == "/arvados/v1/collections/"+normalizedWithSubdirsPDH {
492 json.NewEncoder(w).Encode(arvados.Collection{ManifestText: normalizedManifestWithSubdirs})
495 if r.Method == "GET" && r.URL.Path == "/arvados/v1/collections/"+denormalizedWithSubdirsPDH {
496 json.NewEncoder(w).Encode(arvados.Collection{ManifestText: denormalizedManifestWithSubdirs})
499 if r.Method == "GET" && r.URL.Path == "/arvados/v1/containers/"+apistub.container.UUID {
500 json.NewEncoder(w).Encode(apistub.container)
503 apistub.proxy.ServeHTTP(w, r)
506 func (s *TestSuite) TestLoadImage(c *C) {
507 s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH
508 s.runner.Container.Mounts = map[string]arvados.Mount{
509 "/out": {Kind: "tmp", Writable: true},
511 s.runner.Container.OutputPath = "/out"
513 _, err := s.runner.SetupMounts()
516 imageID, err := s.runner.LoadImage()
518 c.Check(s.executor.loaded, Matches, ".*"+regexp.QuoteMeta(arvadostest.DockerImage112Filename))
519 c.Check(imageID, Equals, strings.TrimSuffix(arvadostest.DockerImage112Filename, ".tar"))
521 s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH
522 s.executor.imageLoaded = false
523 s.executor.loaded = ""
524 s.executor.loadErr = errors.New("bork")
525 imageID, err = s.runner.LoadImage()
526 c.Check(err, ErrorMatches, ".*bork")
527 c.Check(s.executor.loaded, Matches, ".*"+regexp.QuoteMeta(arvadostest.DockerImage112Filename))
529 s.runner.Container.ContainerImage = fakeInputCollectionPDH
530 s.executor.imageLoaded = false
531 s.executor.loaded = ""
532 s.executor.loadErr = nil
533 imageID, err = s.runner.LoadImage()
534 c.Check(err, ErrorMatches, "image collection does not include a \\.tar image file")
535 c.Check(s.executor.loaded, Equals, "")
538 type ArvErrorTestClient struct{}
540 func (ArvErrorTestClient) Create(resourceType string,
541 parameters arvadosclient.Dict,
542 output interface{}) error {
546 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
547 if method == "GET" && resourceType == "containers" && action == "auth" {
550 return errors.New("ArvError")
553 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
554 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
555 return nil, errors.New("ArvError")
558 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
559 return errors.New("ArvError")
562 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
566 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
567 return discoveryMap[key], nil
570 type KeepErrorTestClient struct {
574 func (*KeepErrorTestClient) ManifestFileReader(manifest.Manifest, string) (arvados.File, error) {
575 return nil, errors.New("KeepError")
578 func (*KeepErrorTestClient) BlockWrite(context.Context, arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) {
579 return arvados.BlockWriteResponse{}, errors.New("KeepError")
582 func (*KeepErrorTestClient) LocalLocator(string) (string, error) {
583 return "", errors.New("KeepError")
586 type KeepReadErrorTestClient struct {
590 func (*KeepReadErrorTestClient) ReadAt(string, []byte, int) (int, error) {
591 return 0, errors.New("KeepError")
594 type ErrorReader struct {
598 func (ErrorReader) Read(p []byte) (n int, err error) {
599 return 0, errors.New("ErrorReader")
602 func (ErrorReader) Seek(int64, int) (int64, error) {
603 return 0, errors.New("ErrorReader")
606 func (*KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
607 return ErrorReader{}, nil
610 type ClosableBuffer struct {
614 func (*ClosableBuffer) Close() error {
618 type TestLogs struct {
619 Stdout ClosableBuffer
620 Stderr ClosableBuffer
623 func (tl *TestLogs) NewTestLoggingWriter(logstr string) (io.WriteCloser, error) {
624 if logstr == "stdout" {
625 return &tl.Stdout, nil
627 if logstr == "stderr" {
628 return &tl.Stderr, nil
630 return nil, errors.New("???")
633 func dockerLog(fd byte, msg string) []byte {
635 header := make([]byte, 8+len(by))
637 header[7] = byte(len(by))
642 func (s *TestSuite) TestRunContainer(c *C) {
643 s.executor.runFunc = func() int {
644 fmt.Fprintf(s.executor.created.Stdout, "Hello world\n")
649 s.runner.NewLogWriter = logs.NewTestLoggingWriter
650 s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH
651 s.runner.Container.Command = []string{"./hw"}
652 s.runner.Container.OutputStorageClasses = []string{"default"}
654 imageID, err := s.runner.LoadImage()
657 err = s.runner.CreateContainer(imageID, nil)
660 err = s.runner.StartContainer()
663 err = s.runner.WaitFinish()
666 c.Check(logs.Stdout.String(), Matches, ".*Hello world\n")
667 c.Check(logs.Stderr.String(), Equals, "")
670 func (s *TestSuite) TestCommitLogs(c *C) {
671 api := &ArvTestClient{}
672 kc := &KeepTestClient{}
674 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
676 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
678 cr.CrunchLog.Print("Hello world!")
679 cr.CrunchLog.Print("Goodbye")
680 cr.finalState = "Complete"
682 err = cr.CommitLogs()
685 c.Check(api.Calls, Equals, 2)
686 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
687 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
688 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
689 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
692 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
693 api := &ArvTestClient{}
694 kc := &KeepTestClient{}
696 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
699 err = cr.UpdateContainerRunning("")
702 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
705 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
706 api := &ArvTestClient{}
707 kc := &KeepTestClient{}
709 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
712 cr.LogsPDH = new(string)
713 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
715 cr.ExitCode = new(int)
717 cr.finalState = "Complete"
719 err = cr.UpdateContainerFinal()
722 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
723 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
724 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
727 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
728 api := &ArvTestClient{}
729 kc := &KeepTestClient{}
731 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
734 cr.finalState = "Cancelled"
736 err = cr.UpdateContainerFinal()
739 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
740 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
741 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
744 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
745 // dress rehearsal of the Run() function, starting from a JSON container record.
746 func (s *TestSuite) fullRunHelper(c *C, record string, extraMounts []string, fn func() int) (*ArvTestClient, *ContainerRunner, string) {
747 err := json.Unmarshal([]byte(record), &s.api.Container)
749 initialState := s.api.Container.State
752 SecretMounts map[string]arvados.Mount `json:"secret_mounts"`
754 err = json.Unmarshal([]byte(record), &sm)
756 secretMounts, err := json.Marshal(sm)
758 c.Logf("SecretMounts decoded %v json %q", sm, secretMounts)
760 s.executor.runFunc = fn
762 s.runner.statInterval = 100 * time.Millisecond
763 s.runner.containerWatchdogInterval = time.Second
765 realTemp := c.MkDir()
767 s.runner.MkTempDir = func(_, prefix string) (string, error) {
769 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
770 err := os.Mkdir(d, os.ModePerm)
771 if err != nil && strings.Contains(err.Error(), ": file exists") {
772 // Test case must have pre-populated the tempdir
777 client, _ := apiStub()
778 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
779 return &ArvTestClient{secretMounts: secretMounts}, &s.testContainerKeepClient, client, nil
782 if extraMounts != nil && len(extraMounts) > 0 {
783 err := s.runner.SetupArvMountPoint("keep")
786 for _, m := range extraMounts {
787 os.MkdirAll(s.runner.ArvMountPoint+"/by_id/"+m, os.ModePerm)
792 if s.api.CalledWith("container.state", "Complete") != nil {
795 if s.executor.loadErr == nil && s.executor.createErr == nil && initialState != "Running" {
796 c.Check(s.api.WasSetRunning, Equals, true)
797 var lastupdate arvadosclient.Dict
798 for _, content := range s.api.Content {
799 if content["container"] != nil {
800 lastupdate = content["container"].(arvadosclient.Dict)
803 if lastupdate["log"] == nil {
804 c.Errorf("no container update with non-nil log -- updates were: %v", s.api.Content)
809 for k, v := range s.api.Logs {
815 return s.api, s.runner, realTemp
818 func (s *TestSuite) TestFullRunHello(c *C) {
819 s.runner.enableMemoryLimit = true
820 s.runner.networkMode = "default"
821 s.fullRunHelper(c, `{
822 "command": ["echo", "hello world"],
823 "container_image": "`+arvadostest.DockerImage112PDH+`",
825 "environment": {"foo":"bar","baz":"waz"},
826 "mounts": {"/tmp": {"kind": "tmp"} },
827 "output_path": "/tmp",
829 "runtime_constraints": {"vcpus":1,"ram":1000000},
831 "output_storage_classes": ["default"]
832 }`, nil, func() int {
833 c.Check(s.executor.created.Command, DeepEquals, []string{"echo", "hello world"})
834 c.Check(s.executor.created.Image, Equals, "sha256:d8309758b8fe2c81034ffc8a10c36460b77db7bc5e7b448c4e5b684f9d95a678")
835 c.Check(s.executor.created.Env, DeepEquals, map[string]string{"foo": "bar", "baz": "waz"})
836 c.Check(s.executor.created.VCPUs, Equals, 1)
837 c.Check(s.executor.created.RAM, Equals, int64(1000000))
838 c.Check(s.executor.created.NetworkMode, Equals, "default")
839 c.Check(s.executor.created.EnableNetwork, Equals, false)
840 c.Check(s.executor.created.CUDADeviceCount, Equals, 0)
841 fmt.Fprintln(s.executor.created.Stdout, "hello world")
845 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
846 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
847 c.Check(s.api.Logs["stdout"].String(), Matches, ".*hello world\n")
848 c.Check(s.testDispatcherKeepClient.StorageClasses, DeepEquals, []string{"default"})
849 c.Check(s.testContainerKeepClient.StorageClasses, DeepEquals, []string{"default"})
852 func (s *TestSuite) TestRunAlreadyRunning(c *C) {
854 s.fullRunHelper(c, `{
855 "command": ["sleep", "3"],
856 "container_image": "`+arvadostest.DockerImage112PDH+`",
859 "mounts": {"/tmp": {"kind": "tmp"} },
860 "output_path": "/tmp",
862 "runtime_constraints": {},
863 "scheduling_parameters":{"max_run_time": 1},
865 }`, nil, func() int {
869 c.Check(s.api.CalledWith("container.state", "Cancelled"), IsNil)
870 c.Check(s.api.CalledWith("container.state", "Complete"), IsNil)
871 c.Check(ran, Equals, false)
874 func ec2MetadataServerStub(c *C, token *string, failureRate float64, stoptime *atomic.Value) *httptest.Server {
876 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
877 if !failedOnce || rand.Float64() < failureRate {
878 w.WriteHeader(http.StatusServiceUnavailable)
883 case "/latest/api/token":
884 fmt.Fprintln(w, *token)
885 case "/latest/meta-data/spot/instance-action":
886 if r.Header.Get("X-aws-ec2-metadata-token") != *token {
887 w.WriteHeader(http.StatusUnauthorized)
888 } else if t, _ := stoptime.Load().(time.Time); t.IsZero() {
889 w.WriteHeader(http.StatusNotFound)
891 fmt.Fprintf(w, `{"action":"stop","time":"%s"}`, t.Format(time.RFC3339))
894 w.WriteHeader(http.StatusNotFound)
899 func (s *TestSuite) TestSpotInterruptionNotice(c *C) {
900 s.testSpotInterruptionNotice(c, 0.1)
903 func (s *TestSuite) TestSpotInterruptionNoticeNotAvailable(c *C) {
904 s.testSpotInterruptionNotice(c, 1)
907 func (s *TestSuite) testSpotInterruptionNotice(c *C, failureRate float64) {
908 var stoptime atomic.Value
909 token := "fake-ec2-metadata-token"
910 stub := ec2MetadataServerStub(c, &token, failureRate, &stoptime)
913 defer func(i time.Duration, u string) {
914 spotInterruptionCheckInterval = i
915 ec2MetadataBaseURL = u
916 }(spotInterruptionCheckInterval, ec2MetadataBaseURL)
917 spotInterruptionCheckInterval = time.Second / 8
918 ec2MetadataBaseURL = stub.URL
920 go s.runner.checkSpotInterruptionNotices()
921 s.fullRunHelper(c, `{
922 "command": ["sleep", "3"],
923 "container_image": "`+arvadostest.DockerImage112PDH+`",
926 "mounts": {"/tmp": {"kind": "tmp"} },
927 "output_path": "/tmp",
929 "runtime_constraints": {},
931 }`, nil, func() int {
932 time.Sleep(time.Second)
933 stoptime.Store(time.Now().Add(time.Minute).UTC())
934 token = "different-fake-ec2-metadata-token"
935 time.Sleep(time.Second)
938 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Checking for spot interruptions every 125ms using instance metadata at http://.*`)
939 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Error checking spot interruptions: 503 Service Unavailable.*`)
940 if failureRate == 1 {
941 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Giving up on checking spot interruptions after too many consecutive failures.*`)
943 text := `Cloud provider scheduled instance stop at ` + stoptime.Load().(time.Time).Format(time.RFC3339)
944 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*`+text+`.*`)
945 c.Check(s.api.CalledWith("container.runtime_status.warning", "preemption notice"), NotNil)
946 c.Check(s.api.CalledWith("container.runtime_status.warningDetail", text), NotNil)
947 c.Check(s.api.CalledWith("container.runtime_status.preemptionNotice", text), NotNil)
951 func (s *TestSuite) TestRunTimeExceeded(c *C) {
952 s.fullRunHelper(c, `{
953 "command": ["sleep", "3"],
954 "container_image": "`+arvadostest.DockerImage112PDH+`",
957 "mounts": {"/tmp": {"kind": "tmp"} },
958 "output_path": "/tmp",
960 "runtime_constraints": {},
961 "scheduling_parameters":{"max_run_time": 1},
963 }`, nil, func() int {
964 time.Sleep(3 * time.Second)
968 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
969 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*maximum run time exceeded.*")
972 func (s *TestSuite) TestContainerWaitFails(c *C) {
973 s.fullRunHelper(c, `{
974 "command": ["sleep", "3"],
975 "container_image": "`+arvadostest.DockerImage112PDH+`",
977 "mounts": {"/tmp": {"kind": "tmp"} },
978 "output_path": "/tmp",
981 }`, nil, func() int {
982 s.executor.waitErr = errors.New("Container is not running")
986 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
987 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Container is not running.*")
990 func (s *TestSuite) TestCrunchstat(c *C) {
991 s.runner.crunchstatFakeFS = os.DirFS("../crunchstat/testdata/debian12")
992 s.fullRunHelper(c, `{
993 "command": ["sleep", "1"],
994 "container_image": "`+arvadostest.DockerImage112PDH+`",
997 "mounts": {"/tmp": {"kind": "tmp"} },
998 "output_path": "/tmp",
1000 "runtime_constraints": {},
1002 }`, nil, func() int {
1003 time.Sleep(time.Second)
1007 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1008 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1010 c.Assert(s.api.Logs["crunchstat"], NotNil)
1011 c.Check(s.api.Logs["crunchstat"].String(), Matches, `(?ms).*mem \d+ swap \d+ pgmajfault \d+ rss.*`)
1013 // Check that we called (*crunchstat.Reporter)Stop().
1014 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Maximum crunch-run memory rss usage was \d+ bytes\n.*`)
1017 func (s *TestSuite) TestNodeInfoLog(c *C) {
1018 s.fullRunHelper(c, `{
1019 "command": ["true"],
1020 "container_image": "`+arvadostest.DockerImage112PDH+`",
1023 "mounts": {"/tmp": {"kind": "tmp"} },
1024 "output_path": "/tmp",
1026 "runtime_constraints": {},
1028 }`, nil, func() int {
1032 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1033 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1035 buf, err := fs.ReadFile(arvados.FS(s.runner.LogCollection), "/node.json")
1036 c.Assert(err, IsNil)
1038 c.Check(json, Matches, `(?ms).*"ProviderType": *"a1\.2xlarge".*`)
1039 c.Check(json, Matches, `(?ms).*"Price": *1\.2.*`)
1041 c.Assert(s.api.Logs["node-info"], NotNil)
1042 json = s.api.Logs["node-info"].String()
1043 c.Check(json, Matches, `(?ms).*Host Information.*`)
1044 c.Check(json, Matches, `(?ms).*CPU Information.*`)
1045 c.Check(json, Matches, `(?ms).*Memory Information.*`)
1046 c.Check(json, Matches, `(?ms).*Disk Space.*`)
1047 c.Check(json, Matches, `(?ms).*Disk INodes.*`)
1050 func (s *TestSuite) TestLogVersionAndRuntime(c *C) {
1051 s.fullRunHelper(c, `{
1052 "command": ["sleep", "1"],
1053 "container_image": "`+arvadostest.DockerImage112PDH+`",
1056 "mounts": {"/tmp": {"kind": "tmp"} },
1057 "output_path": "/tmp",
1059 "runtime_constraints": {},
1061 }`, nil, func() int {
1065 c.Assert(s.api.Logs["crunch-run"], NotNil)
1066 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*crunch-run \S+ \(go\S+\) start.*`)
1067 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*crunch-run process has uid=\d+\(.+\) gid=\d+\(.+\) groups=\d+\(.+\)(,\d+\(.+\))*\n.*`)
1068 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Executing container: zzzzz-zzzzz-zzzzzzzzzzzzzzz.*`)
1069 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Using container runtime: stub.*`)
1072 func (s *TestSuite) testLogRSSThresholds(c *C, ram int64, expected []int, notExpected int) {
1073 s.runner.crunchstatFakeFS = os.DirFS("../crunchstat/testdata/debian12")
1074 s.fullRunHelper(c, `{
1075 "command": ["true"],
1076 "container_image": "`+arvadostest.DockerImage112PDH+`",
1079 "mounts": {"/tmp": {"kind": "tmp"} },
1080 "output_path": "/tmp",
1082 "runtime_constraints": {"ram": `+fmt.Sprintf("%d", ram)+`},
1084 }`, nil, func() int { return 0 })
1085 c.Logf("=== crunchstat logs\n%s\n", s.api.Logs["crunchstat"].String())
1086 logs := s.api.Logs["crunch-run"].String()
1087 pattern := logLineStart + `Container using over %d%% of memory \(rss %d/%d bytes\)`
1089 for _, threshold = range expected {
1090 c.Check(logs, Matches, fmt.Sprintf(pattern, threshold, s.debian12MemoryCurrent, ram))
1092 if notExpected > threshold {
1093 c.Check(logs, Not(Matches), fmt.Sprintf(pattern, notExpected, s.debian12MemoryCurrent, ram))
1097 func (s *TestSuite) TestLogNoRSSThresholds(c *C) {
1098 s.testLogRSSThresholds(c, s.debian12MemoryCurrent*10, []int{}, 90)
1101 func (s *TestSuite) TestLogSomeRSSThresholds(c *C) {
1102 onePercentRSS := s.debian12MemoryCurrent / 100
1103 s.testLogRSSThresholds(c, 102*onePercentRSS, []int{90, 95}, 99)
1106 func (s *TestSuite) TestLogAllRSSThresholds(c *C) {
1107 s.testLogRSSThresholds(c, s.debian12MemoryCurrent, []int{90, 95, 99}, 0)
1110 func (s *TestSuite) TestLogMaximaAfterRun(c *C) {
1111 s.runner.crunchstatFakeFS = os.DirFS("../crunchstat/testdata/debian12")
1112 s.runner.parentTemp = c.MkDir()
1113 s.fullRunHelper(c, `{
1114 "command": ["true"],
1115 "container_image": "`+arvadostest.DockerImage112PDH+`",
1118 "mounts": {"/tmp": {"kind": "tmp"} },
1119 "output_path": "/tmp",
1121 "runtime_constraints": {"ram": `+fmt.Sprintf("%d", s.debian12MemoryCurrent*10)+`},
1123 }`, nil, func() int { return 0 })
1124 logs := s.api.Logs["crunch-run"].String()
1125 for _, expected := range []string{
1126 `Maximum disk usage was \d+%, \d+/\d+ bytes`,
1127 fmt.Sprintf(`Maximum container memory swap usage was %d bytes`, s.debian12SwapCurrent),
1128 `Maximum container memory pgmajfault usage was \d+ faults`,
1129 fmt.Sprintf(`Maximum container memory rss usage was 10%%, %d/%d bytes`, s.debian12MemoryCurrent, s.debian12MemoryCurrent*10),
1130 `Maximum crunch-run memory rss usage was \d+ bytes`,
1132 c.Check(logs, Matches, logLineStart+expected)
1136 func (s *TestSuite) TestCommitNodeInfoBeforeStart(c *C) {
1137 var collection_create, container_update arvadosclient.Dict
1138 s.fullRunHelper(c, `{
1139 "command": ["true"],
1140 "container_image": "`+arvadostest.DockerImage112PDH+`",
1143 "mounts": {"/tmp": {"kind": "tmp"} },
1144 "output_path": "/tmp",
1146 "runtime_constraints": {},
1148 "uuid": "zzzzz-dz642-202301121543210"
1149 }`, nil, func() int {
1150 collection_create = s.api.CalledWith("ensure_unique_name", true)
1151 container_update = s.api.CalledWith("container.state", "Running")
1155 c.Assert(collection_create, NotNil)
1156 log_collection := collection_create["collection"].(arvadosclient.Dict)
1157 c.Check(log_collection["name"], Equals, "logs for zzzzz-dz642-202301121543210")
1158 manifest_text := log_collection["manifest_text"].(string)
1159 // We check that the file size is at least two digits as an easy way to
1160 // check the file isn't empty.
1161 c.Check(manifest_text, Matches, `\. .+ \d+:\d{2,}:node-info\.txt( .+)?\n`)
1162 c.Check(manifest_text, Matches, `\. .+ \d+:\d{2,}:node\.json( .+)?\n`)
1164 c.Assert(container_update, NotNil)
1165 // As of Arvados 2.5.0, the container update must specify its log in PDH
1166 // format for the API server to propagate it to container requests, which
1167 // is what we care about for this test.
1168 expect_pdh := fmt.Sprintf("%x+%d", md5.Sum([]byte(manifest_text)), len(manifest_text))
1169 c.Check(container_update["container"].(arvadosclient.Dict)["log"], Equals, expect_pdh)
1172 func (s *TestSuite) TestContainerRecordLog(c *C) {
1173 s.fullRunHelper(c, `{
1174 "command": ["sleep", "1"],
1175 "container_image": "`+arvadostest.DockerImage112PDH+`",
1178 "mounts": {"/tmp": {"kind": "tmp"} },
1179 "output_path": "/tmp",
1181 "runtime_constraints": {},
1185 time.Sleep(time.Second)
1189 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1190 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1192 c.Assert(s.api.Logs["container"], NotNil)
1193 c.Check(s.api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
1196 func (s *TestSuite) TestFullRunStderr(c *C) {
1197 s.fullRunHelper(c, `{
1198 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
1199 "container_image": "`+arvadostest.DockerImage112PDH+`",
1202 "mounts": {"/tmp": {"kind": "tmp"} },
1203 "output_path": "/tmp",
1205 "runtime_constraints": {},
1207 }`, nil, func() int {
1208 fmt.Fprintln(s.executor.created.Stdout, "hello")
1209 fmt.Fprintln(s.executor.created.Stderr, "world")
1213 final := s.api.CalledWith("container.state", "Complete")
1214 c.Assert(final, NotNil)
1215 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1216 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1218 c.Check(s.api.Logs["stdout"].String(), Matches, ".*hello\n")
1219 c.Check(s.api.Logs["stderr"].String(), Matches, ".*world\n")
1222 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
1223 s.fullRunHelper(c, `{
1225 "container_image": "`+arvadostest.DockerImage112PDH+`",
1228 "mounts": {"/tmp": {"kind": "tmp"} },
1229 "output_path": "/tmp",
1231 "runtime_constraints": {},
1233 }`, nil, func() int {
1234 fmt.Fprintf(s.executor.created.Stdout, "workdir=%q", s.executor.created.WorkingDir)
1238 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1239 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1240 c.Log(s.api.Logs["stdout"])
1241 c.Check(s.api.Logs["stdout"].String(), Matches, `.*workdir=""\n`)
1244 func (s *TestSuite) TestFullRunSetCwd(c *C) {
1245 s.fullRunHelper(c, `{
1247 "container_image": "`+arvadostest.DockerImage112PDH+`",
1250 "mounts": {"/tmp": {"kind": "tmp"} },
1251 "output_path": "/tmp",
1253 "runtime_constraints": {},
1255 }`, nil, func() int {
1256 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.WorkingDir)
1260 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1261 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1262 c.Check(s.api.Logs["stdout"].String(), Matches, ".*/bin\n")
1265 func (s *TestSuite) TestFullRunSetOutputStorageClasses(c *C) {
1266 s.fullRunHelper(c, `{
1268 "container_image": "`+arvadostest.DockerImage112PDH+`",
1271 "mounts": {"/tmp": {"kind": "tmp"} },
1272 "output_path": "/tmp",
1274 "runtime_constraints": {},
1276 "output_storage_classes": ["foo", "bar"]
1277 }`, nil, func() int {
1278 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.WorkingDir)
1282 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1283 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1284 c.Check(s.api.Logs["stdout"].String(), Matches, ".*/bin\n")
1285 c.Check(s.testDispatcherKeepClient.StorageClasses, DeepEquals, []string{"foo", "bar"})
1286 c.Check(s.testContainerKeepClient.StorageClasses, DeepEquals, []string{"foo", "bar"})
1289 func (s *TestSuite) TestEnableCUDADeviceCount(c *C) {
1290 s.fullRunHelper(c, `{
1292 "container_image": "`+arvadostest.DockerImage112PDH+`",
1295 "mounts": {"/tmp": {"kind": "tmp"} },
1296 "output_path": "/tmp",
1298 "runtime_constraints": {"cuda": {"device_count": 2}},
1300 "output_storage_classes": ["foo", "bar"]
1301 }`, nil, func() int {
1302 fmt.Fprintln(s.executor.created.Stdout, "ok")
1305 c.Check(s.executor.created.CUDADeviceCount, Equals, 2)
1308 func (s *TestSuite) TestEnableCUDAHardwareCapability(c *C) {
1309 s.fullRunHelper(c, `{
1311 "container_image": "`+arvadostest.DockerImage112PDH+`",
1314 "mounts": {"/tmp": {"kind": "tmp"} },
1315 "output_path": "/tmp",
1317 "runtime_constraints": {"cuda": {"hardware_capability": "foo"}},
1319 "output_storage_classes": ["foo", "bar"]
1320 }`, nil, func() int {
1321 fmt.Fprintln(s.executor.created.Stdout, "ok")
1324 c.Check(s.executor.created.CUDADeviceCount, Equals, 0)
1327 func (s *TestSuite) TestStopOnSignal(c *C) {
1328 s.executor.runFunc = func() int {
1329 s.executor.created.Stdout.Write([]byte("foo\n"))
1330 s.runner.SigChan <- syscall.SIGINT
1331 time.Sleep(10 * time.Second)
1334 s.testStopContainer(c)
1337 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
1338 s.executor.runFunc = func() int {
1339 s.executor.created.Stdout.Write([]byte("foo\n"))
1340 s.runner.ArvMountExit <- nil
1341 close(s.runner.ArvMountExit)
1342 time.Sleep(10 * time.Second)
1345 s.runner.ArvMountExit = make(chan error)
1346 s.testStopContainer(c)
1349 func (s *TestSuite) testStopContainer(c *C) {
1351 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
1352 "container_image": "` + arvadostest.DockerImage112PDH + `",
1355 "mounts": {"/tmp": {"kind": "tmp"} },
1356 "output_path": "/tmp",
1358 "runtime_constraints": {},
1362 err := json.Unmarshal([]byte(record), &s.api.Container)
1363 c.Assert(err, IsNil)
1365 s.runner.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
1366 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
1367 return &ArvTestClient{}, &KeepTestClient{}, nil, nil
1370 done := make(chan error)
1372 done <- s.runner.Run()
1375 case <-time.After(20 * time.Second):
1376 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
1377 c.Fatal("timed out")
1381 for k, v := range s.api.Logs {
1383 c.Log(v.String(), "\n")
1386 c.Check(s.api.CalledWith("container.log", nil), NotNil)
1387 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
1388 c.Check(s.api.Logs["stdout"].String(), Matches, "(?ms).*foo\n$")
1391 func (s *TestSuite) TestFullRunSetEnv(c *C) {
1392 s.fullRunHelper(c, `{
1393 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1394 "container_image": "`+arvadostest.DockerImage112PDH+`",
1396 "environment": {"FROBIZ": "bilbo"},
1397 "mounts": {"/tmp": {"kind": "tmp"} },
1398 "output_path": "/tmp",
1400 "runtime_constraints": {},
1402 }`, nil, func() int {
1403 fmt.Fprintf(s.executor.created.Stdout, "%v", s.executor.created.Env)
1407 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1408 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1409 c.Check(s.api.Logs["stdout"].String(), Matches, `.*map\[FROBIZ:bilbo\]\n`)
1412 type ArvMountCmdLine struct {
1417 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
1423 func stubCert(c *C, temp string) string {
1424 path := temp + "/ca-certificates.crt"
1425 err := os.WriteFile(path, []byte{}, 0666)
1426 c.Assert(err, IsNil)
1427 os.Setenv("SSL_CERT_FILE", path)
1431 func (s *TestSuite) TestSetupMounts(c *C) {
1433 am := &ArvMountCmdLine{}
1434 cr.RunArvMount = am.ArvMountTest
1435 cr.containerClient, _ = apiStub()
1436 cr.ContainerArvClient = &ArvTestClient{}
1437 cr.ContainerKeepClient = &KeepTestClient{}
1438 cr.Container.OutputStorageClasses = []string{"default"}
1440 realTemp := c.MkDir()
1441 certTemp := c.MkDir()
1442 stubCertPath := stubCert(c, certTemp)
1443 cr.parentTemp = realTemp
1446 cr.MkTempDir = func(_ string, prefix string) (string, error) {
1448 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
1449 err := os.Mkdir(d, os.ModePerm)
1450 if err != nil && strings.Contains(err.Error(), ": file exists") {
1451 // Test case must have pre-populated the tempdir
1457 checkEmpty := func() {
1458 // Should be deleted.
1459 _, err := os.Stat(realTemp)
1460 c.Assert(os.IsNotExist(err), Equals, true)
1462 // Now recreate it for the next test.
1463 c.Assert(os.Mkdir(realTemp, 0777), IsNil)
1468 cr.ArvMountPoint = ""
1469 cr.Container.Mounts = make(map[string]arvados.Mount)
1470 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1471 cr.Container.OutputPath = "/tmp"
1472 cr.statInterval = 5 * time.Second
1473 bindmounts, err := cr.SetupMounts()
1475 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1476 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1477 "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1478 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/tmp": {realTemp + "/tmp2", false}})
1479 os.RemoveAll(cr.ArvMountPoint)
1486 cr.ArvMountPoint = ""
1487 cr.Container.Mounts = make(map[string]arvados.Mount)
1488 cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"}
1489 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1490 cr.Container.OutputPath = "/out"
1491 cr.Container.OutputStorageClasses = []string{"foo", "bar"}
1493 bindmounts, err := cr.SetupMounts()
1495 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1496 "--read-write", "--storage-classes", "foo,bar", "--crunchstat-interval=5",
1497 "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1498 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/out": {realTemp + "/tmp2", false}, "/tmp": {realTemp + "/tmp3", false}})
1499 os.RemoveAll(cr.ArvMountPoint)
1506 cr.ArvMountPoint = ""
1507 cr.Container.Mounts = make(map[string]arvados.Mount)
1508 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1509 cr.Container.OutputPath = "/tmp"
1510 cr.Container.RuntimeConstraints.API = true
1511 cr.Container.OutputStorageClasses = []string{"default"}
1513 bindmounts, err := cr.SetupMounts()
1515 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1516 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1517 "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1518 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/tmp": {realTemp + "/tmp2", false}, "/etc/arvados/ca-certificates.crt": {stubCertPath, true}})
1519 os.RemoveAll(cr.ArvMountPoint)
1523 cr.Container.RuntimeConstraints.API = false
1528 cr.ArvMountPoint = ""
1529 cr.Container.Mounts = map[string]arvados.Mount{
1530 "/keeptmp": {Kind: "collection", Writable: true},
1532 cr.Container.OutputPath = "/keeptmp"
1534 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1536 bindmounts, err := cr.SetupMounts()
1538 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1539 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1540 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1541 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/keeptmp": {realTemp + "/keep1/tmp0", false}})
1542 os.RemoveAll(cr.ArvMountPoint)
1549 cr.ArvMountPoint = ""
1550 cr.Container.Mounts = map[string]arvados.Mount{
1551 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1552 "/keepout": {Kind: "collection", Writable: true},
1554 cr.Container.OutputPath = "/keepout"
1556 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1557 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1559 bindmounts, err := cr.SetupMounts()
1561 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1562 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1563 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1564 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1565 "/keepinp": {realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", true},
1566 "/keepout": {realTemp + "/keep1/tmp0", false},
1568 os.RemoveAll(cr.ArvMountPoint)
1575 cr.ArvMountPoint = ""
1576 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1577 cr.Container.Mounts = map[string]arvados.Mount{
1578 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1579 "/keepout": {Kind: "collection", Writable: true},
1581 cr.Container.OutputPath = "/keepout"
1583 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1584 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1586 bindmounts, err := cr.SetupMounts()
1588 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1589 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", "--ram-cache",
1590 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1591 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1592 "/keepinp": {realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", true},
1593 "/keepout": {realTemp + "/keep1/tmp0", false},
1595 os.RemoveAll(cr.ArvMountPoint)
1600 for _, test := range []struct {
1604 {in: "foo", out: `"foo"`},
1605 {in: nil, out: `null`},
1606 {in: map[string]int64{"foo": 123456789123456789}, out: `{"foo":123456789123456789}`},
1609 cr.ArvMountPoint = ""
1610 cr.Container.Mounts = map[string]arvados.Mount{
1611 "/mnt/test.json": {Kind: "json", Content: test.in},
1613 bindmounts, err := cr.SetupMounts()
1615 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1616 "/mnt/test.json": {realTemp + "/json2/mountdata.json", true},
1618 content, err := ioutil.ReadFile(realTemp + "/json2/mountdata.json")
1620 c.Check(content, DeepEquals, []byte(test.out))
1621 os.RemoveAll(cr.ArvMountPoint)
1626 for _, test := range []struct {
1630 {in: "foo", out: `foo`},
1631 {in: nil, out: "error"},
1632 {in: map[string]int64{"foo": 123456789123456789}, out: "error"},
1635 cr.ArvMountPoint = ""
1636 cr.Container.Mounts = map[string]arvados.Mount{
1637 "/mnt/test.txt": {Kind: "text", Content: test.in},
1639 bindmounts, err := cr.SetupMounts()
1640 if test.out == "error" {
1641 c.Check(err.Error(), Equals, "content for mount \"/mnt/test.txt\" must be a string")
1644 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1645 "/mnt/test.txt": {realTemp + "/text2/mountdata.text", true},
1647 content, err := ioutil.ReadFile(realTemp + "/text2/mountdata.text")
1649 c.Check(content, DeepEquals, []byte(test.out))
1651 os.RemoveAll(cr.ArvMountPoint)
1656 // Read-only mount points are allowed underneath output_dir mount point
1659 cr.ArvMountPoint = ""
1660 cr.Container.Mounts = make(map[string]arvados.Mount)
1661 cr.Container.Mounts = map[string]arvados.Mount{
1662 "/tmp": {Kind: "tmp"},
1663 "/tmp/foo": {Kind: "collection"},
1665 cr.Container.OutputPath = "/tmp"
1667 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1669 bindmounts, err := cr.SetupMounts()
1671 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1672 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", "--ram-cache",
1673 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1674 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1675 "/tmp": {realTemp + "/tmp2", false},
1676 "/tmp/foo": {realTemp + "/keep1/tmp0", true},
1678 os.RemoveAll(cr.ArvMountPoint)
1683 // Writable mount points copied to output_dir mount point
1686 cr.ArvMountPoint = ""
1687 cr.Container.Mounts = make(map[string]arvados.Mount)
1688 cr.Container.Mounts = map[string]arvados.Mount{
1689 "/tmp": {Kind: "tmp"},
1690 "/tmp/foo": {Kind: "collection",
1691 PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53",
1693 "/tmp/bar": {Kind: "collection",
1694 PortableDataHash: "59389a8f9ee9d399be35462a0f92541d+53",
1698 cr.Container.OutputPath = "/tmp"
1700 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1701 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz", os.ModePerm)
1703 rf, _ := os.Create(realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz/quux")
1704 rf.Write([]byte("bar"))
1707 _, err := cr.SetupMounts()
1709 _, err = os.Stat(cr.HostOutputDir + "/foo")
1711 _, err = os.Stat(cr.HostOutputDir + "/bar/quux")
1713 os.RemoveAll(cr.ArvMountPoint)
1718 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1721 cr.ArvMountPoint = ""
1722 cr.Container.Mounts = make(map[string]arvados.Mount)
1723 cr.Container.Mounts = map[string]arvados.Mount{
1724 "/tmp": {Kind: "tmp"},
1725 "/tmp/foo": {Kind: "tmp"},
1727 cr.Container.OutputPath = "/tmp"
1729 _, err := cr.SetupMounts()
1730 c.Check(err, NotNil)
1731 c.Check(err, ErrorMatches, `only mount points of kind 'collection', 'text' or 'json' are supported underneath the output_path.*`)
1732 os.RemoveAll(cr.ArvMountPoint)
1737 // Only mount point of kind 'collection' is allowed for stdin
1740 cr.ArvMountPoint = ""
1741 cr.Container.Mounts = make(map[string]arvados.Mount)
1742 cr.Container.Mounts = map[string]arvados.Mount{
1743 "stdin": {Kind: "tmp"},
1746 _, err := cr.SetupMounts()
1747 c.Check(err, NotNil)
1748 c.Check(err, ErrorMatches, `unsupported mount kind 'tmp' for stdin.*`)
1749 os.RemoveAll(cr.ArvMountPoint)
1755 func (s *TestSuite) TestStdout(c *C) {
1757 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1758 "container_image": "` + arvadostest.DockerImage112PDH + `",
1760 "environment": {"FROBIZ": "bilbo"},
1761 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1762 "output_path": "/tmp",
1764 "runtime_constraints": {},
1768 s.fullRunHelper(c, helperRecord, nil, func() int {
1769 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1773 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1774 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1775 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1778 // Used by the TestStdoutWithWrongPath*()
1779 func (s *TestSuite) stdoutErrorRunHelper(c *C, record string, fn func() int) (*ArvTestClient, *ContainerRunner, error) {
1780 err := json.Unmarshal([]byte(record), &s.api.Container)
1781 c.Assert(err, IsNil)
1782 s.executor.runFunc = fn
1783 s.runner.RunArvMount = (&ArvMountCmdLine{}).ArvMountTest
1784 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
1785 return s.api, &KeepTestClient{}, nil, nil
1787 return s.api, s.runner, s.runner.Run()
1790 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1791 _, _, err := s.stdoutErrorRunHelper(c, `{
1792 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1793 "output_path": "/tmp",
1795 }`, func() int { return 0 })
1796 c.Check(err, ErrorMatches, ".*Stdout path does not start with OutputPath.*")
1799 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1800 _, _, err := s.stdoutErrorRunHelper(c, `{
1801 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1802 "output_path": "/tmp",
1804 }`, func() int { return 0 })
1805 c.Check(err, ErrorMatches, ".*unsupported mount kind 'tmp' for stdout.*")
1808 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1809 _, _, err := s.stdoutErrorRunHelper(c, `{
1810 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1811 "output_path": "/tmp",
1813 }`, func() int { return 0 })
1814 c.Check(err, ErrorMatches, ".*unsupported mount kind 'collection' for stdout.*")
1817 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1818 s.fullRunHelper(c, `{
1819 "command": ["/bin/sh", "-c", "true $ARVADOS_API_HOST"],
1820 "container_image": "`+arvadostest.DockerImage112PDH+`",
1823 "mounts": {"/tmp": {"kind": "tmp"} },
1824 "output_path": "/tmp",
1826 "runtime_constraints": {"API": true},
1828 }`, nil, func() int {
1829 c.Check(s.executor.created.Env["ARVADOS_API_HOST"], Equals, os.Getenv("ARVADOS_API_HOST"))
1832 c.Check(s.api.CalledWith("container.exit_code", 3), NotNil)
1833 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1834 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*status code 3\n.*`)
1837 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1838 defer os.Setenv("ARVADOS_API_HOST", os.Getenv("ARVADOS_API_HOST"))
1839 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1840 s.fullRunHelper(c, `{
1841 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1842 "container_image": "`+arvadostest.DockerImage112PDH+`",
1845 "mounts": {"/tmp": {"kind": "tmp"} },
1846 "output_path": "/tmp",
1848 "runtime_constraints": {"API": true},
1850 }`, nil, func() int {
1851 s.api.Container.Output = arvadostest.DockerImage112PDH
1855 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1856 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1857 c.Check(s.api.CalledWith("container.output", arvadostest.DockerImage112PDH), NotNil)
1860 func (s *TestSuite) TestArvMountRuntimeStatusWarning(c *C) {
1861 s.runner.RunArvMount = func([]string, string) (*exec.Cmd, error) {
1862 os.Mkdir(s.runner.ArvMountPoint+"/by_id", 0666)
1863 ioutil.WriteFile(s.runner.ArvMountPoint+"/by_id/README", nil, 0666)
1864 return s.runner.ArvMountCmd([]string{"bash", "-c", "echo >&2 Test: Keep write error: I am a teapot; sleep 3"}, "")
1866 s.executor.runFunc = func() int {
1867 time.Sleep(time.Second)
1871 "command": ["sleep", "1"],
1872 "container_image": "` + arvadostest.DockerImage112PDH + `",
1875 "mounts": {"/tmp": {"kind": "tmp"} },
1876 "output_path": "/tmp",
1878 "runtime_constraints": {"API": true},
1881 err := json.Unmarshal([]byte(record), &s.api.Container)
1882 c.Assert(err, IsNil)
1883 err = s.runner.Run()
1884 c.Assert(err, IsNil)
1885 c.Check(s.api.CalledWith("container.exit_code", 137), NotNil)
1886 c.Check(s.api.CalledWith("container.runtime_status.warning", "arv-mount: Keep write error"), NotNil)
1887 c.Check(s.api.CalledWith("container.runtime_status.warningDetail", "Test: Keep write error: I am a teapot"), NotNil)
1888 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1889 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Container exited with status code 137 \(signal 9, SIGKILL\).*`)
1892 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1894 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1895 "container_image": "` + arvadostest.DockerImage112PDH + `",
1897 "environment": {"FROBIZ": "bilbo"},
1899 "/tmp": {"kind": "tmp"},
1900 "/tmp/foo": {"kind": "collection",
1901 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1902 "exclude_from_output": true
1904 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1906 "output_path": "/tmp",
1908 "runtime_constraints": {},
1912 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1914 s.fullRunHelper(c, helperRecord, extraMounts, func() int {
1915 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1919 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1920 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1921 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1924 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1926 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1927 "container_image": "` + arvadostest.DockerImage112PDH + `",
1929 "environment": {"FROBIZ": "bilbo"},
1931 "/tmp": {"kind": "tmp"},
1932 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1933 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1934 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1935 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1936 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1938 "output_path": "/tmp",
1940 "runtime_constraints": {},
1942 "uuid": "zzzzz-dz642-202301130848001"
1945 extraMounts := []string{
1946 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1947 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1948 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1951 api, _, realtemp := s.fullRunHelper(c, helperRecord, extraMounts, func() int {
1952 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1956 c.Check(s.executor.created.BindMounts, DeepEquals, map[string]bindmount{
1957 "/tmp": {realtemp + "/tmp1", false},
1958 "/tmp/foo/bar": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt", true},
1959 "/tmp/foo/baz/sub2file2": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt", true},
1960 "/tmp/foo/sub1": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1", true},
1961 "/tmp/foo/sub1file2": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt", true},
1964 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1965 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
1966 output_count := uint(0)
1967 for _, v := range s.runner.ContainerArvClient.(*ArvTestClient).Content {
1968 if v["collection"] == nil {
1971 collection := v["collection"].(arvadosclient.Dict)
1972 if collection["name"].(string) != "output for zzzzz-dz642-202301130848001" {
1975 c.Check(v["ensure_unique_name"], Equals, true)
1976 c.Check(collection["manifest_text"].(string), Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
1977 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:bar 36:18:sub1file2
1978 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
1979 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
1980 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
1984 c.Check(output_count, Not(Equals), uint(0))
1987 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
1989 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1990 "container_image": "` + arvadostest.DockerImage112PDH + `",
1992 "environment": {"FROBIZ": "bilbo"},
1994 "/tmp": {"kind": "tmp"},
1995 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/subdir1/file2_in_subdir1.txt"},
1996 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1998 "output_path": "/tmp",
2000 "runtime_constraints": {},
2002 "uuid": "zzzzz-dz642-202301130848002"
2005 extraMounts := []string{
2006 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
2009 s.fullRunHelper(c, helperRecord, extraMounts, func() int {
2010 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
2014 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2015 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2016 output_count := uint(0)
2017 for _, v := range s.runner.ContainerArvClient.(*ArvTestClient).Content {
2018 if v["collection"] == nil {
2021 collection := v["collection"].(arvadosclient.Dict)
2022 if collection["name"].(string) != "output for zzzzz-dz642-202301130848002" {
2025 c.Check(collection["manifest_text"].(string), Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
2026 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
2030 c.Check(output_count, Not(Equals), uint(0))
2033 func (s *TestSuite) TestOutputError(c *C) {
2035 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
2036 "container_image": "` + arvadostest.DockerImage112PDH + `",
2038 "environment": {"FROBIZ": "bilbo"},
2040 "/tmp": {"kind": "tmp"}
2042 "output_path": "/tmp",
2044 "runtime_constraints": {},
2047 s.fullRunHelper(c, helperRecord, nil, func() int {
2048 os.Symlink("/etc/hosts", s.runner.HostOutputDir+"/baz")
2052 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
2055 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
2057 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
2058 "container_image": "` + arvadostest.DockerImage112PDH + `",
2060 "environment": {"FROBIZ": "bilbo"},
2062 "/tmp": {"kind": "tmp"},
2063 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
2064 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
2066 "output_path": "/tmp",
2068 "runtime_constraints": {},
2072 extraMounts := []string{
2073 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
2076 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, func() int {
2077 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
2081 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
2082 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
2083 for _, v := range api.Content {
2084 if v["collection"] != nil {
2085 collection := v["collection"].(arvadosclient.Dict)
2086 if strings.Index(collection["name"].(string), "output") == 0 {
2087 manifest := collection["manifest_text"].(string)
2088 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
2095 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
2097 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
2098 "container_image": "` + arvadostest.DockerImage112PDH + `",
2100 "environment": {"FROBIZ": "bilbo"},
2102 "/tmp": {"kind": "tmp"},
2103 "stdin": {"kind": "json", "content": "foo"},
2104 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
2106 "output_path": "/tmp",
2108 "runtime_constraints": {},
2112 api, _, _ := s.fullRunHelper(c, helperRecord, nil, func() int {
2113 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
2117 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
2118 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
2119 for _, v := range api.Content {
2120 if v["collection"] != nil {
2121 collection := v["collection"].(arvadosclient.Dict)
2122 if strings.Index(collection["name"].(string), "output") == 0 {
2123 manifest := collection["manifest_text"].(string)
2124 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
2131 func (s *TestSuite) TestStderrMount(c *C) {
2132 api, cr, _ := s.fullRunHelper(c, `{
2133 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
2134 "container_image": "`+arvadostest.DockerImage112PDH+`",
2137 "mounts": {"/tmp": {"kind": "tmp"},
2138 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
2139 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
2140 "output_path": "/tmp",
2142 "runtime_constraints": {},
2144 }`, nil, func() int {
2145 fmt.Fprintln(s.executor.created.Stdout, "hello")
2146 fmt.Fprintln(s.executor.created.Stderr, "oops")
2150 final := api.CalledWith("container.state", "Complete")
2151 c.Assert(final, NotNil)
2152 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
2153 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
2155 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)
2158 func (s *TestSuite) TestNumberRoundTrip(c *C) {
2159 s.api.callraw = true
2160 err := s.runner.fetchContainerRecord()
2161 c.Assert(err, IsNil)
2162 jsondata, err := json.Marshal(s.runner.Container.Mounts["/json"].Content)
2163 c.Logf("%#v", s.runner.Container)
2165 c.Check(string(jsondata), Equals, `{"number":123456789123456789}`)
2168 func (s *TestSuite) TestFullBrokenDocker(c *C) {
2170 for _, setup := range []func(){
2172 c.Log("// waitErr = ocl runtime error")
2173 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\\\"\""`)
2174 nextState = "Cancelled"
2177 c.Log("// loadErr = cannot connect")
2178 s.executor.loadErr = errors.New("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
2179 s.runner.brokenNodeHook = c.MkDir() + "/broken-node-hook"
2180 err := ioutil.WriteFile(s.runner.brokenNodeHook, []byte("#!/bin/sh\nexec echo killme\n"), 0700)
2181 c.Assert(err, IsNil)
2182 nextState = "Queued"
2187 s.fullRunHelper(c, `{
2188 "command": ["echo", "hello world"],
2189 "container_image": "`+arvadostest.DockerImage112PDH+`",
2192 "mounts": {"/tmp": {"kind": "tmp"} },
2193 "output_path": "/tmp",
2195 "runtime_constraints": {},
2197 }`, nil, func() int { return 0 })
2198 c.Check(s.api.CalledWith("container.state", nextState), NotNil)
2199 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
2200 if s.runner.brokenNodeHook != "" {
2201 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Running broken node hook.*")
2202 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*killme.*")
2203 c.Check(s.api.Logs["crunch-run"].String(), Not(Matches), "(?ms).*Writing /var/lock/crunch-run-broken to mark node as broken.*")
2205 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Writing /var/lock/crunch-run-broken to mark node as broken.*")
2210 func (s *TestSuite) TestBadCommand(c *C) {
2211 for _, startError := range []string{
2212 `panic: standard_init_linux.go:175: exec user process caused "no such file or directory"`,
2213 `Error response from daemon: Cannot start container 41f26cbc43bcc1280f4323efb1830a394ba8660c9d1c2b564ba42bf7f7694845: [8] System error: no such file or directory`,
2214 `Error response from daemon: Cannot start container 58099cd76c834f3dc2a4fb76c8028f049ae6d4fdf0ec373e1f2cfea030670c2d: [8] System error: exec: "foobar": executable file not found in $PATH`,
2217 s.executor.startErr = errors.New(startError)
2218 s.fullRunHelper(c, `{
2219 "command": ["echo", "hello world"],
2220 "container_image": "`+arvadostest.DockerImage112PDH+`",
2223 "mounts": {"/tmp": {"kind": "tmp"} },
2224 "output_path": "/tmp",
2226 "runtime_constraints": {},
2228 }`, nil, func() int { return 0 })
2229 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
2230 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
2234 func (s *TestSuite) TestSecretTextMountPoint(c *C) {
2236 "command": ["true"],
2237 "container_image": "` + arvadostest.DockerImage112PDH + `",
2240 "/tmp": {"kind": "tmp"},
2241 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2245 "output_path": "/tmp",
2247 "runtime_constraints": {},
2251 s.fullRunHelper(c, helperRecord, nil, func() int {
2252 content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf")
2254 c.Check(string(content), Equals, "mypassword")
2258 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2259 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2260 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". 34819d7beeabb9260a5c854bc85b3e44+10 0:10:secret.conf\n"), NotNil)
2261 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ""), IsNil)
2263 // under secret mounts, not captured in output
2265 "command": ["true"],
2266 "container_image": "` + arvadostest.DockerImage112PDH + `",
2269 "/tmp": {"kind": "tmp"}
2272 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2274 "output_path": "/tmp",
2276 "runtime_constraints": {},
2281 s.fullRunHelper(c, helperRecord, nil, func() int {
2282 content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf")
2284 c.Check(string(content), Equals, "mypassword")
2288 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2289 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2290 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". 34819d7beeabb9260a5c854bc85b3e44+10 0:10:secret.conf\n"), IsNil)
2291 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ""), NotNil)
2293 // under secret mounts, output dir is a collection, not captured in output
2295 "command": ["true"],
2296 "container_image": "` + arvadostest.DockerImage112PDH + `",
2299 "/tmp": {"kind": "collection", "writable": true}
2302 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2304 "output_path": "/tmp",
2306 "runtime_constraints": {},
2311 _, _, realtemp := s.fullRunHelper(c, helperRecord, nil, func() int {
2312 // secret.conf should be provisioned as a separate
2313 // bind mount, i.e., it should not appear in the
2314 // (fake) fuse filesystem as viewed from the host.
2315 content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf")
2316 if !c.Check(errors.Is(err, os.ErrNotExist), Equals, true) {
2317 c.Logf("secret.conf: content %q, err %#v", content, err)
2319 err = ioutil.WriteFile(s.runner.HostOutputDir+"/.arvados#collection", []byte(`{"manifest_text":". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n"}`), 0700)
2324 content, err := ioutil.ReadFile(realtemp + "/text1/mountdata.text")
2326 c.Check(string(content), Equals, "mypassword")
2327 c.Check(s.executor.created.BindMounts["/tmp/secret.conf"], DeepEquals, bindmount{realtemp + "/text1/mountdata.text", true})
2328 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2329 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2330 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n"), NotNil)
2333 func (s *TestSuite) TestCalculateCost(c *C) {
2334 defer func(s string) { lockdir = s }(lockdir)
2338 cr.costStartTime = now.Add(-time.Hour)
2339 var logbuf bytes.Buffer
2340 cr.CrunchLog.Immediate = log.New(&logbuf, "", 0)
2342 // if there's no InstanceType env var, cost is calculated as 0
2343 os.Unsetenv("InstanceType")
2344 cost := cr.calculateCost(now)
2345 c.Check(cost, Equals, 0.0)
2347 // with InstanceType env var and loadPrices() hasn't run (or
2348 // hasn't found any data), cost is calculated based on
2349 // InstanceType env var
2350 os.Setenv("InstanceType", `{"Price":1.2}`)
2351 cost = cr.calculateCost(now)
2352 c.Check(cost, Equals, 1.2)
2354 // first update tells us the spot price was $1/h until 30
2355 // minutes ago when it increased to $2/h
2356 j, err := json.Marshal([]cloud.InstancePrice{
2357 {StartTime: now.Add(-4 * time.Hour), Price: 1.0},
2358 {StartTime: now.Add(-time.Hour / 2), Price: 2.0},
2360 c.Assert(err, IsNil)
2361 os.WriteFile(lockdir+"/"+pricesfile, j, 0777)
2363 cost = cr.calculateCost(now)
2364 c.Check(cost, Equals, 1.5)
2366 // next update (via --list + SIGUSR2) tells us the spot price
2367 // increased to $3/h 15 minutes ago
2368 j, err = json.Marshal([]cloud.InstancePrice{
2369 {StartTime: now.Add(-time.Hour / 3), Price: 2.0}, // dup of -time.Hour/2 price
2370 {StartTime: now.Add(-time.Hour / 4), Price: 3.0},
2372 c.Assert(err, IsNil)
2373 os.WriteFile(lockdir+"/"+pricesfile, j, 0777)
2375 cost = cr.calculateCost(now)
2376 c.Check(cost, Equals, 1.0/2+2.0/4+3.0/4)
2378 cost = cr.calculateCost(now.Add(-time.Hour / 2))
2379 c.Check(cost, Equals, 0.5)
2381 c.Logf("%s", logbuf.String())
2382 c.Check(logbuf.String(), Matches, `(?ms).*Instance price changed to 1\.00 at 20.* changed to 2\.00 .* changed to 3\.00 .*`)
2383 c.Check(logbuf.String(), Not(Matches), `(?ms).*changed to 2\.00 .* changed to 2\.00 .*`)
2386 func (s *TestSuite) TestSIGUSR2CostUpdate(c *C) {
2389 pricesJSON, err := json.Marshal([]cloud.InstancePrice{
2390 {StartTime: now.Add(-4 * time.Hour), Price: 2.4},
2391 {StartTime: now.Add(-2 * time.Hour), Price: 2.6},
2393 c.Assert(err, IsNil)
2395 os.Setenv("InstanceType", `{"Price":2.2}`)
2396 defer func(s string) { lockdir = s }(lockdir)
2399 // We can't use s.api.CalledWith because timing differences will yield
2400 // different cost values across runs. getCostUpdate iterates over API
2401 // calls until it finds one that sets the cost, then writes that value
2402 // to the next index of costUpdates.
2403 deadline := now.Add(time.Second)
2404 costUpdates := make([]float64, 2)
2407 getCostUpdate := func() {
2408 for ; time.Now().Before(deadline); time.Sleep(time.Second / 10) {
2409 for apiIndex < len(s.api.Content) {
2410 update := s.api.Content[apiIndex]
2414 if update, ok = update["container"].(arvadosclient.Dict); !ok {
2417 if cost, ok = update["cost"].(float64); !ok {
2420 c.Logf("API call #%d updates cost to %v", apiIndex-1, cost)
2421 costUpdates[costIndex] = cost
2428 s.fullRunHelper(c, `{
2429 "command": ["true"],
2430 "container_image": "`+arvadostest.DockerImage112PDH+`",
2433 "mounts": {"/tmp": {"kind": "tmp"} },
2434 "output_path": "/tmp",
2436 "runtime_constraints": {},
2438 "uuid": "zzzzz-dz642-20230320101530a"
2439 }`, nil, func() int {
2440 s.runner.costStartTime = now.Add(-3 * time.Hour)
2441 err := syscall.Kill(pid, syscall.SIGUSR2)
2442 c.Check(err, IsNil, Commentf("error sending first SIGUSR2 to runner"))
2445 err = os.WriteFile(path.Join(lockdir, pricesfile), pricesJSON, 0o700)
2446 c.Check(err, IsNil, Commentf("error writing JSON prices file"))
2447 err = syscall.Kill(pid, syscall.SIGUSR2)
2448 c.Check(err, IsNil, Commentf("error sending second SIGUSR2 to runner"))
2453 // Comparing with format strings makes it easy to ignore minor variations
2454 // in cost across runs while keeping diagnostics pretty.
2455 c.Check(fmt.Sprintf("%.3f", costUpdates[0]), Equals, "6.600")
2456 c.Check(fmt.Sprintf("%.3f", costUpdates[1]), Equals, "7.600")
2459 type FakeProcess struct {
2463 func (fp FakeProcess) CmdlineSlice() ([]string, error) {
2464 return fp.cmdLine, nil