本文整理汇总了Golang中launchpad/net/juju-core/worker/provisioner.NewProvisioner函数的典型用法代码示例。如果您正苦于以下问题:Golang NewProvisioner函数的具体用法?Golang NewProvisioner怎么用?Golang NewProvisioner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewProvisioner函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestProvisioningStopsInstances
func (s *ProvisionerSuite) TestProvisioningStopsInstances(c *C) {
p := provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
// create a machine
m0, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
s.checkStartInstance(c, m0)
// create a second machine
m1, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
s.checkStartInstance(c, m1)
stop(c, p)
// mark the first machine as dead
c.Assert(m0.EnsureDead(), IsNil)
// remove the second machine entirely
c.Assert(m1.EnsureDead(), IsNil)
c.Assert(m1.Remove(), IsNil)
// start a new provisioner to shut them both down
p = provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
s.checkStopInstance(c)
s.checkStopInstance(c)
s.waitRemoved(c, m0)
}
示例2: TestProvisioningStopsUnknownInstances
func (s *ProvisionerSuite) TestProvisioningStopsUnknownInstances(c *C) {
p := provisioner.NewProvisioner(s.State)
// we are not using defer s.stopProvisioner(c, p) because we need to control when
// the PA is restarted in this test. Methods like Fatalf and Assert should not be used.
// create a machine
m, err := s.State.AddMachine(state.JobHostUnits)
c.Check(err, IsNil)
s.checkStartInstance(c, m, "pork")
// create a second machine
m, err = s.State.AddMachine(state.JobHostUnits)
c.Check(err, IsNil)
s.checkStartInstance(c, m, "pork")
// stop the PA
c.Check(p.Stop(), IsNil)
// mark the machine as dead
c.Assert(m.EnsureDead(), IsNil)
// start a new provisioner
p = provisioner.NewProvisioner(s.State)
s.checkStopInstance(c)
c.Assert(p.Stop(), IsNil)
}
示例3: TestProvisioningDoesNotProvisionTheSameMachineAfterRestart
func (s *ProvisionerSuite) TestProvisioningDoesNotProvisionTheSameMachineAfterRestart(c *C) {
p := provisioner.NewProvisioner(s.State)
// we are not using defer s.stopProvisioner(c, p) because we need to control when
// the PA is restarted in this test. tf. Methods like Fatalf and Assert should not be used.
// create a machine
m, err := s.State.AddMachine(state.JobHostUnits)
c.Check(err, IsNil)
s.checkStartInstance(c, m, "pork")
// restart the PA
c.Check(p.Stop(), IsNil)
p = provisioner.NewProvisioner(s.State)
// check that there is only one machine known
machines, err := p.AllMachines()
c.Check(err, IsNil)
c.Check(len(machines), Equals, 1)
c.Check(machines[0].Id(), Equals, "0")
// the PA should not create it a second time
s.checkNotStartInstance(c)
c.Assert(p.Stop(), IsNil)
}
示例4: TestProvisionerSetsErrorStatusWhenStartInstanceFailed
func (s *ProvisionerSuite) TestProvisionerSetsErrorStatusWhenStartInstanceFailed(c *C) {
brokenMsg := breakDummyProvider(c, s.State, "StartInstance")
p := provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
// Check that an instance is not provisioned when the machine is created...
m, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
s.checkNoOperations(c)
// And check the machine status is set to error.
status, info, err := m.Status()
c.Assert(err, IsNil)
c.Assert(status, Equals, params.StatusError)
c.Assert(info, Equals, brokenMsg)
// Unbreak the environ config.
err = s.fixEnvironment()
c.Assert(err, IsNil)
// Restart the PA to make sure the machine is skipped again.
stop(c, p)
p = provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
s.checkNoOperations(c)
}
示例5: TestDyingMachines
func (s *ProvisionerSuite) TestDyingMachines(c *C) {
p := provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
// provision a machine
m0, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
s.checkStartInstance(c, m0)
// stop the provisioner and make the machine dying
stop(c, p)
err = m0.Destroy()
c.Assert(err, IsNil)
// add a new, dying, unprovisioned machine
m1, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
err = m1.Destroy()
c.Assert(err, IsNil)
// start the provisioner and wait for it to reap the useless machine
p = provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
s.checkNoOperations(c)
s.waitRemoved(c, m1)
// verify the other one's still fine
err = m0.Refresh()
c.Assert(err, IsNil)
c.Assert(m0.Life(), Equals, state.Dying)
}
示例6: TestProvisioningRecoversAfterInvalidEnvironmentPublished
func (s *ProvisionerSuite) TestProvisioningRecoversAfterInvalidEnvironmentPublished(c *C) {
p := provisioner.NewProvisioner(s.State)
defer s.stopProvisioner(c, p)
// place a new machine into the state
m, err := s.State.AddMachine(state.JobHostUnits)
c.Assert(err, IsNil)
s.checkStartInstance(c, m, "pork")
err = s.invalidateEnvironment(c)
c.Assert(err, IsNil)
s.State.StartSync()
// create a second machine
m, err = s.State.AddMachine(state.JobHostUnits)
c.Assert(err, IsNil)
// the PA should create it using the old environment
s.checkStartInstance(c, m, "pork")
err = s.fixEnvironment()
c.Assert(err, IsNil)
// insert our observer
cfgObserver := make(chan *config.Config, 1)
p.SetObserver(cfgObserver)
cfg, err := s.State.EnvironConfig()
c.Assert(err, IsNil)
attrs := cfg.AllAttrs()
attrs["secret"] = "beef"
cfg, err = config.New(attrs)
c.Assert(err, IsNil)
err = s.State.SetEnvironConfig(cfg)
s.State.StartSync()
// wait for the PA to load the new configuration
select {
case <-cfgObserver:
case <-time.After(200 * time.Millisecond):
c.Fatalf("PA did not action config change")
}
// create a third machine
m, err = s.State.AddMachine(state.JobHostUnits)
c.Assert(err, IsNil)
// the PA should create it using the new environment
s.checkStartInstance(c, m, "beef")
}
示例7: TestConstraints
func (s *ProvisionerSuite) TestConstraints(c *C) {
// Create a machine with non-standard constraints.
m, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
cons := constraints.MustParse("mem=4G arch=amd64")
err = m.SetConstraints(cons)
c.Assert(err, IsNil)
// Start a provisioner and check those constraints are used.
p := provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
s.checkStartInstanceCustom(c, m, "pork", cons)
}
示例8: TestSimple
// STARTb OMIT
func (s *ProvisionerSuite) TestSimple(c *C) {
p := provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
// Check that an instance is provisioned when the machine is created...
m, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
s.checkStartInstance(c, m)
// ...and removed, along with the machine, when the machine is Dead.
c.Assert(m.EnsureDead(), IsNil)
s.checkStopInstance(c)
s.waitRemoved(c, m)
}
示例9: TestProvisioningDoesNotOccurWithAnInvalidEnvironment
func (s *ProvisionerSuite) TestProvisioningDoesNotOccurWithAnInvalidEnvironment(c *C) {
err := s.invalidateEnvironment(c)
c.Assert(err, IsNil)
p := provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
// try to create a machine
_, err = s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
// the PA should not create it
s.checkNoOperations(c)
}
示例10: TestProvisioningDoesNotProvisionTheSameMachineAfterRestart
func (s *ProvisionerSuite) TestProvisioningDoesNotProvisionTheSameMachineAfterRestart(c *C) {
p := provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
// create a machine
m, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
s.checkStartInstance(c, m)
// restart the PA
stop(c, p)
p = provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
// check that there is only one machine known
machines, err := p.AllMachines()
c.Assert(err, IsNil)
c.Check(len(machines), Equals, 1)
c.Check(machines[0].Id(), Equals, "0")
// the PA should not create it a second time
s.checkNoOperations(c)
}
示例11: TestProvisioningDoesNotOccurWithAnInvalidEnvironment
func (s *ProvisionerSuite) TestProvisioningDoesNotOccurWithAnInvalidEnvironment(c *C) {
err := s.invalidateEnvironment(c)
c.Assert(err, IsNil)
p := provisioner.NewProvisioner(s.State)
defer s.stopProvisioner(c, p)
// try to create a machine
_, err = s.State.AddMachine(state.JobHostUnits)
c.Assert(err, IsNil)
// the PA should not create it
s.checkNotStartInstance(c)
}
示例12: TestSimple
// Start and stop one machine, watch the PA.
func (s *ProvisionerSuite) TestSimple(c *C) {
p := provisioner.NewProvisioner(s.State)
defer s.stopProvisioner(c, p)
// place a new machine into the state
m, err := s.State.AddMachine(state.JobHostUnits)
c.Assert(err, IsNil)
s.checkStartInstance(c, m, "pork")
// now mark it as dying
c.Assert(m.EnsureDead(), IsNil)
// watch the PA remove it
s.checkStopInstance(c)
}
示例13: TestProvisioningOccursWithFixedEnvironment
func (s *ProvisionerSuite) TestProvisioningOccursWithFixedEnvironment(c *C) {
err := s.invalidateEnvironment(c)
c.Assert(err, IsNil)
p := provisioner.NewProvisioner(s.State)
defer s.stopProvisioner(c, p)
// try to create a machine
m, err := s.State.AddMachine(state.JobHostUnits)
c.Assert(err, IsNil)
// the PA should not create it
s.checkNotStartInstance(c)
err = s.fixEnvironment()
c.Assert(err, IsNil)
s.checkStartInstance(c, m, "pork")
}
示例14: RunOnce
func (a *MachineAgent) RunOnce(st *state.State, e AgentState) error {
m := e.(*state.Machine)
log.Printf("cmd/jujud: running jobs for machine agent: %v", m.Jobs())
tasks := []task{NewUpgrader(st, m, a.Conf.DataDir)}
for _, j := range m.Jobs() {
switch j {
case state.JobHostUnits:
tasks = append(tasks,
newDeployer(st, m.WatchPrincipalUnits(), a.Conf.DataDir))
case state.JobManageEnviron:
tasks = append(tasks,
provisioner.NewProvisioner(st),
firewaller.NewFirewaller(st))
default:
log.Printf("cmd/jujud: ignoring unknown job %q", j)
}
}
return runTasks(a.tomb.Dying(), tasks...)
}
示例15: TestProvisioningOccursWithFixedEnvironment
func (s *ProvisionerSuite) TestProvisioningOccursWithFixedEnvironment(c *C) {
err := s.invalidateEnvironment(c)
c.Assert(err, IsNil)
p := provisioner.NewProvisioner(s.State, "0")
defer stop(c, p)
// try to create a machine
m, err := s.State.AddMachine(config.DefaultSeries, state.JobHostUnits)
c.Assert(err, IsNil)
// the PA should not create it
s.checkNoOperations(c)
err = s.fixEnvironment()
c.Assert(err, IsNil)
s.checkStartInstance(c, m)
}