X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/91d40ffe727119f7661e734f9535fd9005880e98..b1ed7c643f311605092991e01bcc3437130d6072:/lib/boot/helpers.go diff --git a/lib/boot/helpers.go b/lib/boot/helpers.go index 731fc56c83..77036e9340 100644 --- a/lib/boot/helpers.go +++ b/lib/boot/helpers.go @@ -9,73 +9,24 @@ import ( "net/url" "git.arvados.org/arvados.git/lib/controller/rpc" - "git.arvados.org/arvados.git/lib/service" "git.arvados.org/arvados.git/sdk/go/arvados" "git.arvados.org/arvados.git/sdk/go/arvadosclient" "git.arvados.org/arvados.git/sdk/go/auth" - "git.arvados.org/arvados.git/sdk/go/ctxlog" "git.arvados.org/arvados.git/sdk/go/keepclient" "gopkg.in/check.v1" ) -// TestCluster stores a working test cluster data -type TestCluster struct { - Super Supervisor - Config arvados.Config - ControllerURL *url.URL - ClusterID string -} - -type logger struct { - loggerfunc func(...interface{}) -} - -func (l logger) Log(args ...interface{}) { - l.loggerfunc(args) -} - -// NewTestCluster loads the provided configuration, and sets up a test cluster -// ready for being started. -func NewTestCluster(srcPath, clusterID string, cfg *arvados.Config, listenHost string, logWriter func(...interface{})) *TestCluster { - return &TestCluster{ - Super: Supervisor{ - SourcePath: srcPath, - ClusterType: "test", - ListenHost: listenHost, - ControllerAddr: ":0", - OwnTemporaryDatabase: true, - Stderr: &service.LogPrefixer{ - Writer: ctxlog.LogWriter(logWriter), - Prefix: []byte("[" + clusterID + "] ")}, - }, - Config: *cfg, - ClusterID: clusterID, - } -} - -// Start the test cluster. -func (tc *TestCluster) Start() { - tc.Super.Start(context.Background(), &tc.Config, "-") -} - -// WaitReady waits for all components to report healthy, and finishes setting -// up the TestCluster struct. -func (tc *TestCluster) WaitReady() bool { - au, ok := tc.Super.WaitReady() - if !ok { - return ok - } - u := url.URL(*au) - tc.ControllerURL = &u - return ok -} - // ClientsWithToken returns Context, Arvados.Client and keepclient structs // initialized to connect to the cluster with the supplied Arvados token. -func (tc *TestCluster) ClientsWithToken(token string) (context.Context, *arvados.Client, *keepclient.KeepClient) { - cl := tc.Config.Clusters[tc.ClusterID] - ctx := auth.NewContext(context.Background(), auth.NewCredentials(token)) - ac, err := arvados.NewClientFromConfig(&cl) +func (super *Supervisor) ClientsWithToken(clusterID, token string) (context.Context, *arvados.Client, *keepclient.KeepClient) { + cl := super.cluster + if super.children != nil { + cl = super.children[clusterID].cluster + } else if clusterID != cl.ClusterID { + panic("bad clusterID " + clusterID) + } + ctx := auth.NewContext(super.ctx, auth.NewCredentials(token)) + ac, err := arvados.NewClientFromConfig(cl) if err != nil { panic(err) } @@ -92,7 +43,7 @@ func (tc *TestCluster) ClientsWithToken(token string) (context.Context, *arvados // initialize clients with the API token, set up the user and // optionally activate the user. Return client structs for // communicating with the cluster on behalf of the 'example' user. -func (tc *TestCluster) UserClients(rootctx context.Context, c *check.C, conn *rpc.Conn, authEmail string, activate bool) (context.Context, *arvados.Client, *keepclient.KeepClient, arvados.User) { +func (super *Supervisor) UserClients(clusterID string, rootctx context.Context, c *check.C, conn *rpc.Conn, authEmail string, activate bool) (context.Context, *arvados.Client, *keepclient.KeepClient, arvados.User) { login, err := conn.UserSessionCreate(rootctx, rpc.UserSessionCreateOptions{ ReturnTo: ",https://example.com", AuthInfo: rpc.UserSessionAuthInfo{ @@ -107,7 +58,7 @@ func (tc *TestCluster) UserClients(rootctx context.Context, c *check.C, conn *rp c.Assert(err, check.IsNil) userToken := redirURL.Query().Get("api_token") c.Logf("user token: %q", userToken) - ctx, ac, kc := tc.ClientsWithToken(userToken) + ctx, ac, kc := super.ClientsWithToken(clusterID, userToken) user, err := conn.UserGetCurrent(ctx, arvados.GetOptions{}) c.Assert(err, check.IsNil) _, err = conn.UserSetup(rootctx, arvados.UserSetupOptions{UUID: user.UUID}) @@ -127,18 +78,19 @@ func (tc *TestCluster) UserClients(rootctx context.Context, c *check.C, conn *rp // RootClients returns Context, arvados.Client and keepclient structs initialized // to communicate with the cluster as the system root user. -func (tc *TestCluster) RootClients() (context.Context, *arvados.Client, *keepclient.KeepClient) { - return tc.ClientsWithToken(tc.Config.Clusters[tc.ClusterID].SystemRootToken) +func (super *Supervisor) RootClients(clusterID string) (context.Context, *arvados.Client, *keepclient.KeepClient) { + return super.ClientsWithToken(clusterID, super.Cluster(clusterID).SystemRootToken) } // AnonymousClients returns Context, arvados.Client and keepclient structs initialized // to communicate with the cluster as the anonymous user. -func (tc *TestCluster) AnonymousClients() (context.Context, *arvados.Client, *keepclient.KeepClient) { - return tc.ClientsWithToken(tc.Config.Clusters[tc.ClusterID].Users.AnonymousUserToken) +func (super *Supervisor) AnonymousClients(clusterID string) (context.Context, *arvados.Client, *keepclient.KeepClient) { + return super.ClientsWithToken(clusterID, super.Cluster(clusterID).Users.AnonymousUserToken) } // Conn gets rpc connection struct initialized to communicate with the // specified cluster. -func (tc *TestCluster) Conn() *rpc.Conn { - return rpc.NewConn(tc.ClusterID, tc.ControllerURL, true, rpc.PassthroughTokenProvider) +func (super *Supervisor) Conn(clusterID string) *rpc.Conn { + controllerURL := url.URL(super.Cluster(clusterID).Services.Controller.ExternalURL) + return rpc.NewConn(clusterID, &controllerURL, true, rpc.PassthroughTokenProvider) }