X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/5e9787f914dd1a2f762ae7a653fe8dda36f8f555..db118cca358662e57a3dd0c1186dce1f0a62ca52:/lib/controller/integration_test.go diff --git a/lib/controller/integration_test.go b/lib/controller/integration_test.go index 44be17c77f..c532efa0b6 100644 --- a/lib/controller/integration_test.go +++ b/lib/controller/integration_test.go @@ -11,6 +11,7 @@ import ( "encoding/json" "fmt" "io" + "io/fs" "io/ioutil" "math" "net" @@ -71,6 +72,18 @@ func (s *IntegrationSuite) SetUpSuite(c *check.C) { Insecure: true SystemLogs: Format: text + Containers: + CloudVMs: + Enable: true + Driver: loopback + BootProbeCommand: "rm -f /var/lock/crunch-run-broken" + ProbeInterval: 1s + PollInterval: 5s + SyncInterval: 10s + TimeoutIdle: 1s + TimeoutBooting: 2s + RuntimeEngine: singularity + CrunchRunArgumentsList: ["--broken-node-hook", "true"] RemoteClusters: z1111: Host: ` + hostport["z1111"] + ` @@ -1111,3 +1124,135 @@ func (s *IntegrationSuite) TestForwardRuntimeTokenToLoginCluster(c *check.C) { c.Check(err, check.ErrorMatches, `request failed: .* 401 Unauthorized: cannot use a locally issued token to forward a request to our login cluster \(z1111\)`) c.Check(err, check.Not(check.ErrorMatches), `(?ms).*127\.0\.0\.11.*`) } + +func (s *IntegrationSuite) TestRunTrivialContainer(c *check.C) { + outcoll, _ := s.runContainer(c, "z1111", "", map[string]interface{}{ + "command": []string{"sh", "-c", "touch \"/out/hello world\" /out/ohai"}, + "container_image": "busybox:uclibc", + "cwd": "/tmp", + "environment": map[string]string{}, + "mounts": map[string]arvados.Mount{"/out": {Kind: "tmp", Capacity: 10000}}, + "output_path": "/out", + "runtime_constraints": arvados.RuntimeConstraints{RAM: 100000000, VCPUs: 1, KeepCacheRAM: 1 << 26}, + "priority": 1, + "state": arvados.ContainerRequestStateCommitted, + }, 0) + c.Check(outcoll.ManifestText, check.Matches, `\. d41d8.* 0:0:hello\\040world 0:0:ohai\n`) + c.Check(outcoll.PortableDataHash, check.Equals, "8fa5dee9231a724d7cf377c5a2f4907c+65") +} + +func (s *IntegrationSuite) TestContainerInputOnDifferentCluster(c *check.C) { + conn := s.super.Conn("z1111") + rootctx, _, _ := s.super.RootClients("z1111") + userctx, ac, _, _ := s.super.UserClients("z1111", rootctx, c, conn, s.oidcprovider.AuthEmail, true) + z1coll, err := conn.CollectionCreate(userctx, arvados.CreateOptions{Attrs: map[string]interface{}{ + "manifest_text": ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:ocelot\n", + }}) + c.Assert(err, check.IsNil) + + outcoll, logcfs := s.runContainer(c, "z2222", ac.AuthToken, map[string]interface{}{ + "command": []string{"ls", "/in"}, + "container_image": "busybox:uclibc", + "cwd": "/tmp", + "environment": map[string]string{}, + "mounts": map[string]arvados.Mount{ + "/in": {Kind: "collection", PortableDataHash: z1coll.PortableDataHash}, + "/out": {Kind: "tmp", Capacity: 10000}, + }, + "output_path": "/out", + "runtime_constraints": arvados.RuntimeConstraints{RAM: 100000000, VCPUs: 1, KeepCacheRAM: 1 << 26}, + "priority": 1, + "state": arvados.ContainerRequestStateCommitted, + "container_count_max": 1, + }, -1) + if outcoll.UUID == "" { + arvmountlog, err := fs.ReadFile(arvados.FS(logcfs), "/arv-mount.txt") + c.Check(err, check.IsNil) + c.Check(string(arvmountlog), check.Matches, `(?ms).*cannot use a locally issued token to forward a request to our login cluster \(z1111\).*`) + c.Skip("this use case is not supported yet") + } + stdout, err := fs.ReadFile(arvados.FS(logcfs), "/stdout.txt") + c.Check(err, check.IsNil) + c.Check(string(stdout), check.Equals, "ocelot\n") +} + +func (s *IntegrationSuite) runContainer(c *check.C, clusterID string, token string, ctrSpec map[string]interface{}, expectExitCode int) (outcoll arvados.Collection, logcfs arvados.CollectionFileSystem) { + conn := s.super.Conn(clusterID) + rootctx, _, _ := s.super.RootClients(clusterID) + if token == "" { + _, ac, _, _ := s.super.UserClients(clusterID, rootctx, c, conn, s.oidcprovider.AuthEmail, true) + token = ac.AuthToken + } + _, ac, kc := s.super.ClientsWithToken(clusterID, token) + + c.Log("[docker load]") + out, err := exec.Command("docker", "load", "--input", arvadostest.BusyboxDockerImage(c)).CombinedOutput() + c.Logf("[docker load output] %s", out) + c.Check(err, check.IsNil) + + c.Log("[arv-keepdocker]") + akd := exec.Command("arv-keepdocker", "--no-resume", "busybox:uclibc") + akd.Env = append(os.Environ(), "ARVADOS_API_HOST="+ac.APIHost, "ARVADOS_API_HOST_INSECURE=1", "ARVADOS_API_TOKEN="+ac.AuthToken) + out, err = akd.CombinedOutput() + c.Logf("[arv-keepdocker output]\n%s", out) + c.Check(err, check.IsNil) + + var cr arvados.ContainerRequest + err = ac.RequestAndDecode(&cr, "POST", "/arvados/v1/container_requests", nil, map[string]interface{}{ + "container_request": ctrSpec, + }) + c.Assert(err, check.IsNil) + + showlogs := func(collectionID string) arvados.CollectionFileSystem { + var logcoll arvados.Collection + err = ac.RequestAndDecode(&logcoll, "GET", "/arvados/v1/collections/"+collectionID, nil, nil) + c.Assert(err, check.IsNil) + cfs, err := logcoll.FileSystem(ac, kc) + c.Assert(err, check.IsNil) + fs.WalkDir(arvados.FS(cfs), "/", func(path string, d fs.DirEntry, err error) error { + if d.IsDir() || strings.HasPrefix(path, "/log for container") { + return nil + } + f, err := cfs.Open(path) + c.Assert(err, check.IsNil) + defer f.Close() + buf, err := ioutil.ReadAll(f) + c.Assert(err, check.IsNil) + c.Logf("=== %s\n%s\n", path, buf) + return nil + }) + return cfs + } + + var ctr arvados.Container + var lastState arvados.ContainerState + deadline := time.Now().Add(time.Minute) + for cr.State != arvados.ContainerRequestStateFinal { + err = ac.RequestAndDecode(&cr, "GET", "/arvados/v1/container_requests/"+cr.UUID, nil, nil) + c.Assert(err, check.IsNil) + err = ac.RequestAndDecode(&ctr, "GET", "/arvados/v1/containers/"+cr.ContainerUUID, nil, nil) + if err != nil { + c.Logf("error getting container state: %s", err) + } else if ctr.State != lastState { + c.Logf("container state changed to %q", ctr.State) + lastState = ctr.State + } else { + if time.Now().After(deadline) { + c.Errorf("timed out, container state is %q", cr.State) + showlogs(ctr.Log) + c.FailNow() + } + time.Sleep(time.Second / 2) + } + } + c.Logf("cr.CumulativeCost == %f", cr.CumulativeCost) + c.Check(cr.CumulativeCost, check.Not(check.Equals), 0.0) + if expectExitCode >= 0 { + c.Check(ctr.State, check.Equals, arvados.ContainerStateComplete) + c.Check(ctr.ExitCode, check.Equals, expectExitCode) + err = ac.RequestAndDecode(&outcoll, "GET", "/arvados/v1/collections/"+cr.OutputUUID, nil, nil) + c.Assert(err, check.IsNil) + } + logcfs = showlogs(cr.LogUUID) + return outcoll, logcfs +}