// 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 newObserverFn( controllerConfig controller.Config, clock clock.Clock, jujuServerVersion version.Number, modelUUID string, persistAuditEntry audit.AuditEntrySinkFn, auditErrorHandler observer.ErrorHandler, ) observer.ObserverFactory { var observerFactories []observer.ObserverFactory // Common logging of RPC requests observerFactories = append(observerFactories, func() observer.Observer { logger := loggo.GetLogger("juju.apiserver") ctx := observer.RequestObserverContext{ Clock: clock, Logger: logger, } return observer.NewRequestObserver(ctx) }) // Auditing observer // TODO(katco): Auditing needs feature tests (lp:1604551) if controllerConfig.AuditingEnabled() { observerFactories = append(observerFactories, func() observer.Observer { ctx := &observer.AuditContext{ JujuServerVersion: jujuServerVersion, ModelUUID: modelUUID, } return observer.NewAudit(ctx, persistAuditEntry, auditErrorHandler) }) } return observer.ObserverFactoryMultiplexer(observerFactories...) }
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`) }