func (s *environSuite) TestCloudSpec(c *gc.C) { owner := s.Factory.MakeUser(c, nil).UserTag() emptyCredential := cloud.NewEmptyCredential() tag := names.NewCloudCredentialTag("dummy/" + owner.Id() + "/empty-credential") err := s.State.UpdateCloudCredential(tag, emptyCredential) c.Assert(err, jc.ErrorIsNil) st := s.Factory.MakeModel(c, &factory.ModelParams{ Name: "foo", CloudName: "dummy", CloudCredential: tag, Owner: owner, }) defer st.Close() emptyCredential.Label = "empty-credential" cloudSpec, err := stateenvirons.EnvironConfigGetter{st}.CloudSpec(st.ModelTag()) c.Assert(err, jc.ErrorIsNil) c.Assert(cloudSpec, jc.DeepEquals, environs.CloudSpec{ Type: "dummy", Name: "dummy", Region: "dummy-region", Endpoint: "dummy-endpoint", IdentityEndpoint: "dummy-identity-endpoint", StorageEndpoint: "dummy-storage-endpoint", Credential: &emptyCredential, }) }
func (t *LiveTests) bootstrapParams() bootstrap.BootstrapParams { credential := t.Credential if credential.AuthType() == "" { credential = cloud.NewEmptyCredential() } var regions []cloud.Region if t.CloudRegion != "" { regions = []cloud.Region{{ Name: t.CloudRegion, Endpoint: t.CloudEndpoint, }} } return bootstrap.BootstrapParams{ ControllerConfig: coretesting.FakeControllerConfig(), CloudName: t.TestConfig["type"].(string), Cloud: cloud.Cloud{ Type: t.TestConfig["type"].(string), AuthTypes: []cloud.AuthType{credential.AuthType()}, Regions: regions, Endpoint: t.CloudEndpoint, }, CloudRegion: t.CloudRegion, CloudCredential: &credential, CloudCredentialName: "credential", AdminSecret: AdminSecret, CAPrivateKey: coretesting.CAKey, } }
func (t *Tests) TestBootstrap(c *gc.C) { credential := t.Credential if credential.AuthType() == "" { credential = cloud.NewEmptyCredential() } var regions []cloud.Region if t.CloudRegion != "" { regions = []cloud.Region{{ Name: t.CloudRegion, Endpoint: t.CloudEndpoint, }} } args := bootstrap.BootstrapParams{ ControllerConfig: coretesting.FakeControllerConfig(), CloudName: t.TestConfig["type"].(string), Cloud: cloud.Cloud{ Type: t.TestConfig["type"].(string), AuthTypes: []cloud.AuthType{credential.AuthType()}, Regions: regions, Endpoint: t.CloudEndpoint, }, CloudRegion: t.CloudRegion, CloudCredential: &credential, CloudCredentialName: "credential", AdminSecret: AdminSecret, CAPrivateKey: coretesting.CAKey, } e := t.Prepare(c) err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), e, args) c.Assert(err, jc.ErrorIsNil) controllerInstances, err := e.ControllerInstances(t.ControllerUUID) c.Assert(err, jc.ErrorIsNil) c.Assert(controllerInstances, gc.Not(gc.HasLen), 0) e2 := t.Open(c, e.Config()) controllerInstances2, err := e2.ControllerInstances(t.ControllerUUID) c.Assert(err, jc.ErrorIsNil) c.Assert(controllerInstances2, gc.Not(gc.HasLen), 0) c.Assert(controllerInstances2, jc.SameContents, controllerInstances) err = environs.Destroy(e2.Config().Name(), e2, t.ControllerStore) c.Assert(err, jc.ErrorIsNil) // Prepare again because Destroy invalidates old environments. e3 := t.Prepare(c) err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), e3, args) c.Assert(err, jc.ErrorIsNil) err = environs.Destroy(e3.Config().Name(), e3, t.ControllerStore) c.Assert(err, jc.ErrorIsNil) }
func (t *Tests) CloudSpec() environs.CloudSpec { credential := t.Credential if credential.AuthType() == "" { credential = cloud.NewEmptyCredential() } return environs.CloudSpec{ Type: t.TestConfig["type"].(string), Name: t.TestConfig["type"].(string), Region: t.CloudRegion, Endpoint: t.CloudEndpoint, Credential: &credential, } }
func (t *LiveTests) prepareForBootstrapParams(c *gc.C) environs.PrepareParams { credential := t.Credential if credential.AuthType() == "" { credential = cloud.NewEmptyCredential() } return environs.PrepareParams{ BaseConfig: t.TestConfig, Credential: credential, CloudEndpoint: t.CloudEndpoint, CloudRegion: t.CloudRegion, ControllerName: t.TestConfig["name"].(string), CloudName: t.TestConfig["type"].(string), } }
// Prepare prepares an instance of the testing environment. func (t *Tests) Prepare(c *gc.C) environs.Environ { credential := t.Credential if credential.AuthType() == "" { credential = cloud.NewEmptyCredential() } args := environs.PrepareParams{ BaseConfig: t.TestConfig, Credential: credential, ControllerName: t.TestConfig["name"].(string), CloudName: t.TestConfig["type"].(string), CloudEndpoint: t.CloudEndpoint, CloudRegion: t.CloudRegion, } e, err := environs.Prepare(envtesting.BootstrapContext(c), t.ControllerStore, args) c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", t.TestConfig)) c.Assert(e, gc.NotNil) return e }
func (t *LiveTests) prepareForBootstrapParams(c *gc.C) bootstrap.PrepareParams { credential := t.Credential if credential.AuthType() == "" { credential = cloud.NewEmptyCredential() } return bootstrap.PrepareParams{ ControllerConfig: coretesting.FakeControllerConfig(), ModelConfig: t.TestConfig, Cloud: environs.CloudSpec{ Type: t.TestConfig["type"].(string), Name: t.TestConfig["type"].(string), Region: t.CloudRegion, Endpoint: t.CloudEndpoint, Credential: &credential, }, ControllerName: t.TestConfig["name"].(string), AdminSecret: AdminSecret, } }
func (s *cloudSuite) SetUpTest(c *gc.C) { s.IsolationSuite.SetUpTest(c) s.authorizer = apiservertesting.FakeAuthorizer{ Tag: names.NewUserTag("admin"), } s.backend = mockBackend{ cloud: cloud.Cloud{ Type: "dummy", AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType}, Regions: []cloud.Region{{Name: "nether", Endpoint: "endpoint"}}, }, creds: map[string]cloud.Credential{ names.NewCloudCredentialTag("meep/bruce/one").Id(): cloud.NewEmptyCredential(), names.NewCloudCredentialTag("meep/bruce/two").Id(): cloud.NewCredential(cloud.UserPassAuthType, map[string]string{ "username": "******", "password": "******", }), }, } var err error s.api, err = cloudfacade.NewCloudAPI(&s.backend, &s.authorizer) c.Assert(err, jc.ErrorIsNil) }
func (s *InitializeSuite) TestInitialize(c *gc.C) { cfg := testing.ModelConfig(c) uuid := cfg.UUID() owner := names.NewLocalUserTag("initialize-admin") userPassCredentialTag := names.NewCloudCredentialTag( "dummy/" + owner.Canonical() + "/some-credential", ) emptyCredentialTag := names.NewCloudCredentialTag( "dummy/" + owner.Canonical() + "/empty-credential", ) userpassCredential := cloud.NewCredential( cloud.UserPassAuthType, map[string]string{ "username": "******", "password": "******", }, ) userpassCredential.Label = userPassCredentialTag.Name() emptyCredential := cloud.NewEmptyCredential() emptyCredential.Label = emptyCredentialTag.Name() cloudCredentialsIn := map[names.CloudCredentialTag]cloud.Credential{ userPassCredentialTag: userpassCredential, emptyCredentialTag: emptyCredential, } controllerCfg := testing.FakeControllerConfig() st, err := state.Initialize(state.InitializeParams{ Clock: clock.WallClock, ControllerConfig: controllerCfg, ControllerModelArgs: state.ModelArgs{ Owner: owner, Config: cfg, CloudName: "dummy", CloudRegion: "dummy-region", CloudCredential: userPassCredentialTag, StorageProviderRegistry: storage.StaticProviderRegistry{}, }, CloudName: "dummy", Cloud: cloud.Cloud{ Type: "dummy", AuthTypes: []cloud.AuthType{ cloud.EmptyAuthType, cloud.UserPassAuthType, }, Regions: []cloud.Region{{Name: "dummy-region"}}, }, CloudCredentials: cloudCredentialsIn, MongoInfo: statetesting.NewMongoInfo(), MongoDialOpts: mongotest.DialOpts(), }) c.Assert(err, jc.ErrorIsNil) c.Assert(st, gc.NotNil) modelTag := st.ModelTag() c.Assert(modelTag.Id(), gc.Equals, uuid) err = st.Close() c.Assert(err, jc.ErrorIsNil) s.openState(c, modelTag) cfg, err = s.State.ModelConfig() c.Assert(err, jc.ErrorIsNil) expected := cfg.AllAttrs() for k, v := range config.ConfigDefaults() { if _, ok := expected[k]; !ok { expected[k] = v } } c.Assert(cfg.AllAttrs(), jc.DeepEquals, expected) // Check that the model has been created. model, err := s.State.Model() c.Assert(err, jc.ErrorIsNil) c.Assert(model.Tag(), gc.Equals, modelTag) c.Assert(model.CloudRegion(), gc.Equals, "dummy-region") // Check that the owner has been created. c.Assert(model.Owner(), gc.Equals, owner) // Check that the owner can be retrieved by the tag. entity, err := s.State.FindEntity(model.Owner()) c.Assert(err, jc.ErrorIsNil) c.Assert(entity.Tag(), gc.Equals, owner) // Check that the owner has an ModelUser created for the bootstrapped model. modelUser, err := s.State.UserAccess(model.Owner(), model.Tag()) c.Assert(err, jc.ErrorIsNil) c.Assert(modelUser.UserTag, gc.Equals, owner) c.Assert(modelUser.Object, gc.Equals, model.Tag()) // Check that the model can be found through the tag. entity, err = s.State.FindEntity(modelTag) c.Assert(err, jc.ErrorIsNil) cons, err := s.State.ModelConstraints() c.Assert(err, jc.ErrorIsNil) c.Assert(&cons, jc.Satisfies, constraints.IsEmpty) addrs, err := s.State.APIHostPorts() c.Assert(err, jc.ErrorIsNil) c.Assert(addrs, gc.HasLen, 0) info, err := s.State.ControllerInfo() c.Assert(err, jc.ErrorIsNil) c.Assert(info, jc.DeepEquals, &state.ControllerInfo{ModelTag: modelTag, CloudName: "dummy"}) // Check that the model's cloud and credential names are as // expected, and the owner's cloud credentials are initialised. c.Assert(model.Cloud(), gc.Equals, "dummy") credentialTag, ok := model.CloudCredential() c.Assert(ok, jc.IsTrue) c.Assert(credentialTag, gc.Equals, userPassCredentialTag) cloudCredentials, err := s.State.CloudCredentials(model.Owner(), "dummy") c.Assert(err, jc.ErrorIsNil) expectedCred := make(map[string]cloud.Credential, len(cloudCredentialsIn)) for tag, cred := range cloudCredentialsIn { expectedCred[tag.Canonical()] = cred } c.Assert(cloudCredentials, jc.DeepEquals, expectedCred) }
func (s *JujuConnSuite) setUpConn(c *gc.C) { if s.RootDir != "" { c.Fatal("JujuConnSuite.setUpConn without teardown") } s.RootDir = c.MkDir() s.oldHome = utils.Home() home := filepath.Join(s.RootDir, "/home/ubuntu") err := os.MkdirAll(home, 0777) c.Assert(err, jc.ErrorIsNil) utils.SetHome(home) err = os.MkdirAll(filepath.Join(home, ".local", "share"), 0777) c.Assert(err, jc.ErrorIsNil) s.oldJujuXDGDataHome = osenv.SetJujuXDGDataHome(filepath.Join(home, ".local", "share", "juju")) err = os.MkdirAll(osenv.JujuXDGDataHome(), 0777) c.Assert(err, jc.ErrorIsNil) err = os.MkdirAll(s.DataDir(), 0777) c.Assert(err, jc.ErrorIsNil) s.PatchEnvironment(osenv.JujuModelEnvKey, "admin") cfg, err := config.New(config.UseDefaults, (map[string]interface{})(s.sampleConfig())) c.Assert(err, jc.ErrorIsNil) s.ControllerStore = jujuclient.NewFileClientStore() ctx := testing.Context(c) environ, err := environs.Prepare( modelcmd.BootstrapContext(ctx), s.ControllerStore, environs.PrepareParams{ BaseConfig: cfg.AllAttrs(), Credential: cloud.NewEmptyCredential(), ControllerName: ControllerName, CloudName: "dummy", }, ) c.Assert(err, jc.ErrorIsNil) // sanity check we've got the correct environment. c.Assert(environ.Config().Name(), gc.Equals, "admin") s.PatchValue(&dummy.DataDir, s.DataDir()) s.LogDir = c.MkDir() s.PatchValue(&dummy.LogDir, s.LogDir) versions := PreferredDefaultVersions(environ.Config(), version.Binary{ Number: jujuversion.Current, Arch: "amd64", Series: "precise", }) current := version.Binary{ Number: jujuversion.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } versions = append(versions, current) // Upload tools for both preferred and fake default series s.DefaultToolsStorageDir = c.MkDir() s.PatchValue(&tools.DefaultBaseURL, s.DefaultToolsStorageDir) stor, err := filestorage.NewFileStorageWriter(s.DefaultToolsStorageDir) c.Assert(err, jc.ErrorIsNil) // Upload tools to both release and devel streams since config will dictate that we // end up looking in both places. envtesting.AssertUploadFakeToolsVersions(c, stor, "released", "released", versions...) envtesting.AssertUploadFakeToolsVersions(c, stor, "devel", "devel", versions...) s.DefaultToolsStorage = stor s.PatchValue(&juju.JujuPublicKey, sstesting.SignedMetadataPublicKey) err = bootstrap.Bootstrap(modelcmd.BootstrapContext(ctx), environ, bootstrap.BootstrapParams{}) c.Assert(err, jc.ErrorIsNil) s.BackingState = environ.(GetStater).GetStateInAPIServer() s.State, err = newState(environ, s.BackingState.MongoConnectionInfo()) c.Assert(err, jc.ErrorIsNil) apiInfo, err := environs.APIInfo(environ) c.Assert(err, jc.ErrorIsNil) apiInfo.Tag = s.AdminUserTag(c) apiInfo.Password = environ.Config().AdminSecret() s.APIState, err = api.Open(apiInfo, api.DialOpts{}) c.Assert(err, jc.ErrorIsNil) err = s.State.SetAPIHostPorts(s.APIState.APIHostPorts()) c.Assert(err, jc.ErrorIsNil) // Make sure the controller store has the controller api endpoint address set controller, err := s.ControllerStore.ControllerByName(ControllerName) c.Assert(err, jc.ErrorIsNil) controller.APIEndpoints = []string{s.APIState.APIHostPorts()[0][0].String()} err = s.ControllerStore.UpdateController(ControllerName, *controller) c.Assert(err, jc.ErrorIsNil) err = modelcmd.WriteCurrentController(ControllerName) c.Assert(err, jc.ErrorIsNil) s.Environ = environ // Insert expected values... servingInfo := state.StateServingInfo{ PrivateKey: testing.ServerKey, Cert: testing.ServerCert, CAPrivateKey: testing.CAKey, SharedSecret: "really, really secret", APIPort: 4321, StatePort: 1234, } s.State.SetStateServingInfo(servingInfo) }
func (s *modelManagerSuite) SetUpTest(c *gc.C) { s.IsolationSuite.SetUpTest(c) attrs := dummy.SampleConfig() attrs["agent-version"] = jujuversion.Current.String() cfg, err := config.New(config.UseDefaults, attrs) c.Assert(err, jc.ErrorIsNil) dummyCloud := cloud.Cloud{ Type: "dummy", AuthTypes: []cloud.AuthType{cloud.EmptyAuthType}, Regions: []cloud.Region{ {Name: "some-region"}, {Name: "qux"}, }, } s.st = &mockState{ modelUUID: coretesting.ModelTag.Id(), cloud: dummyCloud, clouds: map[names.CloudTag]cloud.Cloud{ names.NewCloudTag("some-cloud"): dummyCloud, }, controllerModel: &mockModel{ owner: names.NewUserTag("admin@local"), life: state.Alive, cfg: cfg, status: status.StatusInfo{ Status: status.Available, Since: &time.Time{}, }, users: []*mockModelUser{{ userName: "******", access: permission.AdminAccess, }, { userName: "******", access: permission.WriteAccess, }}, }, model: &mockModel{ owner: names.NewUserTag("admin@local"), life: state.Alive, tag: coretesting.ModelTag, cfg: cfg, status: status.StatusInfo{ Status: status.Available, Since: &time.Time{}, }, users: []*mockModelUser{{ userName: "******", access: permission.AdminAccess, }, { userName: "******", access: permission.WriteAccess, }}, }, cred: cloud.NewEmptyCredential(), cfgDefaults: config.ModelDefaultAttributes{ "attr": config.AttributeDefaultValues{ Default: "", Controller: "val", Regions: []config.RegionDefaultValue{{ Name: "dummy", Value: "val++"}}}, "attr2": config.AttributeDefaultValues{ Controller: "val3", Default: "val2", Regions: []config.RegionDefaultValue{{ Name: "left", Value: "spam"}}}, }, } s.authoriser = apiservertesting.FakeAuthorizer{ Tag: names.NewUserTag("admin@local"), } api, err := modelmanager.NewModelManagerAPI(s.st, nil, s.authoriser) c.Assert(err, jc.ErrorIsNil) s.api = api }