func (s *Suite) TestAPIConnectWithMacaroon(c *gc.C) { // Use ABORT because it involves an API connection to the target // and is convenient. status := s.makeStatus(coremigration.ABORT) // Set up macaroon based auth to the target. mac, err := macaroon.New([]byte("secret"), "id", "location") c.Assert(err, jc.ErrorIsNil) macs := []macaroon.Slice{{mac}} status.TargetInfo.Password = "" status.TargetInfo.Macaroons = macs s.facade.queueStatus(status) s.checkWorkerReturns(c, migrationmaster.ErrInactive) s.stub.CheckCalls(c, joinCalls( watchStatusLockdownCalls, []jujutesting.StubCall{ { "apiOpen", []interface{}{ &api.Info{ Addrs: []string{"1.2.3.4:5"}, CACert: "cert", Tag: names.NewUserTag("admin"), Macaroons: macs, // <--- }, migration.ControllerDialOpts(), }, }, abortCall, apiCloseCall, {"facade.SetPhase", []interface{}{coremigration.ABORTDONE}}, }, )) }
} result.Results[i].Error = common.ServerError( ChangeControllerAccess(c.state, c.apiUser, targetUserTag, arg.Action, controllerAccess)) } return result, nil } var runMigrationPrechecks = func(st *state.State, targetInfo coremigration.TargetInfo) error { // Check model and source controller. if err := migration.SourcePrecheck(migration.PrecheckShim(st)); err != nil { return errors.Annotate(err, "source prechecks failed") } // Check target controller. conn, err := api.Open(targetToAPIInfo(targetInfo), migration.ControllerDialOpts()) if err != nil { return errors.Annotate(err, "connect to target controller") } defer conn.Close() modelInfo, err := makeModelInfo(st) if err != nil { return errors.Trace(err) } err = migrationtarget.NewClient(conn).Prechecks(modelInfo) return errors.Annotate(err, "target prechecks failed") } func makeModelInfo(st *state.State) (coremigration.ModelInfo, error) { var empty coremigration.ModelInfo
modelTag = names.NewModelTag(modelUUID) modelName = "model-name" ownerTag = names.NewUserTag("owner") modelVersion = version.MustParse("1.2.4") // Define stub calls that commonly appear in tests here to allow reuse. apiOpenControllerCall = jujutesting.StubCall{ "apiOpen", []interface{}{ &api.Info{ Addrs: []string{"1.2.3.4:5"}, CACert: "cert", Tag: names.NewUserTag("admin"), Password: "******", }, migration.ControllerDialOpts(), }, } apiOpenModelCall = jujutesting.StubCall{ "apiOpen", []interface{}{ &api.Info{ Addrs: []string{"1.2.3.4:5"}, CACert: "cert", Tag: names.NewUserTag("admin"), Password: "******", ModelTag: modelTag, }, migration.ControllerDialOpts(), }, }