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"
43 git_client "gopkg.in/src-d/go-git.v4/plumbing/transport/client"
44 git_http "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
47 // Gocheck boilerplate
48 func TestCrunchExec(t *testing.T) {
52 const logLineStart = `(?m)(.*\n)*\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+Z `
54 var _ = Suite(&TestSuite{})
56 type TestSuite struct {
57 client *arvados.Client
59 runner *ContainerRunner
60 executor *stubExecutor
63 testDispatcherKeepClient KeepTestClient
64 testContainerKeepClient KeepTestClient
67 func (s *TestSuite) SetUpTest(c *C) {
68 s.client = arvados.NewClientFromEnv()
69 s.executor = &stubExecutor{}
71 s.api = &ArvTestClient{}
72 s.runner, err = NewContainerRunner(s.client, s.api, &s.testDispatcherKeepClient, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
74 s.runner.executor = s.executor
75 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
76 return s.api, &s.testContainerKeepClient, s.client, nil
78 s.runner.RunArvMount = func(cmd []string, tok string) (*exec.Cmd, error) {
79 s.runner.ArvMountPoint = s.keepmount
80 for i, opt := range cmd {
81 if opt == "--mount-tmp" {
82 err := os.Mkdir(s.keepmount+"/"+cmd[i+1], 0700)
86 s.keepmountTmp = append(s.keepmountTmp, cmd[i+1])
91 s.keepmount = c.MkDir()
92 err = os.Mkdir(s.keepmount+"/by_id", 0755)
95 err = os.Mkdir(s.keepmount+"/by_id/"+arvadostest.DockerImage112PDH, 0755)
97 err = ioutil.WriteFile(s.keepmount+"/by_id/"+arvadostest.DockerImage112PDH+"/"+arvadostest.DockerImage112Filename, []byte("#notarealtarball"), 0644)
98 err = os.Mkdir(s.keepmount+"/by_id/"+fakeInputCollectionPDH, 0755)
100 err = ioutil.WriteFile(s.keepmount+"/by_id/"+fakeInputCollectionPDH+"/input.json", []byte(`{"input":true}`), 0644)
102 s.runner.ArvMountPoint = s.keepmount
105 type ArvTestClient struct {
108 Content []arvadosclient.Dict
111 Logs map[string]*bytes.Buffer
117 type KeepTestClient struct {
120 StorageClasses []string
123 type stubExecutor struct {
129 created containerSpec
131 waitSleep time.Duration
140 func (e *stubExecutor) LoadImage(imageId string, tarball string, container arvados.Container, keepMount string,
141 containerClient *arvados.Client) error {
145 func (e *stubExecutor) Runtime() string { return "stub" }
146 func (e *stubExecutor) Version() string { return "stub " + cmd.Version.String() }
147 func (e *stubExecutor) Create(spec containerSpec) error { e.created = spec; return e.createErr }
148 func (e *stubExecutor) Start() error {
149 e.exit = make(chan int, 1)
150 go func() { e.exit <- e.runFunc() }()
153 func (e *stubExecutor) CgroupID() string { return "cgroupid" }
154 func (e *stubExecutor) Stop() error { e.stopped = true; go func() { e.exit <- -1 }(); return e.stopErr }
155 func (e *stubExecutor) Close() { e.closed = true }
156 func (e *stubExecutor) Wait(context.Context) (int, error) {
157 return <-e.exit, e.waitErr
159 func (e *stubExecutor) InjectCommand(ctx context.Context, _, _ string, _ bool, _ []string) (*exec.Cmd, error) {
160 return nil, errors.New("unimplemented")
162 func (e *stubExecutor) IPAddress() (string, error) { return "", errors.New("unimplemented") }
164 const fakeInputCollectionPDH = "ffffffffaaaaaaaa88888888eeeeeeee+1234"
166 var hwManifest = ". 82ab40c24fc8df01798e57ba66795bb1+841216+Aa124ac75e5168396c73c0a18eda641a4f41791c0@569fa8c3 0:841216:9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7.tar\n"
167 var hwPDH = "a45557269dcb65a6b78f9ac061c0850b+120"
168 var hwImageID = "9c31ee32b3d15268a0754e8edc74d4f815ee014b693bc5109058e431dd5caea7"
170 var otherManifest = ". 68a84f561b1d1708c6baff5e019a9ab3+46+Ae5d0af96944a3690becb1decdf60cc1c937f556d@5693216f 0:46:md5sum.txt\n"
171 var otherPDH = "a3e8f74c6f101eae01fa08bfb4e49b3a+54"
173 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
174 ./subdir1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
175 ./subdir1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
178 var normalizedWithSubdirsPDH = "a0def87f80dd594d4675809e83bd4f15+367"
180 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"
181 var denormalizedWithSubdirsPDH = "b0def87f80dd594d4675809e83bd4f15+367"
183 var fakeAuthUUID = "zzzzz-gj3su-55pqoyepgi2glem"
184 var fakeAuthToken = "a3ltuwzqcu2u4sc0q7yhpc2w7s00fdcqecg5d6e0u3pfohmbjt"
186 func (client *ArvTestClient) Create(resourceType string,
187 parameters arvadosclient.Dict,
188 output interface{}) error {
191 defer client.Mutex.Unlock()
194 client.Content = append(client.Content, parameters)
196 if resourceType == "logs" {
197 et := parameters["log"].(arvadosclient.Dict)["event_type"].(string)
198 if client.Logs == nil {
199 client.Logs = make(map[string]*bytes.Buffer)
201 if client.Logs[et] == nil {
202 client.Logs[et] = &bytes.Buffer{}
204 client.Logs[et].Write([]byte(parameters["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]))
207 if resourceType == "collections" && output != nil {
208 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
209 md5sum := md5.Sum([]byte(mt))
210 outmap := output.(*arvados.Collection)
211 outmap.PortableDataHash = fmt.Sprintf("%x+%d", md5sum, len(mt))
212 outmap.UUID = fmt.Sprintf("zzzzz-4zz18-%015x", md5sum[:7])
218 func (client *ArvTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
220 case method == "GET" && resourceType == "containers" && action == "auth":
221 return json.Unmarshal([]byte(`{
222 "kind": "arvados#api_client_authorization",
223 "uuid": "`+fakeAuthUUID+`",
224 "api_token": "`+fakeAuthToken+`"
226 case method == "GET" && resourceType == "containers" && action == "secret_mounts":
227 if client.secretMounts != nil {
228 return json.Unmarshal(client.secretMounts, output)
230 return json.Unmarshal([]byte(`{"secret_mounts":{}}`), output)
232 return fmt.Errorf("Not found")
236 func (client *ArvTestClient) CallRaw(method, resourceType, uuid, action string,
237 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
239 if method == "GET" && resourceType == "nodes" && uuid == "" && action == "" {
241 "kind": "arvados#nodeList",
243 "uuid": "zzzzz-7ekkf-2z3mc76g2q73aio",
244 "hostname": "compute2",
245 "properties": {"total_cpu_cores": 16}
247 } else if method == "GET" && resourceType == "containers" && action == "" && !client.callraw {
249 j, err = json.Marshal(map[string]interface{}{
250 "items": []interface{}{client.Container},
251 "kind": "arvados#nodeList",
254 j, err = json.Marshal(client.Container)
258 "command": ["sleep", "1"],
259 "container_image": "` + arvadostest.DockerImage112PDH + `",
262 "mounts": {"/tmp": {"kind": "tmp"}, "/json": {"kind": "json", "content": {"number": 123456789123456789}}},
263 "output_path": "/tmp",
265 "runtime_constraints": {}
268 return ioutil.NopCloser(bytes.NewReader(j)), err
271 func (client *ArvTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
272 if resourceType == "collections" {
274 output.(*arvados.Collection).ManifestText = hwManifest
275 } else if uuid == otherPDH {
276 output.(*arvados.Collection).ManifestText = otherManifest
277 } else if uuid == normalizedWithSubdirsPDH {
278 output.(*arvados.Collection).ManifestText = normalizedManifestWithSubdirs
279 } else if uuid == denormalizedWithSubdirsPDH {
280 output.(*arvados.Collection).ManifestText = denormalizedManifestWithSubdirs
283 if resourceType == "containers" {
284 (*output.(*arvados.Container)) = client.Container
289 func (client *ArvTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
291 defer client.Mutex.Unlock()
293 client.Content = append(client.Content, parameters)
294 if resourceType == "containers" {
295 if parameters["container"].(arvadosclient.Dict)["state"] == "Running" {
296 client.WasSetRunning = true
298 } else if resourceType == "collections" && output != nil {
299 mt := parameters["collection"].(arvadosclient.Dict)["manifest_text"].(string)
300 output.(*arvados.Collection).UUID = uuid
301 output.(*arvados.Collection).PortableDataHash = fmt.Sprintf("%x", md5.Sum([]byte(mt)))
306 var discoveryMap = map[string]interface{}{
307 "defaultTrashLifetime": float64(1209600),
308 "crunchLimitLogBytesPerJob": float64(67108864),
309 "crunchLogThrottleBytes": float64(65536),
310 "crunchLogThrottlePeriod": float64(60),
311 "crunchLogThrottleLines": float64(1024),
312 "crunchLogPartialLineThrottlePeriod": float64(5),
313 "crunchLogBytesPerEvent": float64(4096),
314 "crunchLogSecondsBetweenEvents": float64(1),
317 func (client *ArvTestClient) Discovery(key string) (interface{}, error) {
318 return discoveryMap[key], nil
321 // CalledWith returns the parameters from the first API call whose
322 // parameters match jpath/string. E.g., CalledWith(c, "foo.bar",
323 // "baz") returns parameters with parameters["foo"]["bar"]=="baz". If
324 // no call matches, it returns nil.
325 func (client *ArvTestClient) CalledWith(jpath string, expect interface{}) arvadosclient.Dict {
327 for _, content := range client.Content {
328 var v interface{} = content
329 for _, k := range strings.Split(jpath, ".") {
330 if dict, ok := v.(arvadosclient.Dict); !ok {
343 func (client *KeepTestClient) LocalLocator(locator string) (string, error) {
347 func (client *KeepTestClient) BlockWrite(_ context.Context, opts arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) {
348 client.Content = opts.Data
349 return arvados.BlockWriteResponse{
350 Locator: fmt.Sprintf("%x+%d", md5.Sum(opts.Data), len(opts.Data)),
354 func (client *KeepTestClient) ReadAt(string, []byte, int) (int, error) {
355 return 0, errors.New("not implemented")
358 func (client *KeepTestClient) ClearBlockCache() {
361 func (client *KeepTestClient) Close() {
365 func (client *KeepTestClient) SetStorageClasses(sc []string) {
366 client.StorageClasses = sc
369 type FileWrapper struct {
374 func (fw FileWrapper) Readdir(n int) ([]os.FileInfo, error) {
375 return nil, errors.New("not implemented")
378 func (fw FileWrapper) Seek(int64, int) (int64, error) {
379 return 0, errors.New("not implemented")
382 func (fw FileWrapper) Size() int64 {
386 func (fw FileWrapper) Stat() (os.FileInfo, error) {
387 return nil, errors.New("not implemented")
390 func (fw FileWrapper) Truncate(int64) error {
391 return errors.New("not implemented")
394 func (fw FileWrapper) Write([]byte) (int, error) {
395 return 0, errors.New("not implemented")
398 func (fw FileWrapper) Sync() error {
399 return errors.New("not implemented")
402 func (fw FileWrapper) Snapshot() (*arvados.Subtree, error) {
403 return nil, errors.New("not implemented")
406 func (fw FileWrapper) Splice(*arvados.Subtree) error {
407 return errors.New("not implemented")
410 func (client *KeepTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
411 if filename == hwImageID+".tar" {
412 rdr := ioutil.NopCloser(&bytes.Buffer{})
414 return FileWrapper{rdr, 1321984}, nil
415 } else if filename == "/file1_in_main.txt" {
416 rdr := ioutil.NopCloser(strings.NewReader("foo"))
418 return FileWrapper{rdr, 3}, nil
423 type apiStubServer struct {
424 server *httptest.Server
425 proxy *httputil.ReverseProxy
426 intercept func(http.ResponseWriter, *http.Request) bool
428 container arvados.Container
429 logs map[string]string
432 func apiStub() (*arvados.Client, *apiStubServer) {
433 client := arvados.NewClientFromEnv()
434 apistub := &apiStubServer{}
435 apistub.server = httptest.NewTLSServer(apistub)
436 apistub.proxy = httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "https", Host: client.APIHost})
438 apistub.proxy.Transport = arvados.InsecureHTTPClient.Transport
440 client.APIHost = apistub.server.Listener.Addr().String()
441 return client, apistub
444 func (apistub *apiStubServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
445 if apistub.intercept != nil && apistub.intercept(w, r) {
448 if r.Method == "POST" && r.URL.Path == "/arvados/v1/logs" {
451 EventType string `json:"event_type"`
457 json.NewDecoder(r.Body).Decode(&body)
458 apistub.logs[body.Log.EventType] += body.Log.Properties.Text
461 if r.Method == "GET" && r.URL.Path == "/arvados/v1/collections/"+hwPDH {
462 json.NewEncoder(w).Encode(arvados.Collection{ManifestText: hwManifest})
465 if r.Method == "GET" && r.URL.Path == "/arvados/v1/collections/"+otherPDH {
466 json.NewEncoder(w).Encode(arvados.Collection{ManifestText: otherManifest})
469 if r.Method == "GET" && r.URL.Path == "/arvados/v1/collections/"+normalizedWithSubdirsPDH {
470 json.NewEncoder(w).Encode(arvados.Collection{ManifestText: normalizedManifestWithSubdirs})
473 if r.Method == "GET" && r.URL.Path == "/arvados/v1/collections/"+denormalizedWithSubdirsPDH {
474 json.NewEncoder(w).Encode(arvados.Collection{ManifestText: denormalizedManifestWithSubdirs})
477 if r.Method == "GET" && r.URL.Path == "/arvados/v1/containers/"+apistub.container.UUID {
478 json.NewEncoder(w).Encode(apistub.container)
481 apistub.proxy.ServeHTTP(w, r)
484 func (s *TestSuite) TestLoadImage(c *C) {
485 s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH
486 s.runner.Container.Mounts = map[string]arvados.Mount{
487 "/out": {Kind: "tmp", Writable: true},
489 s.runner.Container.OutputPath = "/out"
491 _, err := s.runner.SetupMounts()
494 imageID, err := s.runner.LoadImage()
496 c.Check(s.executor.loaded, Matches, ".*"+regexp.QuoteMeta(arvadostest.DockerImage112Filename))
497 c.Check(imageID, Equals, strings.TrimSuffix(arvadostest.DockerImage112Filename, ".tar"))
499 s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH
500 s.executor.imageLoaded = false
501 s.executor.loaded = ""
502 s.executor.loadErr = errors.New("bork")
503 imageID, err = s.runner.LoadImage()
504 c.Check(err, ErrorMatches, ".*bork")
505 c.Check(s.executor.loaded, Matches, ".*"+regexp.QuoteMeta(arvadostest.DockerImage112Filename))
507 s.runner.Container.ContainerImage = fakeInputCollectionPDH
508 s.executor.imageLoaded = false
509 s.executor.loaded = ""
510 s.executor.loadErr = nil
511 imageID, err = s.runner.LoadImage()
512 c.Check(err, ErrorMatches, "image collection does not include a \\.tar image file")
513 c.Check(s.executor.loaded, Equals, "")
516 type ArvErrorTestClient struct{}
518 func (ArvErrorTestClient) Create(resourceType string,
519 parameters arvadosclient.Dict,
520 output interface{}) error {
524 func (ArvErrorTestClient) Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) error {
525 if method == "GET" && resourceType == "containers" && action == "auth" {
528 return errors.New("ArvError")
531 func (ArvErrorTestClient) CallRaw(method, resourceType, uuid, action string,
532 parameters arvadosclient.Dict) (reader io.ReadCloser, err error) {
533 return nil, errors.New("ArvError")
536 func (ArvErrorTestClient) Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error {
537 return errors.New("ArvError")
540 func (ArvErrorTestClient) Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error) {
544 func (ArvErrorTestClient) Discovery(key string) (interface{}, error) {
545 return discoveryMap[key], nil
548 type KeepErrorTestClient struct {
552 func (*KeepErrorTestClient) ManifestFileReader(manifest.Manifest, string) (arvados.File, error) {
553 return nil, errors.New("KeepError")
556 func (*KeepErrorTestClient) BlockWrite(context.Context, arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) {
557 return arvados.BlockWriteResponse{}, errors.New("KeepError")
560 func (*KeepErrorTestClient) LocalLocator(string) (string, error) {
561 return "", errors.New("KeepError")
564 type KeepReadErrorTestClient struct {
568 func (*KeepReadErrorTestClient) ReadAt(string, []byte, int) (int, error) {
569 return 0, errors.New("KeepError")
572 type ErrorReader struct {
576 func (ErrorReader) Read(p []byte) (n int, err error) {
577 return 0, errors.New("ErrorReader")
580 func (ErrorReader) Seek(int64, int) (int64, error) {
581 return 0, errors.New("ErrorReader")
584 func (KeepReadErrorTestClient) ManifestFileReader(m manifest.Manifest, filename string) (arvados.File, error) {
585 return ErrorReader{}, nil
588 type ClosableBuffer struct {
592 func (*ClosableBuffer) Close() error {
596 type TestLogs struct {
597 Stdout ClosableBuffer
598 Stderr ClosableBuffer
601 func (tl *TestLogs) NewTestLoggingWriter(logstr string) (io.WriteCloser, error) {
602 if logstr == "stdout" {
603 return &tl.Stdout, nil
605 if logstr == "stderr" {
606 return &tl.Stderr, nil
608 return nil, errors.New("???")
611 func dockerLog(fd byte, msg string) []byte {
613 header := make([]byte, 8+len(by))
615 header[7] = byte(len(by))
620 func (s *TestSuite) TestRunContainer(c *C) {
621 s.executor.runFunc = func() int {
622 fmt.Fprintf(s.executor.created.Stdout, "Hello world\n")
627 s.runner.NewLogWriter = logs.NewTestLoggingWriter
628 s.runner.Container.ContainerImage = arvadostest.DockerImage112PDH
629 s.runner.Container.Command = []string{"./hw"}
630 s.runner.Container.OutputStorageClasses = []string{"default"}
632 imageID, err := s.runner.LoadImage()
635 err = s.runner.CreateContainer(imageID, nil)
638 err = s.runner.StartContainer()
641 err = s.runner.WaitFinish()
644 c.Check(logs.Stdout.String(), Matches, ".*Hello world\n")
645 c.Check(logs.Stderr.String(), Equals, "")
648 func (s *TestSuite) TestCommitLogs(c *C) {
649 api := &ArvTestClient{}
650 kc := &KeepTestClient{}
652 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
654 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
656 cr.CrunchLog.Print("Hello world!")
657 cr.CrunchLog.Print("Goodbye")
658 cr.finalState = "Complete"
660 err = cr.CommitLogs()
663 c.Check(api.Calls, Equals, 2)
664 c.Check(api.Content[1]["ensure_unique_name"], Equals, true)
665 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["name"], Equals, "logs for zzzzz-zzzzz-zzzzzzzzzzzzzzz")
666 c.Check(api.Content[1]["collection"].(arvadosclient.Dict)["manifest_text"], Equals, ". 744b2e4553123b02fa7b452ec5c18993+123 0:123:crunch-run.txt\n")
667 c.Check(*cr.LogsPDH, Equals, "63da7bdacf08c40f604daad80c261e9a+60")
670 func (s *TestSuite) TestUpdateContainerRunning(c *C) {
671 api := &ArvTestClient{}
672 kc := &KeepTestClient{}
674 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
677 err = cr.UpdateContainerRunning("")
680 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Running")
683 func (s *TestSuite) TestUpdateContainerComplete(c *C) {
684 api := &ArvTestClient{}
685 kc := &KeepTestClient{}
687 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
690 cr.LogsPDH = new(string)
691 *cr.LogsPDH = "d3a229d2fe3690c2c3e75a71a153c6a3+60"
693 cr.ExitCode = new(int)
695 cr.finalState = "Complete"
697 err = cr.UpdateContainerFinal()
700 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], Equals, *cr.LogsPDH)
701 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], Equals, *cr.ExitCode)
702 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Complete")
705 func (s *TestSuite) TestUpdateContainerCancelled(c *C) {
706 api := &ArvTestClient{}
707 kc := &KeepTestClient{}
709 cr, err := NewContainerRunner(s.client, api, kc, "zzzzz-zzzzz-zzzzzzzzzzzzzzz")
712 cr.finalState = "Cancelled"
714 err = cr.UpdateContainerFinal()
717 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["log"], IsNil)
718 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["exit_code"], IsNil)
719 c.Check(api.Content[0]["container"].(arvadosclient.Dict)["state"], Equals, "Cancelled")
722 // Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
723 // dress rehearsal of the Run() function, starting from a JSON container record.
724 func (s *TestSuite) fullRunHelper(c *C, record string, extraMounts []string, fn func() int) (*ArvTestClient, *ContainerRunner, string) {
725 err := json.Unmarshal([]byte(record), &s.api.Container)
727 initialState := s.api.Container.State
730 SecretMounts map[string]arvados.Mount `json:"secret_mounts"`
732 err = json.Unmarshal([]byte(record), &sm)
734 secretMounts, err := json.Marshal(sm)
736 c.Logf("SecretMounts decoded %v json %q", sm, secretMounts)
738 s.executor.runFunc = fn
740 s.runner.statInterval = 100 * time.Millisecond
741 s.runner.containerWatchdogInterval = time.Second
743 realTemp := c.MkDir()
745 s.runner.MkTempDir = func(_, prefix string) (string, error) {
747 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
748 err := os.Mkdir(d, os.ModePerm)
749 if err != nil && strings.Contains(err.Error(), ": file exists") {
750 // Test case must have pre-populated the tempdir
755 client, _ := apiStub()
756 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
757 return &ArvTestClient{secretMounts: secretMounts}, &s.testContainerKeepClient, client, nil
760 if extraMounts != nil && len(extraMounts) > 0 {
761 err := s.runner.SetupArvMountPoint("keep")
764 for _, m := range extraMounts {
765 os.MkdirAll(s.runner.ArvMountPoint+"/by_id/"+m, os.ModePerm)
770 if s.api.CalledWith("container.state", "Complete") != nil {
773 if s.executor.loadErr == nil && s.executor.createErr == nil && initialState != "Running" {
774 c.Check(s.api.WasSetRunning, Equals, true)
775 var lastupdate arvadosclient.Dict
776 for _, content := range s.api.Content {
777 if content["container"] != nil {
778 lastupdate = content["container"].(arvadosclient.Dict)
781 if lastupdate["log"] == nil {
782 c.Errorf("no container update with non-nil log -- updates were: %v", s.api.Content)
787 for k, v := range s.api.Logs {
793 return s.api, s.runner, realTemp
796 func (s *TestSuite) TestFullRunHello(c *C) {
797 s.runner.enableMemoryLimit = true
798 s.runner.networkMode = "default"
799 s.fullRunHelper(c, `{
800 "command": ["echo", "hello world"],
801 "container_image": "`+arvadostest.DockerImage112PDH+`",
803 "environment": {"foo":"bar","baz":"waz"},
804 "mounts": {"/tmp": {"kind": "tmp"} },
805 "output_path": "/tmp",
807 "runtime_constraints": {"vcpus":1,"ram":1000000},
809 "output_storage_classes": ["default"]
810 }`, nil, func() int {
811 c.Check(s.executor.created.Command, DeepEquals, []string{"echo", "hello world"})
812 c.Check(s.executor.created.Image, Equals, "sha256:d8309758b8fe2c81034ffc8a10c36460b77db7bc5e7b448c4e5b684f9d95a678")
813 c.Check(s.executor.created.Env, DeepEquals, map[string]string{"foo": "bar", "baz": "waz"})
814 c.Check(s.executor.created.VCPUs, Equals, 1)
815 c.Check(s.executor.created.RAM, Equals, int64(1000000))
816 c.Check(s.executor.created.NetworkMode, Equals, "default")
817 c.Check(s.executor.created.EnableNetwork, Equals, false)
818 c.Check(s.executor.created.CUDADeviceCount, Equals, 0)
819 fmt.Fprintln(s.executor.created.Stdout, "hello world")
823 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
824 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
825 c.Check(s.api.Logs["stdout"].String(), Matches, ".*hello world\n")
826 c.Check(s.testDispatcherKeepClient.StorageClasses, DeepEquals, []string{"default"})
827 c.Check(s.testContainerKeepClient.StorageClasses, DeepEquals, []string{"default"})
830 func (s *TestSuite) TestRunAlreadyRunning(c *C) {
832 s.fullRunHelper(c, `{
833 "command": ["sleep", "3"],
834 "container_image": "`+arvadostest.DockerImage112PDH+`",
837 "mounts": {"/tmp": {"kind": "tmp"} },
838 "output_path": "/tmp",
840 "runtime_constraints": {},
841 "scheduling_parameters":{"max_run_time": 1},
843 }`, nil, func() int {
847 c.Check(s.api.CalledWith("container.state", "Cancelled"), IsNil)
848 c.Check(s.api.CalledWith("container.state", "Complete"), IsNil)
849 c.Check(ran, Equals, false)
852 func ec2MetadataServerStub(c *C, token *string, failureRate float64, stoptime *atomic.Value) *httptest.Server {
854 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
855 if !failedOnce || rand.Float64() < failureRate {
856 w.WriteHeader(http.StatusServiceUnavailable)
861 case "/latest/api/token":
862 fmt.Fprintln(w, *token)
863 case "/latest/meta-data/spot/instance-action":
864 if r.Header.Get("X-aws-ec2-metadata-token") != *token {
865 w.WriteHeader(http.StatusUnauthorized)
866 } else if t, _ := stoptime.Load().(time.Time); t.IsZero() {
867 w.WriteHeader(http.StatusNotFound)
869 fmt.Fprintf(w, `{"action":"stop","time":"%s"}`, t.Format(time.RFC3339))
872 w.WriteHeader(http.StatusNotFound)
877 func (s *TestSuite) TestSpotInterruptionNotice(c *C) {
878 s.testSpotInterruptionNotice(c, 0.1)
881 func (s *TestSuite) TestSpotInterruptionNoticeNotAvailable(c *C) {
882 s.testSpotInterruptionNotice(c, 1)
885 func (s *TestSuite) testSpotInterruptionNotice(c *C, failureRate float64) {
886 var stoptime atomic.Value
887 token := "fake-ec2-metadata-token"
888 stub := ec2MetadataServerStub(c, &token, failureRate, &stoptime)
891 defer func(i time.Duration, u string) {
892 spotInterruptionCheckInterval = i
893 ec2MetadataBaseURL = u
894 }(spotInterruptionCheckInterval, ec2MetadataBaseURL)
895 spotInterruptionCheckInterval = time.Second / 8
896 ec2MetadataBaseURL = stub.URL
898 go s.runner.checkSpotInterruptionNotices()
899 s.fullRunHelper(c, `{
900 "command": ["sleep", "3"],
901 "container_image": "`+arvadostest.DockerImage112PDH+`",
904 "mounts": {"/tmp": {"kind": "tmp"} },
905 "output_path": "/tmp",
907 "runtime_constraints": {},
909 }`, nil, func() int {
910 time.Sleep(time.Second)
911 stoptime.Store(time.Now().Add(time.Minute).UTC())
912 token = "different-fake-ec2-metadata-token"
913 time.Sleep(time.Second)
916 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Checking for spot interruptions every 125ms using instance metadata at http://.*`)
917 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Error checking spot interruptions: 503 Service Unavailable.*`)
918 if failureRate == 1 {
919 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Giving up on checking spot interruptions after too many consecutive failures.*`)
921 text := `Cloud provider scheduled instance stop at ` + stoptime.Load().(time.Time).Format(time.RFC3339)
922 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*`+text+`.*`)
923 c.Check(s.api.CalledWith("container.runtime_status.warning", "preemption notice"), NotNil)
924 c.Check(s.api.CalledWith("container.runtime_status.warningDetail", text), NotNil)
925 c.Check(s.api.CalledWith("container.runtime_status.preemptionNotice", text), NotNil)
929 func (s *TestSuite) TestRunTimeExceeded(c *C) {
930 s.fullRunHelper(c, `{
931 "command": ["sleep", "3"],
932 "container_image": "`+arvadostest.DockerImage112PDH+`",
935 "mounts": {"/tmp": {"kind": "tmp"} },
936 "output_path": "/tmp",
938 "runtime_constraints": {},
939 "scheduling_parameters":{"max_run_time": 1},
941 }`, nil, func() int {
942 time.Sleep(3 * time.Second)
946 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
947 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*maximum run time exceeded.*")
950 func (s *TestSuite) TestContainerWaitFails(c *C) {
951 s.fullRunHelper(c, `{
952 "command": ["sleep", "3"],
953 "container_image": "`+arvadostest.DockerImage112PDH+`",
955 "mounts": {"/tmp": {"kind": "tmp"} },
956 "output_path": "/tmp",
959 }`, nil, func() int {
960 s.executor.waitErr = errors.New("Container is not running")
964 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
965 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Container is not running.*")
968 func (s *TestSuite) TestCrunchstat(c *C) {
969 s.fullRunHelper(c, `{
970 "command": ["sleep", "1"],
971 "container_image": "`+arvadostest.DockerImage112PDH+`",
974 "mounts": {"/tmp": {"kind": "tmp"} },
975 "output_path": "/tmp",
977 "runtime_constraints": {},
979 }`, nil, func() int {
980 time.Sleep(time.Second)
984 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
985 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
987 // We didn't actually start a container, so crunchstat didn't
988 // find accounting files and therefore didn't log any stats.
989 // It should have logged a "can't find accounting files"
990 // message after one poll interval, though, so we can confirm
992 c.Assert(s.api.Logs["crunchstat"], NotNil)
993 c.Check(s.api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files have not appeared after 100ms.*`)
995 // The "files never appeared" log assures us that we called
996 // (*crunchstat.Reporter)Stop(), and that we set it up with
997 // the correct container ID "abcde":
998 c.Check(s.api.Logs["crunchstat"].String(), Matches, `(?ms).*cgroup stats files never appeared for cgroupid\n`)
1001 func (s *TestSuite) TestNodeInfoLog(c *C) {
1002 os.Setenv("SLURMD_NODENAME", "compute2")
1003 s.fullRunHelper(c, `{
1004 "command": ["sleep", "1"],
1005 "container_image": "`+arvadostest.DockerImage112PDH+`",
1008 "mounts": {"/tmp": {"kind": "tmp"} },
1009 "output_path": "/tmp",
1011 "runtime_constraints": {},
1013 }`, nil, func() int {
1014 time.Sleep(time.Second)
1018 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1019 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1021 c.Assert(s.api.Logs["node"], NotNil)
1022 json := s.api.Logs["node"].String()
1023 c.Check(json, Matches, `(?ms).*"uuid": *"zzzzz-7ekkf-2z3mc76g2q73aio".*`)
1024 c.Check(json, Matches, `(?ms).*"total_cpu_cores": *16.*`)
1025 c.Check(json, Not(Matches), `(?ms).*"info":.*`)
1027 c.Assert(s.api.Logs["node-info"], NotNil)
1028 json = s.api.Logs["node-info"].String()
1029 c.Check(json, Matches, `(?ms).*Host Information.*`)
1030 c.Check(json, Matches, `(?ms).*CPU Information.*`)
1031 c.Check(json, Matches, `(?ms).*Memory Information.*`)
1032 c.Check(json, Matches, `(?ms).*Disk Space.*`)
1033 c.Check(json, Matches, `(?ms).*Disk INodes.*`)
1036 func (s *TestSuite) TestLogVersionAndRuntime(c *C) {
1037 s.fullRunHelper(c, `{
1038 "command": ["sleep", "1"],
1039 "container_image": "`+arvadostest.DockerImage112PDH+`",
1042 "mounts": {"/tmp": {"kind": "tmp"} },
1043 "output_path": "/tmp",
1045 "runtime_constraints": {},
1047 }`, nil, func() int {
1051 c.Assert(s.api.Logs["crunch-run"], NotNil)
1052 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*crunch-run \S+ \(go\S+\) start.*`)
1053 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*crunch-run process has uid=\d+\(.+\) gid=\d+\(.+\) groups=\d+\(.+\)(,\d+\(.+\))*\n.*`)
1054 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Executing container: zzzzz-zzzzz-zzzzzzzzzzzzzzz.*`)
1055 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Using container runtime: stub.*`)
1058 func (s *TestSuite) testLogRSSThresholds(c *C, ram int, expected []int, notExpected int) {
1059 s.runner.cgroupRoot = "testdata/fakestat"
1060 s.fullRunHelper(c, `{
1061 "command": ["true"],
1062 "container_image": "`+arvadostest.DockerImage112PDH+`",
1065 "mounts": {"/tmp": {"kind": "tmp"} },
1066 "output_path": "/tmp",
1068 "runtime_constraints": {"ram": `+strconv.Itoa(ram)+`},
1070 }`, nil, func() int { return 0 })
1071 logs := s.api.Logs["crunch-run"].String()
1072 pattern := logLineStart + `Container using over %d%% of memory \(rss 734003200/%d bytes\)`
1074 for _, threshold = range expected {
1075 c.Check(logs, Matches, fmt.Sprintf(pattern, threshold, ram))
1077 if notExpected > threshold {
1078 c.Check(logs, Not(Matches), fmt.Sprintf(pattern, notExpected, ram))
1082 func (s *TestSuite) TestLogNoRSSThresholds(c *C) {
1083 s.testLogRSSThresholds(c, 7340032000, []int{}, 90)
1086 func (s *TestSuite) TestLogSomeRSSThresholds(c *C) {
1087 onePercentRSS := 7340032
1088 s.testLogRSSThresholds(c, 102*onePercentRSS, []int{90, 95}, 99)
1091 func (s *TestSuite) TestLogAllRSSThresholds(c *C) {
1092 s.testLogRSSThresholds(c, 734003299, []int{90, 95, 99}, 0)
1095 func (s *TestSuite) TestLogMaximaAfterRun(c *C) {
1096 s.runner.cgroupRoot = "testdata/fakestat"
1097 s.runner.parentTemp = c.MkDir()
1098 s.fullRunHelper(c, `{
1099 "command": ["true"],
1100 "container_image": "`+arvadostest.DockerImage112PDH+`",
1103 "mounts": {"/tmp": {"kind": "tmp"} },
1104 "output_path": "/tmp",
1106 "runtime_constraints": {"ram": 7340032000},
1108 }`, nil, func() int { return 0 })
1109 logs := s.api.Logs["crunch-run"].String()
1110 for _, expected := range []string{
1111 `Maximum disk usage was \d+%, \d+/\d+ bytes`,
1112 `Maximum container memory cache usage was 73400320 bytes`,
1113 `Maximum container memory swap usage was 320 bytes`,
1114 `Maximum container memory pgmajfault usage was 20 faults`,
1115 `Maximum container memory rss usage was 10%, 734003200/7340032000 bytes`,
1116 `Maximum crunch-run memory rss usage was \d+ bytes`,
1118 c.Check(logs, Matches, logLineStart+expected)
1122 func (s *TestSuite) TestCommitNodeInfoBeforeStart(c *C) {
1123 var collection_create, container_update arvadosclient.Dict
1124 s.fullRunHelper(c, `{
1125 "command": ["true"],
1126 "container_image": "`+arvadostest.DockerImage112PDH+`",
1129 "mounts": {"/tmp": {"kind": "tmp"} },
1130 "output_path": "/tmp",
1132 "runtime_constraints": {},
1134 "uuid": "zzzzz-dz642-202301121543210"
1135 }`, nil, func() int {
1136 collection_create = s.api.CalledWith("ensure_unique_name", true)
1137 container_update = s.api.CalledWith("container.state", "Running")
1141 c.Assert(collection_create, NotNil)
1142 log_collection := collection_create["collection"].(arvadosclient.Dict)
1143 c.Check(log_collection["name"], Equals, "logs for zzzzz-dz642-202301121543210")
1144 manifest_text := log_collection["manifest_text"].(string)
1145 // We check that the file size is at least two digits as an easy way to
1146 // check the file isn't empty.
1147 c.Check(manifest_text, Matches, `\. .+ \d+:\d{2,}:node-info\.txt( .+)?\n`)
1148 c.Check(manifest_text, Matches, `\. .+ \d+:\d{2,}:node\.json( .+)?\n`)
1150 c.Assert(container_update, NotNil)
1151 // As of Arvados 2.5.0, the container update must specify its log in PDH
1152 // format for the API server to propagate it to container requests, which
1153 // is what we care about for this test.
1154 expect_pdh := fmt.Sprintf("%x+%d", md5.Sum([]byte(manifest_text)), len(manifest_text))
1155 c.Check(container_update["container"].(arvadosclient.Dict)["log"], Equals, expect_pdh)
1158 func (s *TestSuite) TestContainerRecordLog(c *C) {
1159 s.fullRunHelper(c, `{
1160 "command": ["sleep", "1"],
1161 "container_image": "`+arvadostest.DockerImage112PDH+`",
1164 "mounts": {"/tmp": {"kind": "tmp"} },
1165 "output_path": "/tmp",
1167 "runtime_constraints": {},
1171 time.Sleep(time.Second)
1175 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1176 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1178 c.Assert(s.api.Logs["container"], NotNil)
1179 c.Check(s.api.Logs["container"].String(), Matches, `(?ms).*container_image.*`)
1182 func (s *TestSuite) TestFullRunStderr(c *C) {
1183 s.fullRunHelper(c, `{
1184 "command": ["/bin/sh", "-c", "echo hello ; echo world 1>&2 ; exit 1"],
1185 "container_image": "`+arvadostest.DockerImage112PDH+`",
1188 "mounts": {"/tmp": {"kind": "tmp"} },
1189 "output_path": "/tmp",
1191 "runtime_constraints": {},
1193 }`, nil, func() int {
1194 fmt.Fprintln(s.executor.created.Stdout, "hello")
1195 fmt.Fprintln(s.executor.created.Stderr, "world")
1199 final := s.api.CalledWith("container.state", "Complete")
1200 c.Assert(final, NotNil)
1201 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
1202 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
1204 c.Check(s.api.Logs["stdout"].String(), Matches, ".*hello\n")
1205 c.Check(s.api.Logs["stderr"].String(), Matches, ".*world\n")
1208 func (s *TestSuite) TestFullRunDefaultCwd(c *C) {
1209 s.fullRunHelper(c, `{
1211 "container_image": "`+arvadostest.DockerImage112PDH+`",
1214 "mounts": {"/tmp": {"kind": "tmp"} },
1215 "output_path": "/tmp",
1217 "runtime_constraints": {},
1219 }`, nil, func() int {
1220 fmt.Fprintf(s.executor.created.Stdout, "workdir=%q", s.executor.created.WorkingDir)
1224 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1225 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1226 c.Log(s.api.Logs["stdout"])
1227 c.Check(s.api.Logs["stdout"].String(), Matches, `.*workdir=""\n`)
1230 func (s *TestSuite) TestFullRunSetCwd(c *C) {
1231 s.fullRunHelper(c, `{
1233 "container_image": "`+arvadostest.DockerImage112PDH+`",
1236 "mounts": {"/tmp": {"kind": "tmp"} },
1237 "output_path": "/tmp",
1239 "runtime_constraints": {},
1241 }`, nil, func() int {
1242 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.WorkingDir)
1246 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1247 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1248 c.Check(s.api.Logs["stdout"].String(), Matches, ".*/bin\n")
1251 func (s *TestSuite) TestFullRunSetOutputStorageClasses(c *C) {
1252 s.fullRunHelper(c, `{
1254 "container_image": "`+arvadostest.DockerImage112PDH+`",
1257 "mounts": {"/tmp": {"kind": "tmp"} },
1258 "output_path": "/tmp",
1260 "runtime_constraints": {},
1262 "output_storage_classes": ["foo", "bar"]
1263 }`, nil, func() int {
1264 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.WorkingDir)
1268 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1269 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1270 c.Check(s.api.Logs["stdout"].String(), Matches, ".*/bin\n")
1271 c.Check(s.testDispatcherKeepClient.StorageClasses, DeepEquals, []string{"foo", "bar"})
1272 c.Check(s.testContainerKeepClient.StorageClasses, DeepEquals, []string{"foo", "bar"})
1275 func (s *TestSuite) TestEnableCUDADeviceCount(c *C) {
1276 s.fullRunHelper(c, `{
1278 "container_image": "`+arvadostest.DockerImage112PDH+`",
1281 "mounts": {"/tmp": {"kind": "tmp"} },
1282 "output_path": "/tmp",
1284 "runtime_constraints": {"cuda": {"device_count": 2}},
1286 "output_storage_classes": ["foo", "bar"]
1287 }`, nil, func() int {
1288 fmt.Fprintln(s.executor.created.Stdout, "ok")
1291 c.Check(s.executor.created.CUDADeviceCount, Equals, 2)
1294 func (s *TestSuite) TestEnableCUDAHardwareCapability(c *C) {
1295 s.fullRunHelper(c, `{
1297 "container_image": "`+arvadostest.DockerImage112PDH+`",
1300 "mounts": {"/tmp": {"kind": "tmp"} },
1301 "output_path": "/tmp",
1303 "runtime_constraints": {"cuda": {"hardware_capability": "foo"}},
1305 "output_storage_classes": ["foo", "bar"]
1306 }`, nil, func() int {
1307 fmt.Fprintln(s.executor.created.Stdout, "ok")
1310 c.Check(s.executor.created.CUDADeviceCount, Equals, 0)
1313 func (s *TestSuite) TestStopOnSignal(c *C) {
1314 s.executor.runFunc = func() int {
1315 s.executor.created.Stdout.Write([]byte("foo\n"))
1316 s.runner.SigChan <- syscall.SIGINT
1317 time.Sleep(10 * time.Second)
1320 s.testStopContainer(c)
1323 func (s *TestSuite) TestStopOnArvMountDeath(c *C) {
1324 s.executor.runFunc = func() int {
1325 s.executor.created.Stdout.Write([]byte("foo\n"))
1326 s.runner.ArvMountExit <- nil
1327 close(s.runner.ArvMountExit)
1328 time.Sleep(10 * time.Second)
1331 s.runner.ArvMountExit = make(chan error)
1332 s.testStopContainer(c)
1335 func (s *TestSuite) testStopContainer(c *C) {
1337 "command": ["/bin/sh", "-c", "echo foo && sleep 30 && echo bar"],
1338 "container_image": "` + arvadostest.DockerImage112PDH + `",
1341 "mounts": {"/tmp": {"kind": "tmp"} },
1342 "output_path": "/tmp",
1344 "runtime_constraints": {},
1348 err := json.Unmarshal([]byte(record), &s.api.Container)
1349 c.Assert(err, IsNil)
1351 s.runner.RunArvMount = func([]string, string) (*exec.Cmd, error) { return nil, nil }
1352 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
1353 return &ArvTestClient{}, &KeepTestClient{}, nil, nil
1356 done := make(chan error)
1358 done <- s.runner.Run()
1361 case <-time.After(20 * time.Second):
1362 pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
1363 c.Fatal("timed out")
1367 for k, v := range s.api.Logs {
1369 c.Log(v.String(), "\n")
1372 c.Check(s.api.CalledWith("container.log", nil), NotNil)
1373 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
1374 c.Check(s.api.Logs["stdout"].String(), Matches, "(?ms).*foo\n$")
1377 func (s *TestSuite) TestFullRunSetEnv(c *C) {
1378 s.fullRunHelper(c, `{
1379 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1380 "container_image": "`+arvadostest.DockerImage112PDH+`",
1382 "environment": {"FROBIZ": "bilbo"},
1383 "mounts": {"/tmp": {"kind": "tmp"} },
1384 "output_path": "/tmp",
1386 "runtime_constraints": {},
1388 }`, nil, func() int {
1389 fmt.Fprintf(s.executor.created.Stdout, "%v", s.executor.created.Env)
1393 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1394 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1395 c.Check(s.api.Logs["stdout"].String(), Matches, `.*map\[FROBIZ:bilbo\]\n`)
1398 type ArvMountCmdLine struct {
1403 func (am *ArvMountCmdLine) ArvMountTest(c []string, token string) (*exec.Cmd, error) {
1409 func stubCert(temp string) string {
1410 path := temp + "/ca-certificates.crt"
1411 crt, _ := os.Create(path)
1413 arvadosclient.CertFiles = []string{path}
1417 func (s *TestSuite) TestSetupMounts(c *C) {
1419 am := &ArvMountCmdLine{}
1420 cr.RunArvMount = am.ArvMountTest
1421 cr.containerClient, _ = apiStub()
1422 cr.ContainerArvClient = &ArvTestClient{}
1423 cr.ContainerKeepClient = &KeepTestClient{}
1424 cr.Container.OutputStorageClasses = []string{"default"}
1426 realTemp := c.MkDir()
1427 certTemp := c.MkDir()
1428 stubCertPath := stubCert(certTemp)
1429 cr.parentTemp = realTemp
1432 cr.MkTempDir = func(_ string, prefix string) (string, error) {
1434 d := fmt.Sprintf("%s/%s%d", realTemp, prefix, i)
1435 err := os.Mkdir(d, os.ModePerm)
1436 if err != nil && strings.Contains(err.Error(), ": file exists") {
1437 // Test case must have pre-populated the tempdir
1443 checkEmpty := func() {
1444 // Should be deleted.
1445 _, err := os.Stat(realTemp)
1446 c.Assert(os.IsNotExist(err), Equals, true)
1448 // Now recreate it for the next test.
1449 c.Assert(os.Mkdir(realTemp, 0777), IsNil)
1454 cr.ArvMountPoint = ""
1455 cr.Container.Mounts = make(map[string]arvados.Mount)
1456 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1457 cr.Container.OutputPath = "/tmp"
1458 cr.statInterval = 5 * time.Second
1459 bindmounts, err := cr.SetupMounts()
1461 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1462 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1463 "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1464 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/tmp": {realTemp + "/tmp2", false}})
1465 os.RemoveAll(cr.ArvMountPoint)
1472 cr.ArvMountPoint = ""
1473 cr.Container.Mounts = make(map[string]arvados.Mount)
1474 cr.Container.Mounts["/out"] = arvados.Mount{Kind: "tmp"}
1475 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1476 cr.Container.OutputPath = "/out"
1477 cr.Container.OutputStorageClasses = []string{"foo", "bar"}
1479 bindmounts, err := cr.SetupMounts()
1481 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1482 "--read-write", "--storage-classes", "foo,bar", "--crunchstat-interval=5",
1483 "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1484 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/out": {realTemp + "/tmp2", false}, "/tmp": {realTemp + "/tmp3", false}})
1485 os.RemoveAll(cr.ArvMountPoint)
1492 cr.ArvMountPoint = ""
1493 cr.Container.Mounts = make(map[string]arvados.Mount)
1494 cr.Container.Mounts["/tmp"] = arvados.Mount{Kind: "tmp"}
1495 cr.Container.OutputPath = "/tmp"
1496 cr.Container.RuntimeConstraints.API = true
1497 cr.Container.OutputStorageClasses = []string{"default"}
1499 bindmounts, err := cr.SetupMounts()
1501 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1502 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1503 "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1504 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/tmp": {realTemp + "/tmp2", false}, "/etc/arvados/ca-certificates.crt": {stubCertPath, true}})
1505 os.RemoveAll(cr.ArvMountPoint)
1509 cr.Container.RuntimeConstraints.API = false
1514 cr.ArvMountPoint = ""
1515 cr.Container.Mounts = map[string]arvados.Mount{
1516 "/keeptmp": {Kind: "collection", Writable: true},
1518 cr.Container.OutputPath = "/keeptmp"
1520 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1522 bindmounts, err := cr.SetupMounts()
1524 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1525 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1526 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1527 c.Check(bindmounts, DeepEquals, map[string]bindmount{"/keeptmp": {realTemp + "/keep1/tmp0", false}})
1528 os.RemoveAll(cr.ArvMountPoint)
1535 cr.ArvMountPoint = ""
1536 cr.Container.Mounts = map[string]arvados.Mount{
1537 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1538 "/keepout": {Kind: "collection", Writable: true},
1540 cr.Container.OutputPath = "/keepout"
1542 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1543 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1545 bindmounts, err := cr.SetupMounts()
1547 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1548 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5",
1549 "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1550 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1551 "/keepinp": {realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", true},
1552 "/keepout": {realTemp + "/keep1/tmp0", false},
1554 os.RemoveAll(cr.ArvMountPoint)
1561 cr.ArvMountPoint = ""
1562 cr.Container.RuntimeConstraints.KeepCacheRAM = 512
1563 cr.Container.Mounts = map[string]arvados.Mount{
1564 "/keepinp": {Kind: "collection", PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53"},
1565 "/keepout": {Kind: "collection", Writable: true},
1567 cr.Container.OutputPath = "/keepout"
1569 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1570 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1572 bindmounts, err := cr.SetupMounts()
1574 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1575 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", "--ram-cache",
1576 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1577 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1578 "/keepinp": {realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", true},
1579 "/keepout": {realTemp + "/keep1/tmp0", false},
1581 os.RemoveAll(cr.ArvMountPoint)
1586 for _, test := range []struct {
1590 {in: "foo", out: `"foo"`},
1591 {in: nil, out: `null`},
1592 {in: map[string]int64{"foo": 123456789123456789}, out: `{"foo":123456789123456789}`},
1595 cr.ArvMountPoint = ""
1596 cr.Container.Mounts = map[string]arvados.Mount{
1597 "/mnt/test.json": {Kind: "json", Content: test.in},
1599 bindmounts, err := cr.SetupMounts()
1601 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1602 "/mnt/test.json": {realTemp + "/json2/mountdata.json", true},
1604 content, err := ioutil.ReadFile(realTemp + "/json2/mountdata.json")
1606 c.Check(content, DeepEquals, []byte(test.out))
1607 os.RemoveAll(cr.ArvMountPoint)
1612 for _, test := range []struct {
1616 {in: "foo", out: `foo`},
1617 {in: nil, out: "error"},
1618 {in: map[string]int64{"foo": 123456789123456789}, out: "error"},
1621 cr.ArvMountPoint = ""
1622 cr.Container.Mounts = map[string]arvados.Mount{
1623 "/mnt/test.txt": {Kind: "text", Content: test.in},
1625 bindmounts, err := cr.SetupMounts()
1626 if test.out == "error" {
1627 c.Check(err.Error(), Equals, "content for mount \"/mnt/test.txt\" must be a string")
1630 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1631 "/mnt/test.txt": {realTemp + "/text2/mountdata.text", true},
1633 content, err := ioutil.ReadFile(realTemp + "/text2/mountdata.text")
1635 c.Check(content, DeepEquals, []byte(test.out))
1637 os.RemoveAll(cr.ArvMountPoint)
1642 // Read-only mount points are allowed underneath output_dir mount point
1645 cr.ArvMountPoint = ""
1646 cr.Container.Mounts = make(map[string]arvados.Mount)
1647 cr.Container.Mounts = map[string]arvados.Mount{
1648 "/tmp": {Kind: "tmp"},
1649 "/tmp/foo": {Kind: "collection"},
1651 cr.Container.OutputPath = "/tmp"
1653 os.MkdirAll(realTemp+"/keep1/tmp0", os.ModePerm)
1655 bindmounts, err := cr.SetupMounts()
1657 c.Check(am.Cmd, DeepEquals, []string{"arv-mount", "--foreground",
1658 "--read-write", "--storage-classes", "default", "--crunchstat-interval=5", "--ram-cache",
1659 "--file-cache", "512", "--mount-tmp", "tmp0", "--mount-by-pdh", "by_id", "--disable-event-listening", "--mount-by-id", "by_uuid", realTemp + "/keep1"})
1660 c.Check(bindmounts, DeepEquals, map[string]bindmount{
1661 "/tmp": {realTemp + "/tmp2", false},
1662 "/tmp/foo": {realTemp + "/keep1/tmp0", true},
1664 os.RemoveAll(cr.ArvMountPoint)
1669 // Writable mount points copied to output_dir mount point
1672 cr.ArvMountPoint = ""
1673 cr.Container.Mounts = make(map[string]arvados.Mount)
1674 cr.Container.Mounts = map[string]arvados.Mount{
1675 "/tmp": {Kind: "tmp"},
1676 "/tmp/foo": {Kind: "collection",
1677 PortableDataHash: "59389a8f9ee9d399be35462a0f92541c+53",
1679 "/tmp/bar": {Kind: "collection",
1680 PortableDataHash: "59389a8f9ee9d399be35462a0f92541d+53",
1684 cr.Container.OutputPath = "/tmp"
1686 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541c+53", os.ModePerm)
1687 os.MkdirAll(realTemp+"/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz", os.ModePerm)
1689 rf, _ := os.Create(realTemp + "/keep1/by_id/59389a8f9ee9d399be35462a0f92541d+53/baz/quux")
1690 rf.Write([]byte("bar"))
1693 _, err := cr.SetupMounts()
1695 _, err = os.Stat(cr.HostOutputDir + "/foo")
1697 _, err = os.Stat(cr.HostOutputDir + "/bar/quux")
1699 os.RemoveAll(cr.ArvMountPoint)
1704 // Only mount points of kind 'collection' are allowed underneath output_dir mount point
1707 cr.ArvMountPoint = ""
1708 cr.Container.Mounts = make(map[string]arvados.Mount)
1709 cr.Container.Mounts = map[string]arvados.Mount{
1710 "/tmp": {Kind: "tmp"},
1711 "/tmp/foo": {Kind: "tmp"},
1713 cr.Container.OutputPath = "/tmp"
1715 _, err := cr.SetupMounts()
1716 c.Check(err, NotNil)
1717 c.Check(err, ErrorMatches, `only mount points of kind 'collection', 'text' or 'json' are supported underneath the output_path.*`)
1718 os.RemoveAll(cr.ArvMountPoint)
1723 // Only mount point of kind 'collection' is allowed for stdin
1726 cr.ArvMountPoint = ""
1727 cr.Container.Mounts = make(map[string]arvados.Mount)
1728 cr.Container.Mounts = map[string]arvados.Mount{
1729 "stdin": {Kind: "tmp"},
1732 _, err := cr.SetupMounts()
1733 c.Check(err, NotNil)
1734 c.Check(err, ErrorMatches, `unsupported mount kind 'tmp' for stdin.*`)
1735 os.RemoveAll(cr.ArvMountPoint)
1743 cr.ArvMountPoint = ""
1744 git_client.InstallProtocol("https", git_http.NewClient(arvados.InsecureHTTPClient))
1745 cr.token = arvadostest.ActiveToken
1746 cr.Container.Mounts = make(map[string]arvados.Mount)
1747 cr.Container.Mounts = map[string]arvados.Mount{
1750 UUID: arvadostest.Repository2UUID,
1751 Commit: "fd3531f42995344f36c30b79f55f27b502f3d344",
1756 UUID: arvadostest.Repository2UUID,
1757 Commit: "5ebfab0522851df01fec11ec55a6d0f4877b542e",
1761 cr.Container.OutputPath = "/tmp"
1763 bindmounts, err := cr.SetupMounts()
1766 for path, mount := range bindmounts {
1767 c.Check(mount.ReadOnly, Equals, !cr.Container.Mounts[path].Writable, Commentf("%s %#v", path, mount))
1770 data, err := ioutil.ReadFile(bindmounts["/tip"].HostPath + "/dir1/dir2/file with mode 0644")
1772 c.Check(string(data), Equals, "\000\001\002\003")
1773 _, err = ioutil.ReadFile(bindmounts["/tip"].HostPath + "/file only on testbranch")
1774 c.Check(err, FitsTypeOf, &os.PathError{})
1775 c.Check(os.IsNotExist(err), Equals, true)
1777 data, err = ioutil.ReadFile(bindmounts["/non-tip"].HostPath + "/dir1/dir2/file with mode 0644")
1779 c.Check(string(data), Equals, "\000\001\002\003")
1780 data, err = ioutil.ReadFile(bindmounts["/non-tip"].HostPath + "/file only on testbranch")
1782 c.Check(string(data), Equals, "testfile\n")
1789 func (s *TestSuite) TestStdout(c *C) {
1791 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1792 "container_image": "` + arvadostest.DockerImage112PDH + `",
1794 "environment": {"FROBIZ": "bilbo"},
1795 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"} },
1796 "output_path": "/tmp",
1798 "runtime_constraints": {},
1802 s.fullRunHelper(c, helperRecord, nil, func() int {
1803 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1807 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1808 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1809 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1812 // Used by the TestStdoutWithWrongPath*()
1813 func (s *TestSuite) stdoutErrorRunHelper(c *C, record string, fn func() int) (*ArvTestClient, *ContainerRunner, error) {
1814 err := json.Unmarshal([]byte(record), &s.api.Container)
1815 c.Assert(err, IsNil)
1816 s.executor.runFunc = fn
1817 s.runner.RunArvMount = (&ArvMountCmdLine{}).ArvMountTest
1818 s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
1819 return s.api, &KeepTestClient{}, nil, nil
1821 return s.api, s.runner, s.runner.Run()
1824 func (s *TestSuite) TestStdoutWithWrongPath(c *C) {
1825 _, _, err := s.stdoutErrorRunHelper(c, `{
1826 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "file", "path":"/tmpa.out"} },
1827 "output_path": "/tmp",
1829 }`, func() int { return 0 })
1830 c.Check(err, ErrorMatches, ".*Stdout path does not start with OutputPath.*")
1833 func (s *TestSuite) TestStdoutWithWrongKindTmp(c *C) {
1834 _, _, err := s.stdoutErrorRunHelper(c, `{
1835 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "tmp", "path":"/tmp/a.out"} },
1836 "output_path": "/tmp",
1838 }`, func() int { return 0 })
1839 c.Check(err, ErrorMatches, ".*unsupported mount kind 'tmp' for stdout.*")
1842 func (s *TestSuite) TestStdoutWithWrongKindCollection(c *C) {
1843 _, _, err := s.stdoutErrorRunHelper(c, `{
1844 "mounts": {"/tmp": {"kind": "tmp"}, "stdout": {"kind": "collection", "path":"/tmp/a.out"} },
1845 "output_path": "/tmp",
1847 }`, func() int { return 0 })
1848 c.Check(err, ErrorMatches, ".*unsupported mount kind 'collection' for stdout.*")
1851 func (s *TestSuite) TestFullRunWithAPI(c *C) {
1852 s.fullRunHelper(c, `{
1853 "command": ["/bin/sh", "-c", "true $ARVADOS_API_HOST"],
1854 "container_image": "`+arvadostest.DockerImage112PDH+`",
1857 "mounts": {"/tmp": {"kind": "tmp"} },
1858 "output_path": "/tmp",
1860 "runtime_constraints": {"API": true},
1862 }`, nil, func() int {
1863 c.Check(s.executor.created.Env["ARVADOS_API_HOST"], Equals, os.Getenv("ARVADOS_API_HOST"))
1866 c.Check(s.api.CalledWith("container.exit_code", 3), NotNil)
1867 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1868 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*status code 3\n.*`)
1871 func (s *TestSuite) TestFullRunSetOutput(c *C) {
1872 defer os.Setenv("ARVADOS_API_HOST", os.Getenv("ARVADOS_API_HOST"))
1873 os.Setenv("ARVADOS_API_HOST", "test.arvados.org")
1874 s.fullRunHelper(c, `{
1875 "command": ["/bin/sh", "-c", "echo $ARVADOS_API_HOST"],
1876 "container_image": "`+arvadostest.DockerImage112PDH+`",
1879 "mounts": {"/tmp": {"kind": "tmp"} },
1880 "output_path": "/tmp",
1882 "runtime_constraints": {"API": true},
1884 }`, nil, func() int {
1885 s.api.Container.Output = arvadostest.DockerImage112PDH
1889 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1890 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1891 c.Check(s.api.CalledWith("container.output", arvadostest.DockerImage112PDH), NotNil)
1894 func (s *TestSuite) TestArvMountRuntimeStatusWarning(c *C) {
1895 s.runner.RunArvMount = func([]string, string) (*exec.Cmd, error) {
1896 os.Mkdir(s.runner.ArvMountPoint+"/by_id", 0666)
1897 ioutil.WriteFile(s.runner.ArvMountPoint+"/by_id/README", nil, 0666)
1898 return s.runner.ArvMountCmd([]string{"bash", "-c", "echo >&2 Test: Keep write error: I am a teapot; sleep 3"}, "")
1900 s.executor.runFunc = func() int {
1901 time.Sleep(time.Second)
1905 "command": ["sleep", "1"],
1906 "container_image": "` + arvadostest.DockerImage112PDH + `",
1909 "mounts": {"/tmp": {"kind": "tmp"} },
1910 "output_path": "/tmp",
1912 "runtime_constraints": {"API": true},
1915 err := json.Unmarshal([]byte(record), &s.api.Container)
1916 c.Assert(err, IsNil)
1917 err = s.runner.Run()
1918 c.Assert(err, IsNil)
1919 c.Check(s.api.CalledWith("container.exit_code", 137), NotNil)
1920 c.Check(s.api.CalledWith("container.runtime_status.warning", "arv-mount: Keep write error"), NotNil)
1921 c.Check(s.api.CalledWith("container.runtime_status.warningDetail", "Test: Keep write error: I am a teapot"), NotNil)
1922 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1923 c.Check(s.api.Logs["crunch-run"].String(), Matches, `(?ms).*Container exited with status code 137 \(signal 9, SIGKILL\).*`)
1926 func (s *TestSuite) TestStdoutWithExcludeFromOutputMountPointUnderOutputDir(c *C) {
1928 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1929 "container_image": "` + arvadostest.DockerImage112PDH + `",
1931 "environment": {"FROBIZ": "bilbo"},
1933 "/tmp": {"kind": "tmp"},
1934 "/tmp/foo": {"kind": "collection",
1935 "portable_data_hash": "a3e8f74c6f101eae01fa08bfb4e49b3a+54",
1936 "exclude_from_output": true
1938 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1940 "output_path": "/tmp",
1942 "runtime_constraints": {},
1946 extraMounts := []string{"a3e8f74c6f101eae01fa08bfb4e49b3a+54"}
1948 s.fullRunHelper(c, helperRecord, extraMounts, func() int {
1949 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1953 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
1954 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
1955 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", "./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out\n"), NotNil)
1958 func (s *TestSuite) TestStdoutWithMultipleMountPointsUnderOutputDir(c *C) {
1960 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
1961 "container_image": "` + arvadostest.DockerImage112PDH + `",
1963 "environment": {"FROBIZ": "bilbo"},
1965 "/tmp": {"kind": "tmp"},
1966 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/file2_in_main.txt"},
1967 "/tmp/foo/sub1": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1"},
1968 "/tmp/foo/sub1file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/file2_in_subdir1.txt"},
1969 "/tmp/foo/baz/sub2file2": {"kind": "collection", "portable_data_hash": "a0def87f80dd594d4675809e83bd4f15+367", "path":"/subdir1/subdir2/file2_in_subdir2.txt"},
1970 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
1972 "output_path": "/tmp",
1974 "runtime_constraints": {},
1976 "uuid": "zzzzz-dz642-202301130848001"
1979 extraMounts := []string{
1980 "a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt",
1981 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
1982 "a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt",
1985 api, _, realtemp := s.fullRunHelper(c, helperRecord, extraMounts, func() int {
1986 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
1990 c.Check(s.executor.created.BindMounts, DeepEquals, map[string]bindmount{
1991 "/tmp": {realtemp + "/tmp1", false},
1992 "/tmp/foo/bar": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/file2_in_main.txt", true},
1993 "/tmp/foo/baz/sub2file2": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/subdir2/file2_in_subdir2.txt", true},
1994 "/tmp/foo/sub1": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1", true},
1995 "/tmp/foo/sub1file2": {s.keepmount + "/by_id/a0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt", true},
1998 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
1999 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
2000 output_count := uint(0)
2001 for _, v := range s.runner.ContainerArvClient.(*ArvTestClient).Content {
2002 if v["collection"] == nil {
2005 collection := v["collection"].(arvadosclient.Dict)
2006 if collection["name"].(string) != "output for zzzzz-dz642-202301130848001" {
2009 c.Check(v["ensure_unique_name"], Equals, true)
2010 c.Check(collection["manifest_text"].(string), Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
2011 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 9:18:bar 36:18:sub1file2
2012 ./foo/baz 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 9:18:sub2file2
2013 ./foo/sub1 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396cabcdefghij6419876543234@569fa8c4 0:9:file1_in_subdir1.txt 9:18:file2_in_subdir1.txt
2014 ./foo/sub1/subdir2 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0bcdefghijk544332211@569fa8c5 0:9:file1_in_subdir2.txt 9:18:file2_in_subdir2.txt
2018 c.Check(output_count, Not(Equals), uint(0))
2021 func (s *TestSuite) TestStdoutWithMountPointsUnderOutputDirDenormalizedManifest(c *C) {
2023 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
2024 "container_image": "` + arvadostest.DockerImage112PDH + `",
2026 "environment": {"FROBIZ": "bilbo"},
2028 "/tmp": {"kind": "tmp"},
2029 "/tmp/foo/bar": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/subdir1/file2_in_subdir1.txt"},
2030 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
2032 "output_path": "/tmp",
2034 "runtime_constraints": {},
2036 "uuid": "zzzzz-dz642-202301130848002"
2039 extraMounts := []string{
2040 "b0def87f80dd594d4675809e83bd4f15+367/subdir1/file2_in_subdir1.txt",
2043 s.fullRunHelper(c, helperRecord, extraMounts, func() int {
2044 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
2048 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2049 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2050 output_count := uint(0)
2051 for _, v := range s.runner.ContainerArvClient.(*ArvTestClient).Content {
2052 if v["collection"] == nil {
2055 collection := v["collection"].(arvadosclient.Dict)
2056 if collection["name"].(string) != "output for zzzzz-dz642-202301130848002" {
2059 c.Check(collection["manifest_text"].(string), Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
2060 ./foo 3e426d509afffb85e06c4c96a7c15e91+27+Aa124ac75e5168396c73c0abcdefgh11234567890@569fa8c3 10:17:bar
2064 c.Check(output_count, Not(Equals), uint(0))
2067 func (s *TestSuite) TestOutputError(c *C) {
2069 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
2070 "container_image": "` + arvadostest.DockerImage112PDH + `",
2072 "environment": {"FROBIZ": "bilbo"},
2074 "/tmp": {"kind": "tmp"}
2076 "output_path": "/tmp",
2078 "runtime_constraints": {},
2081 s.fullRunHelper(c, helperRecord, nil, func() int {
2082 os.Symlink("/etc/hosts", s.runner.HostOutputDir+"/baz")
2086 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
2089 func (s *TestSuite) TestStdinCollectionMountPoint(c *C) {
2091 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
2092 "container_image": "` + arvadostest.DockerImage112PDH + `",
2094 "environment": {"FROBIZ": "bilbo"},
2096 "/tmp": {"kind": "tmp"},
2097 "stdin": {"kind": "collection", "portable_data_hash": "b0def87f80dd594d4675809e83bd4f15+367", "path": "/file1_in_main.txt"},
2098 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
2100 "output_path": "/tmp",
2102 "runtime_constraints": {},
2106 extraMounts := []string{
2107 "b0def87f80dd594d4675809e83bd4f15+367/file1_in_main.txt",
2110 api, _, _ := s.fullRunHelper(c, helperRecord, extraMounts, func() int {
2111 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
2115 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
2116 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
2117 for _, v := range api.Content {
2118 if v["collection"] != nil {
2119 collection := v["collection"].(arvadosclient.Dict)
2120 if strings.Index(collection["name"].(string), "output") == 0 {
2121 manifest := collection["manifest_text"].(string)
2122 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
2129 func (s *TestSuite) TestStdinJsonMountPoint(c *C) {
2131 "command": ["/bin/sh", "-c", "echo $FROBIZ"],
2132 "container_image": "` + arvadostest.DockerImage112PDH + `",
2134 "environment": {"FROBIZ": "bilbo"},
2136 "/tmp": {"kind": "tmp"},
2137 "stdin": {"kind": "json", "content": "foo"},
2138 "stdout": {"kind": "file", "path": "/tmp/a/b/c.out"}
2140 "output_path": "/tmp",
2142 "runtime_constraints": {},
2146 api, _, _ := s.fullRunHelper(c, helperRecord, nil, func() int {
2147 fmt.Fprintln(s.executor.created.Stdout, s.executor.created.Env["FROBIZ"])
2151 c.Check(api.CalledWith("container.exit_code", 0), NotNil)
2152 c.Check(api.CalledWith("container.state", "Complete"), NotNil)
2153 for _, v := range api.Content {
2154 if v["collection"] != nil {
2155 collection := v["collection"].(arvadosclient.Dict)
2156 if strings.Index(collection["name"].(string), "output") == 0 {
2157 manifest := collection["manifest_text"].(string)
2158 c.Check(manifest, Equals, `./a/b 307372fa8fd5c146b22ae7a45b49bc31+6 0:6:c.out
2165 func (s *TestSuite) TestStderrMount(c *C) {
2166 api, cr, _ := s.fullRunHelper(c, `{
2167 "command": ["/bin/sh", "-c", "echo hello;exit 1"],
2168 "container_image": "`+arvadostest.DockerImage112PDH+`",
2171 "mounts": {"/tmp": {"kind": "tmp"},
2172 "stdout": {"kind": "file", "path": "/tmp/a/out.txt"},
2173 "stderr": {"kind": "file", "path": "/tmp/b/err.txt"}},
2174 "output_path": "/tmp",
2176 "runtime_constraints": {},
2178 }`, nil, func() int {
2179 fmt.Fprintln(s.executor.created.Stdout, "hello")
2180 fmt.Fprintln(s.executor.created.Stderr, "oops")
2184 final := api.CalledWith("container.state", "Complete")
2185 c.Assert(final, NotNil)
2186 c.Check(final["container"].(arvadosclient.Dict)["exit_code"], Equals, 1)
2187 c.Check(final["container"].(arvadosclient.Dict)["log"], NotNil)
2189 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)
2192 func (s *TestSuite) TestNumberRoundTrip(c *C) {
2193 s.api.callraw = true
2194 err := s.runner.fetchContainerRecord()
2195 c.Assert(err, IsNil)
2196 jsondata, err := json.Marshal(s.runner.Container.Mounts["/json"].Content)
2197 c.Logf("%#v", s.runner.Container)
2199 c.Check(string(jsondata), Equals, `{"number":123456789123456789}`)
2202 func (s *TestSuite) TestFullBrokenDocker(c *C) {
2204 for _, setup := range []func(){
2206 c.Log("// waitErr = ocl runtime error")
2207 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\\\"\""`)
2208 nextState = "Cancelled"
2211 c.Log("// loadErr = cannot connect")
2212 s.executor.loadErr = errors.New("Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?")
2213 s.runner.brokenNodeHook = c.MkDir() + "/broken-node-hook"
2214 err := ioutil.WriteFile(s.runner.brokenNodeHook, []byte("#!/bin/sh\nexec echo killme\n"), 0700)
2215 c.Assert(err, IsNil)
2216 nextState = "Queued"
2221 s.fullRunHelper(c, `{
2222 "command": ["echo", "hello world"],
2223 "container_image": "`+arvadostest.DockerImage112PDH+`",
2226 "mounts": {"/tmp": {"kind": "tmp"} },
2227 "output_path": "/tmp",
2229 "runtime_constraints": {},
2231 }`, nil, func() int { return 0 })
2232 c.Check(s.api.CalledWith("container.state", nextState), NotNil)
2233 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*unable to run containers.*")
2234 if s.runner.brokenNodeHook != "" {
2235 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Running broken node hook.*")
2236 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*killme.*")
2237 c.Check(s.api.Logs["crunch-run"].String(), Not(Matches), "(?ms).*Writing /var/lock/crunch-run-broken to mark node as broken.*")
2239 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Writing /var/lock/crunch-run-broken to mark node as broken.*")
2244 func (s *TestSuite) TestBadCommand(c *C) {
2245 for _, startError := range []string{
2246 `panic: standard_init_linux.go:175: exec user process caused "no such file or directory"`,
2247 `Error response from daemon: Cannot start container 41f26cbc43bcc1280f4323efb1830a394ba8660c9d1c2b564ba42bf7f7694845: [8] System error: no such file or directory`,
2248 `Error response from daemon: Cannot start container 58099cd76c834f3dc2a4fb76c8028f049ae6d4fdf0ec373e1f2cfea030670c2d: [8] System error: exec: "foobar": executable file not found in $PATH`,
2251 s.executor.startErr = errors.New(startError)
2252 s.fullRunHelper(c, `{
2253 "command": ["echo", "hello world"],
2254 "container_image": "`+arvadostest.DockerImage112PDH+`",
2257 "mounts": {"/tmp": {"kind": "tmp"} },
2258 "output_path": "/tmp",
2260 "runtime_constraints": {},
2262 }`, nil, func() int { return 0 })
2263 c.Check(s.api.CalledWith("container.state", "Cancelled"), NotNil)
2264 c.Check(s.api.Logs["crunch-run"].String(), Matches, "(?ms).*Possible causes:.*is missing.*")
2268 func (s *TestSuite) TestSecretTextMountPoint(c *C) {
2270 "command": ["true"],
2271 "container_image": "` + arvadostest.DockerImage112PDH + `",
2274 "/tmp": {"kind": "tmp"},
2275 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2279 "output_path": "/tmp",
2281 "runtime_constraints": {},
2285 s.fullRunHelper(c, helperRecord, nil, func() int {
2286 content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf")
2288 c.Check(string(content), Equals, "mypassword")
2292 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2293 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2294 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". 34819d7beeabb9260a5c854bc85b3e44+10 0:10:secret.conf\n"), NotNil)
2295 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ""), IsNil)
2297 // under secret mounts, not captured in output
2299 "command": ["true"],
2300 "container_image": "` + arvadostest.DockerImage112PDH + `",
2303 "/tmp": {"kind": "tmp"}
2306 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2308 "output_path": "/tmp",
2310 "runtime_constraints": {},
2315 s.fullRunHelper(c, helperRecord, nil, func() int {
2316 content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf")
2318 c.Check(string(content), Equals, "mypassword")
2322 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2323 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2324 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". 34819d7beeabb9260a5c854bc85b3e44+10 0:10:secret.conf\n"), IsNil)
2325 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ""), NotNil)
2327 // under secret mounts, output dir is a collection, not captured in output
2329 "command": ["true"],
2330 "container_image": "` + arvadostest.DockerImage112PDH + `",
2333 "/tmp": {"kind": "collection", "writable": true}
2336 "/tmp/secret.conf": {"kind": "text", "content": "mypassword"}
2338 "output_path": "/tmp",
2340 "runtime_constraints": {},
2345 _, _, realtemp := s.fullRunHelper(c, helperRecord, nil, func() int {
2346 // secret.conf should be provisioned as a separate
2347 // bind mount, i.e., it should not appear in the
2348 // (fake) fuse filesystem as viewed from the host.
2349 content, err := ioutil.ReadFile(s.runner.HostOutputDir + "/secret.conf")
2350 if !c.Check(errors.Is(err, os.ErrNotExist), Equals, true) {
2351 c.Logf("secret.conf: content %q, err %#v", content, err)
2353 err = ioutil.WriteFile(s.runner.HostOutputDir+"/.arvados#collection", []byte(`{"manifest_text":". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n"}`), 0700)
2358 content, err := ioutil.ReadFile(realtemp + "/text1/mountdata.text")
2360 c.Check(string(content), Equals, "mypassword")
2361 c.Check(s.executor.created.BindMounts["/tmp/secret.conf"], DeepEquals, bindmount{realtemp + "/text1/mountdata.text", true})
2362 c.Check(s.api.CalledWith("container.exit_code", 0), NotNil)
2363 c.Check(s.api.CalledWith("container.state", "Complete"), NotNil)
2364 c.Check(s.runner.ContainerArvClient.(*ArvTestClient).CalledWith("collection.manifest_text", ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo.txt\n"), NotNil)
2367 func (s *TestSuite) TestCalculateCost(c *C) {
2368 defer func(s string) { lockdir = s }(lockdir)
2372 cr.costStartTime = now.Add(-time.Hour)
2373 var logbuf bytes.Buffer
2374 cr.CrunchLog.Immediate = log.New(&logbuf, "", 0)
2376 // if there's no InstanceType env var, cost is calculated as 0
2377 os.Unsetenv("InstanceType")
2378 cost := cr.calculateCost(now)
2379 c.Check(cost, Equals, 0.0)
2381 // with InstanceType env var and loadPrices() hasn't run (or
2382 // hasn't found any data), cost is calculated based on
2383 // InstanceType env var
2384 os.Setenv("InstanceType", `{"Price":1.2}`)
2385 defer os.Unsetenv("InstanceType")
2386 cost = cr.calculateCost(now)
2387 c.Check(cost, Equals, 1.2)
2389 // first update tells us the spot price was $1/h until 30
2390 // minutes ago when it increased to $2/h
2391 j, err := json.Marshal([]cloud.InstancePrice{
2392 {StartTime: now.Add(-4 * time.Hour), Price: 1.0},
2393 {StartTime: now.Add(-time.Hour / 2), Price: 2.0},
2395 c.Assert(err, IsNil)
2396 os.WriteFile(lockdir+"/"+pricesfile, j, 0777)
2398 cost = cr.calculateCost(now)
2399 c.Check(cost, Equals, 1.5)
2401 // next update (via --list + SIGUSR2) tells us the spot price
2402 // increased to $3/h 15 minutes ago
2403 j, err = json.Marshal([]cloud.InstancePrice{
2404 {StartTime: now.Add(-time.Hour / 3), Price: 2.0}, // dup of -time.Hour/2 price
2405 {StartTime: now.Add(-time.Hour / 4), Price: 3.0},
2407 c.Assert(err, IsNil)
2408 os.WriteFile(lockdir+"/"+pricesfile, j, 0777)
2410 cost = cr.calculateCost(now)
2411 c.Check(cost, Equals, 1.0/2+2.0/4+3.0/4)
2413 cost = cr.calculateCost(now.Add(-time.Hour / 2))
2414 c.Check(cost, Equals, 0.5)
2416 c.Logf("%s", logbuf.String())
2417 c.Check(logbuf.String(), Matches, `(?ms).*Instance price changed to 1\.00 at 20.* changed to 2\.00 .* changed to 3\.00 .*`)
2418 c.Check(logbuf.String(), Not(Matches), `(?ms).*changed to 2\.00 .* changed to 2\.00 .*`)
2421 func (s *TestSuite) TestSIGUSR2CostUpdate(c *C) {
2424 pricesJSON, err := json.Marshal([]cloud.InstancePrice{
2425 {StartTime: now.Add(-4 * time.Hour), Price: 2.4},
2426 {StartTime: now.Add(-2 * time.Hour), Price: 2.6},
2428 c.Assert(err, IsNil)
2430 os.Setenv("InstanceType", `{"Price":2.2}`)
2431 defer os.Unsetenv("InstanceType")
2432 defer func(s string) { lockdir = s }(lockdir)
2435 // We can't use s.api.CalledWith because timing differences will yield
2436 // different cost values across runs. getCostUpdate iterates over API
2437 // calls until it finds one that sets the cost, then writes that value
2438 // to the next index of costUpdates.
2439 deadline := now.Add(time.Second)
2440 costUpdates := make([]float64, 2)
2443 getCostUpdate := func() {
2444 for ; time.Now().Before(deadline); time.Sleep(time.Second / 10) {
2445 for apiIndex < len(s.api.Content) {
2446 update := s.api.Content[apiIndex]
2450 if update, ok = update["container"].(arvadosclient.Dict); !ok {
2453 if cost, ok = update["cost"].(float64); !ok {
2456 c.Logf("API call #%d updates cost to %v", apiIndex-1, cost)
2457 costUpdates[costIndex] = cost
2464 s.fullRunHelper(c, `{
2465 "command": ["true"],
2466 "container_image": "`+arvadostest.DockerImage112PDH+`",
2469 "mounts": {"/tmp": {"kind": "tmp"} },
2470 "output_path": "/tmp",
2472 "runtime_constraints": {},
2474 "uuid": "zzzzz-dz642-20230320101530a"
2475 }`, nil, func() int {
2476 s.runner.costStartTime = now.Add(-3 * time.Hour)
2477 err := syscall.Kill(pid, syscall.SIGUSR2)
2478 c.Check(err, IsNil, Commentf("error sending first SIGUSR2 to runner"))
2481 err = os.WriteFile(path.Join(lockdir, pricesfile), pricesJSON, 0o700)
2482 c.Check(err, IsNil, Commentf("error writing JSON prices file"))
2483 err = syscall.Kill(pid, syscall.SIGUSR2)
2484 c.Check(err, IsNil, Commentf("error sending second SIGUSR2 to runner"))
2489 // Comparing with format strings makes it easy to ignore minor variations
2490 // in cost across runs while keeping diagnostics pretty.
2491 c.Check(fmt.Sprintf("%.3f", costUpdates[0]), Equals, "6.600")
2492 c.Check(fmt.Sprintf("%.3f", costUpdates[1]), Equals, "7.600")
2495 type FakeProcess struct {
2499 func (fp FakeProcess) CmdlineSlice() ([]string, error) {
2500 return fp.cmdLine, nil