func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) { if !t.HasProvisioner { c.Skip("HasProvisioner is false; cannot test deployment") } current := version.Binary{ Number: jujuversion.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } other := current other.Series = "quantal" if current == other { other.Series = "precise" } dummyCfg := dummy.SampleConfig().Merge(coretesting.Attrs{ "controller": false, "name": "dummy storage", }) args := t.prepareForBootstrapParams(c) args.ModelConfig = dummyCfg dummyenv, err := bootstrap.Prepare(envtesting.BootstrapContext(c), jujuclienttesting.NewMemStore(), args, ) c.Assert(err, jc.ErrorIsNil) defer dummyenv.Destroy() t.Destroy(c) attrs := t.TestConfig.Merge(coretesting.Attrs{ "name": "livetests", "default-series": other.Series, }) args.ModelConfig = attrs env, err := bootstrap.Prepare(envtesting.BootstrapContext(c), t.ControllerStore, args) c.Assert(err, jc.ErrorIsNil) defer environs.Destroy("livetests", env, t.ControllerStore) err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, t.bootstrapParams()) c.Assert(err, jc.ErrorIsNil) st := t.Env.(jujutesting.GetStater).GetStateInAPIServer() // Wait for machine agent to come up on the bootstrap // machine and ensure it deployed the proper series. m0, err := st.Machine("0") c.Assert(err, jc.ErrorIsNil) mw0 := newMachineToolWaiter(m0) defer mw0.Stop() waitAgentTools(c, mw0, other) }
func (s *ToolsMetadataSuite) SetUpTest(c *gc.C) { s.FakeJujuXDGDataHomeSuite.SetUpTest(c) s.AddCleanup(dummy.Reset) cfg, err := config.New(config.UseDefaults, map[string]interface{}{ "name": "erewhemos", "type": "dummy", "uuid": coretesting.ModelTag.Id(), "controller-uuid": coretesting.ControllerTag.Id(), "conroller": true, }) c.Assert(err, jc.ErrorIsNil) env, err := bootstrap.Prepare( modelcmd.BootstrapContextNoVerify(coretesting.Context(c)), jujuclienttesting.NewMemStore(), bootstrap.PrepareParams{ ControllerConfig: coretesting.FakeControllerConfig(), ControllerName: cfg.Name(), ModelConfig: cfg.AllAttrs(), Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }, ) c.Assert(err, jc.ErrorIsNil) s.env = env loggo.GetLogger("").SetLogLevel(loggo.INFO) // Switch the default tools location. s.publicStorageDir = c.MkDir() s.PatchValue(&tools.DefaultBaseURL, s.publicStorageDir) }
func (s *OpenSuite) TestUpdateEnvInfo(c *gc.C) { store := jujuclienttesting.NewMemStore() ctx := envtesting.BootstrapContext(c) uuid := utils.MustNewUUID().String() cfg, err := config.New(config.UseDefaults, map[string]interface{}{ "type": "dummy", "name": "admin-model", "uuid": uuid, }) c.Assert(err, jc.ErrorIsNil) controllerCfg := testing.FakeControllerConfig() _, err = bootstrap.Prepare(ctx, store, bootstrap.PrepareParams{ ControllerConfig: controllerCfg, ControllerName: "controller-name", ModelConfig: cfg.AllAttrs(), Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }) c.Assert(err, jc.ErrorIsNil) foundController, err := store.ControllerByName("controller-name") c.Assert(err, jc.ErrorIsNil) c.Assert(foundController.ControllerUUID, gc.Not(gc.Equals), "") c.Assert(foundController.CACert, gc.Not(gc.Equals), "") foundModel, err := store.ModelByName("controller-name", "admin/admin-model") c.Assert(err, jc.ErrorIsNil) c.Assert(foundModel, jc.DeepEquals, &jujuclient.ModelDetails{ ModelUUID: cfg.UUID(), }) }
func (s *OpenSuite) TestNewDummyEnviron(c *gc.C) { s.PatchValue(&jujuversion.Current, testing.FakeVersionNumber) // matches *Settings.Map() cfg, err := config.New(config.NoDefaults, dummySampleConfig()) c.Assert(err, jc.ErrorIsNil) ctx := envtesting.BootstrapContext(c) cache := jujuclienttesting.NewMemStore() controllerCfg := testing.FakeControllerConfig() env, err := bootstrap.Prepare(ctx, cache, bootstrap.PrepareParams{ ControllerConfig: controllerCfg, ControllerName: cfg.Name(), ModelConfig: cfg.AllAttrs(), Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }) c.Assert(err, jc.ErrorIsNil) storageDir := c.MkDir() s.PatchValue(&envtools.DefaultBaseURL, storageDir) stor, err := filestorage.NewFileStorageWriter(storageDir) c.Assert(err, jc.ErrorIsNil) envtesting.UploadFakeTools(c, stor, cfg.AgentStream(), cfg.AgentStream()) err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{ ControllerConfig: controllerCfg, AdminSecret: "admin-secret", CAPrivateKey: testing.CAKey, }) c.Assert(err, jc.ErrorIsNil) // New controller should have been added to collection. foundController, err := cache.ControllerByName(cfg.Name()) c.Assert(err, jc.ErrorIsNil) c.Assert(foundController.ControllerUUID, gc.DeepEquals, controllerCfg.ControllerUUID()) }
func (*OpenSuite) TestDestroy(c *gc.C) { cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge( testing.Attrs{ "name": "erewhemos", }, )) c.Assert(err, jc.ErrorIsNil) store := jujuclienttesting.NewMemStore() // Prepare the environment and sanity-check that // the config storage info has been made. controllerCfg := testing.FakeControllerConfig() ctx := envtesting.BootstrapContext(c) e, err := bootstrap.Prepare(ctx, store, bootstrap.PrepareParams{ ControllerConfig: controllerCfg, ControllerName: "controller-name", ModelConfig: cfg.AllAttrs(), Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }) c.Assert(err, jc.ErrorIsNil) _, err = store.ControllerByName("controller-name") c.Assert(err, jc.ErrorIsNil) err = environs.Destroy("controller-name", e, store) c.Assert(err, jc.ErrorIsNil) // Check that the environment has actually been destroyed // and that the controller details been removed too. _, err = e.ControllerInstances(controllerCfg.ControllerUUID()) c.Assert(err, gc.ErrorMatches, "model is not prepared") _, err = store.ControllerByName("controller-name") c.Assert(err, jc.Satisfies, errors.IsNotFound) }
func (s *suite) bootstrapTestEnviron(c *gc.C) environs.NetworkingEnviron { env, err := bootstrap.Prepare( envtesting.BootstrapContext(c), s.ControllerStore, bootstrap.PrepareParams{ ControllerConfig: testing.FakeControllerConfig(), ModelConfig: s.TestConfig, ControllerName: s.TestConfig["name"].(string), Cloud: dummy.SampleCloudSpec(), AdminSecret: AdminSecret, }, ) c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", s.TestConfig)) c.Assert(env, gc.NotNil) netenv, supported := environs.SupportsNetworking(env) c.Assert(supported, jc.IsTrue) err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), netenv, bootstrap.BootstrapParams{ ControllerConfig: testing.FakeControllerConfig(), CloudName: "dummy", Cloud: cloud.Cloud{ Type: "dummy", AuthTypes: []cloud.AuthType{cloud.EmptyAuthType}, }, AdminSecret: AdminSecret, CAPrivateKey: testing.CAKey, }) c.Assert(err, jc.ErrorIsNil) return netenv }
func (s *ImageMetadataSuite) env(c *gc.C, imageMetadataURL, stream string) environs.Environ { attrs := dummy.SampleConfig() if stream != "" { attrs = attrs.Merge(testing.Attrs{ "image-stream": stream, }) } if imageMetadataURL != "" { attrs = attrs.Merge(testing.Attrs{ "image-metadata-url": imageMetadataURL, }) } env, err := bootstrap.Prepare( envtesting.BootstrapContext(c), jujuclienttesting.NewMemStore(), bootstrap.PrepareParams{ ControllerConfig: testing.FakeControllerConfig(), ControllerName: attrs["name"].(string), ModelConfig: attrs, Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }, ) c.Assert(err, jc.ErrorIsNil) return env }
func (t *Tests) AssertPrepareFailsWithConfig(c *gc.C, badConfig coretesting.Attrs, errorMatches string) error { args := t.PrepareParams(c) args.ModelConfig = coretesting.Attrs(args.ModelConfig).Merge(badConfig) e, err := bootstrap.Prepare(envtesting.BootstrapContext(c), t.ControllerStore, args) c.Assert(err, gc.ErrorMatches, errorMatches) c.Assert(e, gc.IsNil) return err }
// PrepareOnce ensures that the environment is // available and prepared. It sets t.Env appropriately. func (t *LiveTests) PrepareOnce(c *gc.C) { if t.prepared { return } args := t.prepareForBootstrapParams(c) e, err := bootstrap.Prepare(envtesting.BootstrapContext(c), t.ControllerStore, args) c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", t.TestConfig)) c.Assert(e, gc.NotNil) t.Env = e t.prepared = true t.ControllerUUID = coretesting.FakeControllerConfig().ControllerUUID() }
func testingEnvConfig(c *gc.C) *config.Config { env, err := bootstrap.Prepare( modelcmd.BootstrapContext(testing.Context(c)), jujuclienttesting.NewMemStore(), bootstrap.PrepareParams{ ControllerConfig: testing.FakeControllerConfig(), ControllerName: "dummycontroller", ModelConfig: dummy.SampleConfig(), Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }, ) c.Assert(err, jc.ErrorIsNil) return env.Config() }
func (s *SimpleStreamsToolsSuite) resetEnv(c *gc.C, attrs map[string]interface{}) { jujuversion.Current = s.origCurrentVersion dummy.Reset(c) attrs = dummy.SampleConfig().Merge(attrs) env, err := bootstrap.Prepare(envtesting.BootstrapContext(c), jujuclienttesting.NewMemStore(), bootstrap.PrepareParams{ ControllerConfig: coretesting.FakeControllerConfig(), ControllerName: attrs["name"].(string), ModelConfig: attrs, Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }, ) c.Assert(err, jc.ErrorIsNil) s.env = env s.removeTools(c) }
func (s *ConfigSuite) TestFirewallMode(c *gc.C) { for i, test := range firewallModeTests { c.Logf("test %d: %s", i, test.configFirewallMode) attrs := dummy.SampleConfig() if test.configFirewallMode != "" { attrs = attrs.Merge(testing.Attrs{ "firewall-mode": test.configFirewallMode, }) } cfg, err := config.New(config.NoDefaults, attrs) if err != nil { c.Assert(err, gc.ErrorMatches, test.errorMsg) continue } ctx := envtesting.BootstrapContext(c) env, err := bootstrap.Prepare( ctx, jujuclienttesting.NewMemStore(), bootstrap.PrepareParams{ ControllerConfig: testing.FakeControllerConfig(), ControllerName: cfg.Name(), ModelConfig: cfg.AllAttrs(), Cloud: dummy.SampleCloudSpec(), AdminSecret: AdminSecret, }, ) if test.errorMsg != "" { c.Assert(err, gc.ErrorMatches, test.errorMsg) continue } c.Assert(err, jc.ErrorIsNil) defer env.Destroy() firewallMode := env.Config().FirewallMode() c.Assert(firewallMode, gc.Equals, test.firewallMode) s.TearDownTest(c) } }
func (s *NewAPIClientSuite) bootstrapModel(c *gc.C) (environs.Environ, jujuclient.ClientStore) { const controllerName = "my-controller" store := jujuclienttesting.NewMemStore() ctx := envtesting.BootstrapContext(c) env, err := bootstrap.Prepare(ctx, store, bootstrap.PrepareParams{ ControllerConfig: coretesting.FakeControllerConfig(), ControllerName: controllerName, ModelConfig: dummy.SampleConfig(), Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }) c.Assert(err, jc.ErrorIsNil) storageDir := c.MkDir() s.PatchValue(&envtools.DefaultBaseURL, storageDir) stor, err := filestorage.NewFileStorageWriter(storageDir) c.Assert(err, jc.ErrorIsNil) envtesting.UploadFakeTools(c, stor, "released", "released") err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{ ControllerConfig: coretesting.FakeControllerConfig(), CloudName: "dummy", Cloud: cloud.Cloud{ Type: "dummy", AuthTypes: []cloud.AuthType{cloud.EmptyAuthType}, }, AdminSecret: "admin-secret", CAPrivateKey: coretesting.CAKey, }) c.Assert(err, jc.ErrorIsNil) return env, store }
func (*PrepareSuite) TestPrepare(c *gc.C) { baselineAttrs := dummy.SampleConfig().Merge(testing.Attrs{ "controller": false, "name": "erewhemos", "test-mode": true, }).Delete( "admin-secret", ) cfg, err := config.New(config.NoDefaults, baselineAttrs) c.Assert(err, jc.ErrorIsNil) controllerStore := jujuclienttesting.NewMemStore() ctx := envtesting.BootstrapContext(c) controllerCfg := controller.Config{ controller.ControllerUUIDKey: testing.ControllerTag.Id(), controller.CACertKey: testing.CACert, controller.APIPort: 17777, controller.StatePort: 1234, controller.SetNUMAControlPolicyKey: true, } _, err = bootstrap.Prepare(ctx, controllerStore, bootstrap.PrepareParams{ ControllerConfig: controllerCfg, ControllerName: cfg.Name(), ModelConfig: cfg.AllAttrs(), Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }) c.Assert(err, jc.ErrorIsNil) // Check that controller was cached foundController, err := controllerStore.ControllerByName(cfg.Name()) c.Assert(err, jc.ErrorIsNil) c.Assert(foundController.ControllerUUID, gc.DeepEquals, controllerCfg.ControllerUUID()) c.Assert(foundController.Cloud, gc.Equals, "dummy") // Check that bootstrap config was written bootstrapCfg, err := controllerStore.BootstrapConfigForController(cfg.Name()) c.Assert(err, jc.ErrorIsNil) c.Assert(bootstrapCfg, jc.DeepEquals, &jujuclient.BootstrapConfig{ ControllerConfig: controller.Config{ controller.APIPort: 17777, controller.StatePort: 1234, controller.SetNUMAControlPolicyKey: true, }, Config: map[string]interface{}{ "default-series": "xenial", "firewall-mode": "instance", "ssl-hostname-verification": true, "logging-config": "<root>=DEBUG;unit=DEBUG", "secret": "pork", "authorized-keys": testing.FakeAuthKeys, "type": "dummy", "name": "erewhemos", "controller": false, "development": false, "test-mode": true, }, ControllerModelUUID: cfg.UUID(), Cloud: "dummy", CloudRegion: "dummy-region", CloudType: "dummy", CloudEndpoint: "dummy-endpoint", CloudIdentityEndpoint: "dummy-identity-endpoint", CloudStorageEndpoint: "dummy-storage-endpoint", }) // Check we cannot call Prepare again. _, err = bootstrap.Prepare(ctx, controllerStore, bootstrap.PrepareParams{ ControllerConfig: controllerCfg, ControllerName: cfg.Name(), ModelConfig: cfg.AllAttrs(), Cloud: dummy.SampleCloudSpec(), AdminSecret: "admin-secret", }) c.Assert(err, jc.Satisfies, errors.IsAlreadyExists) c.Assert(err, gc.ErrorMatches, `controller "erewhemos" already exists`) }
// PrepareWithParams prepares an instance of the testing environment. func (t *Tests) PrepareWithParams(c *gc.C, params bootstrap.PrepareParams) environs.Environ { e, err := bootstrap.Prepare(envtesting.BootstrapContext(c), t.ControllerStore, params) c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", params.ModelConfig)) c.Assert(e, gc.NotNil) return e }
func (s *JujuConnSuite) setUpConn(c *gc.C) { if s.RootDir != "" { c.Fatal("JujuConnSuite.setUpConn without teardown") } s.RootDir = c.MkDir() s.oldHome = utils.Home() userHomeParams := UserHomeParams{ Username: "******", ModelEnvKey: "controller", SetOldHome: true, } s.CreateUserHome(c, &userHomeParams) cfg, err := config.New(config.UseDefaults, (map[string]interface{})(s.sampleConfig())) c.Assert(err, jc.ErrorIsNil) ctx := testing.Context(c) s.ControllerConfig = testing.FakeControllerConfig() for key, value := range s.ControllerConfigAttrs { s.ControllerConfig[key] = value } cloudSpec := dummy.SampleCloudSpec() environ, err := bootstrap.Prepare( modelcmd.BootstrapContext(ctx), s.ControllerStore, bootstrap.PrepareParams{ ControllerConfig: s.ControllerConfig, ModelConfig: cfg.AllAttrs(), Cloud: cloudSpec, ControllerName: ControllerName, AdminSecret: AdminSecret, }, ) c.Assert(err, jc.ErrorIsNil) // sanity check we've got the correct environment. c.Assert(environ.Config().Name(), gc.Equals, "controller") s.PatchValue(&dummy.DataDir, s.DataDir()) s.LogDir = c.MkDir() s.PatchValue(&dummy.LogDir, s.LogDir) versions := DefaultVersions(environ.Config()) // 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(&keys.JujuPublicKey, sstesting.SignedMetadataPublicKey) // Dummy provider uses a random port, which is added to cfg used to create environment. apiPort := dummy.APIPort(environ.Provider()) s.ControllerConfig["api-port"] = apiPort err = bootstrap.Bootstrap(modelcmd.BootstrapContext(ctx), environ, bootstrap.BootstrapParams{ ControllerConfig: s.ControllerConfig, CloudName: cloudSpec.Name, CloudRegion: "dummy-region", Cloud: cloud.Cloud{ Type: cloudSpec.Type, AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType}, Endpoint: cloudSpec.Endpoint, IdentityEndpoint: cloudSpec.IdentityEndpoint, StorageEndpoint: cloudSpec.StorageEndpoint, Regions: []cloud.Region{ { Name: "dummy-region", Endpoint: "dummy-endpoint", IdentityEndpoint: "dummy-identity-endpoint", StorageEndpoint: "dummy-storage-endpoint", }, }, }, CloudCredential: cloudSpec.Credential, CloudCredentialName: "cred", AdminSecret: AdminSecret, CAPrivateKey: testing.CAKey, }) c.Assert(err, jc.ErrorIsNil) getStater := environ.(GetStater) s.BackingState = getStater.GetStateInAPIServer() s.BackingStatePool = getStater.GetStatePoolInAPIServer() s.State, err = newState(s.ControllerConfig.ControllerUUID(), environ, s.BackingState.MongoConnectionInfo()) c.Assert(err, jc.ErrorIsNil) apiInfo, err := environs.APIInfo(s.ControllerConfig.ControllerUUID(), testing.ModelTag.Id(), testing.CACert, s.ControllerConfig.APIPort(), environ) c.Assert(err, jc.ErrorIsNil) apiInfo.Tag = s.AdminUserTag(c) apiInfo.Password = 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 = s.ControllerStore.SetCurrentController(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: s.ControllerConfig.APIPort(), StatePort: s.ControllerConfig.StatePort(), } s.State.SetStateServingInfo(servingInfo) }