func (s *CommonProvisionerSuite) newEnvironProvisioner(c *gc.C) provisioner.Provisioner { machineTag := names.NewMachineTag("0") agentConfig := s.AgentConfigForTag(c, machineTag) apiState := apiprovisioner.NewState(s.st) w, err := provisioner.NewEnvironProvisioner(apiState, agentConfig, s.Environ) c.Assert(err, jc.ErrorIsNil) return w }
// updateSupportedContainers records in state that a machine can run the specified containers. // It starts a watcher and when a container of a given type is first added to the machine, // the watcher is killed, the machine is set up to be able to start containers of the given type, // and a suitable provisioner is started. func (a *MachineAgent) updateSupportedContainers( runner worker.Runner, st api.Connection, containers []instance.ContainerType, agentConfig agent.Config, ) error { pr := apiprovisioner.NewState(st) tag := agentConfig.Tag().(names.MachineTag) machine, err := pr.Machine(tag) if errors.IsNotFound(err) || err == nil && machine.Life() == params.Dead { return worker.ErrTerminateAgent } if err != nil { return errors.Annotatef(err, "cannot load machine %s from state", tag) } if len(containers) == 0 { if err := machine.SupportsNoContainers(); err != nil { return errors.Annotatef(err, "clearing supported containers for %s", tag) } return nil } if err := machine.SetSupportedContainers(containers...); err != nil { return errors.Annotatef(err, "setting supported containers for %s", tag) } // Start the watcher to fire when a container is first requested on the machine. watcherName := fmt.Sprintf("%s-container-watcher", machine.Id()) params := provisioner.ContainerSetupParams{ Runner: runner, WorkerName: watcherName, SupportedContainers: containers, Machine: machine, Provisioner: pr, Config: agentConfig, InitLockName: agent.MachineLockName, } handler := provisioner.NewContainerSetupHandler(params) a.startWorkerAfterUpgrade(runner, watcherName, func() (worker.Worker, error) { w, err := watcher.NewStringsWorker(watcher.StringsConfig{ Handler: handler, }) if err != nil { return nil, errors.Annotatef(err, "cannot start %s worker", watcherName) } return w, nil }) return nil }
// Manifold creates a manifold that runs an environemnt provisioner. See the // ManifoldConfig type for discussion about how this can/should evolve. func Manifold(config ManifoldConfig) dependency.Manifold { return dependency.Manifold{ Inputs: []string{config.AgentName, config.APICallerName}, Start: func(getResource dependency.GetResourceFunc) (worker.Worker, error) { var agent agent.Agent if err := getResource(config.AgentName, &agent); err != nil { return nil, errors.Trace(err) } var apiCaller base.APICaller if err := getResource(config.APICallerName, &apiCaller); err != nil { return nil, errors.Trace(err) } api := apiprovisioner.NewState(apiCaller) config := agent.CurrentConfig() w, err := NewEnvironProvisioner(api, config) if err != nil { return nil, errors.Trace(err) } return w, nil }, } }
func (s *provisionerSuite) SetUpTest(c *gc.C) { s.JujuConnSuite.SetUpTest(c) var err error s.machine, err = s.State.AddMachine("quantal", state.JobManageModel) c.Assert(err, jc.ErrorIsNil) password, err := utils.RandomPassword() c.Assert(err, jc.ErrorIsNil) err = s.machine.SetPassword(password) c.Assert(err, jc.ErrorIsNil) err = s.machine.SetInstanceInfo("i-manager", "fake_nonce", nil, nil, nil, nil, nil) c.Assert(err, jc.ErrorIsNil) s.st = s.OpenAPIAsMachine(c, s.machine.Tag(), password, "fake_nonce") c.Assert(s.st, gc.NotNil) err = s.machine.SetProviderAddresses(network.NewAddress("0.1.2.3")) c.Assert(err, jc.ErrorIsNil) // Create the provisioner API facade. s.provisioner = provisioner.NewState(s.st) c.Assert(s.provisioner, gc.NotNil) s.ModelWatcherTests = apitesting.NewModelWatcherTests(s.provisioner, s.BackingState) s.APIAddresserTests = apitesting.NewAPIAddresserTests(s.provisioner, s.BackingState) }
// Provisioner returns a version of the state that provides functionality // required by the provisioner worker. func (st *State) Provisioner() *provisioner.State { return provisioner.NewState(st) }
func (s *CommonProvisionerSuite) SetUpTest(c *gc.C) { s.JujuConnSuite.SetUpTest(c) // We do not want to pull published image metadata for tests... imagetesting.PatchOfficialDataSources(&s.CleanupSuite, "") // We want an image to start test instances err := s.State.CloudImageMetadataStorage.SaveMetadata([]cloudimagemetadata.Metadata{{ MetadataAttributes: cloudimagemetadata.MetadataAttributes{ Region: "region", Series: "trusty", Arch: "amd64", VirtType: "", RootStorageType: "", Source: "test", Stream: "released", }, Priority: 10, ImageId: "-999", }}) c.Assert(err, jc.ErrorIsNil) // Create the operations channel with more than enough space // for those tests that don't listen on it. op := make(chan dummy.Operation, 500) dummy.Listen(op) s.op = op cfg, err := s.State.ModelConfig() c.Assert(err, jc.ErrorIsNil) s.cfg = cfg // Create a machine for the dummy bootstrap instance, // so the provisioner doesn't destroy it. insts, err := s.Environ.Instances([]instance.Id{dummy.BootstrapInstanceId}) c.Assert(err, jc.ErrorIsNil) addrs, err := insts[0].Addresses() c.Assert(err, jc.ErrorIsNil) machine, err := s.State.AddOneMachine(state.MachineTemplate{ Addresses: addrs, Series: "quantal", Nonce: agent.BootstrapNonce, InstanceId: dummy.BootstrapInstanceId, Jobs: []state.MachineJob{state.JobManageModel}, }) c.Assert(err, jc.ErrorIsNil) c.Assert(machine.Id(), gc.Equals, "0") current := version.Binary{ Number: jujuversion.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } err = machine.SetAgentVersion(current) c.Assert(err, jc.ErrorIsNil) password, err := utils.RandomPassword() c.Assert(err, jc.ErrorIsNil) err = machine.SetPassword(password) c.Assert(err, jc.ErrorIsNil) s.st = s.OpenAPIAsMachine(c, machine.Tag(), password, agent.BootstrapNonce) c.Assert(s.st, gc.NotNil) c.Logf("API: login as %q successful", machine.Tag()) s.provisioner = apiprovisioner.NewState(s.st) c.Assert(s.provisioner, gc.NotNil) }