// NewBootstrapInstanceConfig sets up a basic machine configuration for a // bootstrap node. You'll still need to supply more information, but this // takes care of the fixed entries and the ones that are always needed. func NewBootstrapInstanceConfig( config controller.Config, cons, modelCons constraints.Value, series, publicImageSigningKey string, ) (*InstanceConfig, error) { // For a bootstrap instance, the caller must provide the state.Info // and the api.Info. The machine id must *always* be "0". icfg, err := NewInstanceConfig(names.NewControllerTag(config.ControllerUUID()), "0", agent.BootstrapNonce, "", series, nil) if err != nil { return nil, err } icfg.Controller = &ControllerConfig{ PublicImageSigningKey: publicImageSigningKey, } icfg.Controller.Config = make(map[string]interface{}) for k, v := range config { icfg.Controller.Config[k] = v } icfg.Bootstrap = &BootstrapConfig{ StateInitializationParams: StateInitializationParams{ BootstrapMachineConstraints: cons, ModelConstraints: modelCons, }, } icfg.Jobs = []multiwatcher.MachineJob{ multiwatcher.JobManageModel, multiwatcher.JobHostUnits, } return icfg, nil }
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`) }