X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3fa6aa4043286ad61e5f29c136d3cc2942e8750d..99a1c26447c7cc06f27ce9b79690cdb64752f2ca:/lib/controller/integration_test.go diff --git a/lib/controller/integration_test.go b/lib/controller/integration_test.go index 7bf739f902..53e6a90b8f 100644 --- a/lib/controller/integration_test.go +++ b/lib/controller/integration_test.go @@ -72,6 +72,8 @@ func (s *IntegrationSuite) SetUpSuite(c *check.C) { Insecure: true SystemLogs: Format: text + API: + MaxConcurrentRequests: 128 Containers: CloudVMs: Enable: true @@ -499,6 +501,7 @@ func (s *IntegrationSuite) TestCreateContainerRequestWithFedToken(c *check.C) { req.Header.Set("Authorization", "OAuth2 "+ac2.AuthToken) resp, err = arvados.InsecureHTTPClient.Do(req) c.Assert(err, check.IsNil) + defer resp.Body.Close() err = json.NewDecoder(resp.Body).Decode(&cr) c.Check(err, check.IsNil) c.Check(cr.UUID, check.Matches, "z2222-.*") @@ -536,8 +539,10 @@ func (s *IntegrationSuite) TestCreateContainerRequestWithBadToken(c *check.C) { c.Assert(err, check.IsNil) req.Header.Set("Content-Type", "application/json") resp, err := ac1.Do(req) - c.Assert(err, check.IsNil) - c.Assert(resp.StatusCode, check.Equals, tt.expectedCode) + if c.Check(err, check.IsNil) { + c.Assert(resp.StatusCode, check.Equals, tt.expectedCode) + resp.Body.Close() + } } } @@ -605,9 +610,11 @@ func (s *IntegrationSuite) TestRequestIDHeader(c *check.C) { var jresp httpserver.ErrorResponse err := json.NewDecoder(resp.Body).Decode(&jresp) c.Check(err, check.IsNil) - c.Assert(jresp.Errors, check.HasLen, 1) - c.Check(jresp.Errors[0], check.Matches, `.*\(`+respHdr+`\).*`) + if c.Check(jresp.Errors, check.HasLen, 1) { + c.Check(jresp.Errors[0], check.Matches, `.*\(`+respHdr+`\).*`) + } } + resp.Body.Close() } } @@ -964,8 +971,8 @@ func (s *IntegrationSuite) TestSetupUserWithVM(c *check.C) { "hostname": "example", }, }) + c.Assert(err, check.IsNil) c.Check(outVM.UUID[0:5], check.Equals, "z3333") - c.Check(err, check.IsNil) // Make sure z3333 user list is up to date _, err = conn3.UserList(rootctx3, arvados.ListOptions{Limit: 1000}) @@ -1126,14 +1133,14 @@ func (s *IntegrationSuite) TestForwardRuntimeTokenToLoginCluster(c *check.C) { } func (s *IntegrationSuite) TestRunTrivialContainer(c *check.C) { - outcoll := s.runContainer(c, "z1111", map[string]interface{}{ + 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}, + "runtime_constraints": arvados.RuntimeConstraints{RAM: 100000000, VCPUs: 1, KeepCacheRAM: 1 << 26}, "priority": 1, "state": arvados.ContainerRequestStateCommitted, }, 0) @@ -1141,22 +1148,60 @@ func (s *IntegrationSuite) TestRunTrivialContainer(c *check.C) { c.Check(outcoll.PortableDataHash, check.Equals, "8fa5dee9231a724d7cf377c5a2f4907c+65") } -func (s *IntegrationSuite) runContainer(c *check.C, clusterID string, ctrSpec map[string]interface{}, expectExitCode int) arvados.Collection { +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) - _, ac, kc, _ := s.super.UserClients(clusterID, rootctx, c, conn, s.oidcprovider.AuthEmail, true) + 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 done] %s", out) + 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) - c.Logf("[arv-keepdocker env] %q", akd.Env) out, err = akd.CombinedOutput() - c.Logf("[arv-keepdocker done] %s", out) + c.Logf("[arv-keepdocker output]\n%s", out) c.Check(err, check.IsNil) var cr arvados.ContainerRequest @@ -1165,7 +1210,7 @@ func (s *IntegrationSuite) runContainer(c *check.C, clusterID string, ctrSpec ma }) c.Assert(err, check.IsNil) - showlogs := func(collectionID string) { + 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) @@ -1183,42 +1228,74 @@ func (s *IntegrationSuite) runContainer(c *check.C, clusterID string, ctrSpec ma c.Logf("=== %s\n%s\n", path, buf) return nil }) + return cfs + } + + checkwebdavlogs := func(cr arvados.ContainerRequest) { + req, err := http.NewRequest("OPTIONS", "https://"+ac.APIHost+"/arvados/v1/container_requests/"+cr.UUID+"/log/"+cr.ContainerUUID+"/", nil) + c.Assert(err, check.IsNil) + req.Header.Set("Origin", "http://example.example") + resp, err := ac.Do(req) + c.Assert(err, check.IsNil) + c.Check(resp.StatusCode, check.Equals, http.StatusOK) + // Check for duplicate headers -- must use Header[], not Header.Get() + c.Check(resp.Header["Access-Control-Allow-Origin"], check.DeepEquals, []string{"*"}) } var ctr arvados.Container var lastState arvados.ContainerState + var status, lastStatus arvados.ContainerStatus + var allStatus string + checkstatus := func() { + err := ac.RequestAndDecode(&status, "GET", "/arvados/v1/container_requests/"+cr.UUID+"/container_status", nil, nil) + c.Assert(err, check.IsNil) + if status != lastStatus { + c.Logf("container status: %s, %s", status.State, status.SchedulingStatus) + allStatus += fmt.Sprintf("%s, %s\n", status.State, status.SchedulingStatus) + lastStatus = status + } + } deadline := time.Now().Add(time.Minute) -wait: - for ; ; lastState = ctr.State { - err = ac.RequestAndDecode(&ctr, "GET", "/arvados/v1/containers/"+cr.ContainerUUID, nil, nil) + for cr.State != arvados.ContainerRequestStateFinal || (lastStatus.State != arvados.ContainerStateComplete && lastStatus.State != arvados.ContainerStateCancelled) { + err = ac.RequestAndDecode(&cr, "GET", "/arvados/v1/container_requests/"+cr.UUID, nil, nil) c.Assert(err, check.IsNil) - switch ctr.State { - case lastState: + checkstatus() + 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 request state is %q", cr.State) - showlogs(ctr.Log) + c.Errorf("timed out, container state is %q", cr.State) + if ctr.Log == "" { + c.Logf("=== NO LOG COLLECTION saved for container") + } else { + showlogs(ctr.Log) + } c.FailNow() } time.Sleep(time.Second / 2) - case arvados.ContainerStateComplete: - break wait - case arvados.ContainerStateQueued, arvados.ContainerStateLocked, arvados.ContainerStateRunning: - c.Logf("container state changed to %q", ctr.State) - default: - c.Errorf("unexpected container state %q", ctr.State) - showlogs(ctr.Log) - c.FailNow() } } - c.Check(ctr.ExitCode, check.Equals, 0) - - err = ac.RequestAndDecode(&cr, "GET", "/arvados/v1/container_requests/"+cr.UUID, nil, nil) - c.Assert(err, check.IsNil) - - showlogs(cr.LogUUID) - - var outcoll arvados.Collection - err = ac.RequestAndDecode(&outcoll, "GET", "/arvados/v1/collections/"+cr.OutputUUID, nil, nil) - c.Assert(err, check.IsNil) - return outcoll + checkstatus() + 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) + c.Check(allStatus, check.Matches, `Queued, waiting for dispatch\n`+ + `(Queued, waiting.*\n)*`+ + `(Locked, waiting for dispatch\n)?`+ + `(Locked, waiting for new instance to be ready\n)?`+ + `(Locked, preparing runtime environment\n)?`+ + `(Running, \n)?`+ + `Complete, \n`) + } + logcfs = showlogs(cr.LogUUID) + checkwebdavlogs(cr) + return outcoll, logcfs }