Exemplo n.º 1
0
func (s *DeployerSuite) TestRemoveNonAlivePrincipals(c *C) {
	// Create a machine, and a couple of units.
	m, err := s.State.AddMachine(state.JobHostUnits)
	c.Assert(err, IsNil)
	svc, err := s.State.AddService("wordpress", s.AddTestingCharm(c, "wordpress"))
	c.Assert(err, IsNil)
	u0, err := svc.AddUnit()
	c.Assert(err, IsNil)
	u1, err := svc.AddUnit()
	c.Assert(err, IsNil)

	// Assign the units to the machine, and set them to Dying/Dead.
	err = u0.AssignToMachine(m)
	c.Assert(err, IsNil)
	err = u0.EnsureDead()
	c.Assert(err, IsNil)
	err = u1.AssignToMachine(m)
	c.Assert(err, IsNil)
	err = u1.EnsureDying()
	c.Assert(err, IsNil)

	// When the deployer is started, in each case (1) no unit agent is deployed
	// and (2) the non-Alive unit is been removed from state.
	mgr := s.getManager(c, m.EntityName())
	dep := deployer.NewDeployer(s.State, mgr, m.WatchPrincipalUnits())
	defer stop(c, dep)
	s.waitFor(c, isRemoved(s.State, u0.Name()))
	s.waitFor(c, isRemoved(s.State, u1.Name()))
	s.waitFor(c, isDeployed(mgr))
}
Exemplo n.º 2
0
func (s *DeployerSuite) TestRemoveNonAlivePrincipals(c *C) {
	// Create a machine, and a couple of units.
	m, err := s.State.AddMachine("series", state.JobHostUnits)
	c.Assert(err, IsNil)
	svc, err := s.State.AddService("wordpress", s.AddTestingCharm(c, "wordpress"))
	c.Assert(err, IsNil)
	u0, err := svc.AddUnit()
	c.Assert(err, IsNil)
	u1, err := svc.AddUnit()
	c.Assert(err, IsNil)

	// Assign the units to the machine, and set them to Dying/Dead.
	err = u0.AssignToMachine(m)
	c.Assert(err, IsNil)
	err = u0.EnsureDead()
	c.Assert(err, IsNil)
	err = u1.AssignToMachine(m)
	c.Assert(err, IsNil)
	// note: this is not a sane state; for the unit to have a status it must
	// have been deployed. But it's instructive to check that the right thing
	// would happen if it were possible to have a dying unit in this situation.
	err = u1.SetStatus(params.StatusInstalled, "")
	c.Assert(err, IsNil)
	err = u1.Destroy()
	c.Assert(err, IsNil)

	// When the deployer is started, in each case (1) no unit agent is deployed
	// and (2) the non-Alive unit is been removed from state.
	ctx := s.getContext(c)
	dep := deployer.NewDeployer(s.State, ctx, m.Id())
	defer stop(c, dep)
	s.waitFor(c, isRemoved(s.State, u0.Name()))
	s.waitFor(c, isRemoved(s.State, u1.Name()))
	s.waitFor(c, isDeployed(ctx))
}
Exemplo n.º 3
0
func (s *DeployerSuite) TestNonAliveSubordinates(c *C) {
	// Add two subordinate units and set them to Dead/Dying respectively.
	u, rus := s.prepareSubordinates(c)
	err := rus[0].EnterScope(nil)
	c.Assert(err, IsNil)
	sub0, err := s.State.Unit("subsvc0/0")
	c.Assert(err, IsNil)
	err = sub0.EnsureDead()
	c.Assert(err, IsNil)
	err = rus[1].EnterScope(nil)
	c.Assert(err, IsNil)
	sub1, err := s.State.Unit("subsvc1/0")
	c.Assert(err, IsNil)
	err = sub1.Destroy()
	c.Assert(err, IsNil)

	// When we start a new deployer, neither unit will be deployed and
	// both will be removed.
	ctx := s.getContext(c)
	machineId, err := u.AssignedMachineId()
	c.Assert(err, IsNil)
	dep := deployer.NewDeployer(s.State, ctx, machineId)
	defer stop(c, dep)
	s.waitFor(c, isRemoved(s.State, sub0.Name()))
	s.waitFor(c, isRemoved(s.State, sub1.Name()))
}
Exemplo n.º 4
0
func (s *DeployerSuite) TestDeployRecallRemoveSubordinates(c *C) {
	// Create a deployer acting on behalf of the principal.
	u, rus := s.prepareSubordinates(c)
	mgr := s.getManager(c, u.EntityName())
	dep := deployer.NewDeployer(s.State, mgr, u.WatchSubordinateUnits())
	defer stop(c, dep)

	// Add a subordinate, and wait for it to be deployed.
	err := rus[0].EnterScope(nil)
	c.Assert(err, IsNil)
	sub0, err := s.State.Unit("subsvc0/0")
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(mgr, sub0.Name()))

	// And another.
	err = rus[1].EnterScope(nil)
	c.Assert(err, IsNil)
	sub1, err := s.State.Unit("subsvc1/0")
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(mgr, sub0.Name(), sub1.Name()))

	// Set one to Dying; check nothing happens.
	err = sub1.EnsureDying()
	c.Assert(err, IsNil)
	s.State.StartSync()
	c.Assert(isRemoved(s.State, sub1.Name())(c), Equals, false)
	s.waitFor(c, isDeployed(mgr, sub0.Name(), sub1.Name()))

	// Set the other to Dead; check it's recalled and removed.
	err = sub0.EnsureDead()
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(mgr, sub1.Name()))
	s.waitFor(c, isRemoved(s.State, sub0.Name()))
}
Exemplo n.º 5
0
func newDeployer(st *apideployer.State, machineTag string, dataDir string) (worker.Worker, error) {
	ctx, err := newDeployContext(st, dataDir)
	if err != nil {
		return nil, err
	}
	return deployer.NewDeployer(st, ctx, machineTag), nil
}
Exemplo n.º 6
0
func newDeployer(st *state.State, w *state.UnitsWatcher, dataDir string) *deployer.Deployer {
	info := &state.Info{
		EntityName: w.EntityName(),
		Addrs:      st.Addrs(),
		CACert:     st.CACert(),
	}
	mgr := newDeployManager(st, info, dataDir)
	return deployer.NewDeployer(st, mgr, w)
}
Exemplo n.º 7
0
func (s *DeployerSuite) TestDeployRecallRemovePrincipals(c *C) {
	// Create a machine, and a couple of units.
	m, err := s.State.AddMachine("series", state.JobHostUnits)
	c.Assert(err, IsNil)
	err = m.SetProvisioned("i-exist", "fake_nonce", nil)
	c.Assert(err, IsNil)
	svc, err := s.State.AddService("wordpress", s.AddTestingCharm(c, "wordpress"))
	c.Assert(err, IsNil)
	u0, err := svc.AddUnit()
	c.Assert(err, IsNil)
	u1, err := svc.AddUnit()
	c.Assert(err, IsNil)

	// Create a deployer acting on behalf of the machine.
	ctx := s.getContext(c)
	dep := deployer.NewDeployer(s.State, ctx, m.Id())
	defer stop(c, dep)

	// Assign one unit, and wait for it to be deployed.
	err = u0.AssignToMachine(m)
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(ctx, u0.Name()))

	// Assign another unit, and wait for that to be deployed.
	err = u1.AssignToMachine(m)
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(ctx, u0.Name(), u1.Name()))

	// Cause a unit to become Dying, and check no change.
	err = u1.SetStatus(params.StatusInstalled, "")
	c.Assert(err, IsNil)
	err = u1.Destroy()
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(ctx, u0.Name(), u1.Name()))

	// Cause a unit to become Dead, and check that it is both recalled and
	// removed from state.
	err = u0.EnsureDead()
	c.Assert(err, IsNil)
	s.waitFor(c, isRemoved(s.State, u0.Name()))
	s.waitFor(c, isDeployed(ctx, u1.Name()))

	// Remove the Dying unit from the machine, and check that it is recalled...
	err = u1.UnassignFromMachine()
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(ctx))

	// ...and that the deployer, no longer bearing any responsibility for the
	// Dying unit, does nothing further to it.
	err = u1.Refresh()
	c.Assert(err, IsNil)
	c.Assert(u1.Life(), Equals, state.Dying)
}
Exemplo n.º 8
0
func (s *DeployerSuite) TestDeployRecallRemovePrincipals(c *C) {
	// Create a machine, and a couple of units.
	m, err := s.State.AddMachine(state.JobHostUnits)
	c.Assert(err, IsNil)
	svc, err := s.State.AddService("wordpress", s.AddTestingCharm(c, "wordpress"))
	c.Assert(err, IsNil)
	u0, err := svc.AddUnit()
	c.Assert(err, IsNil)
	u1, err := svc.AddUnit()
	c.Assert(err, IsNil)

	// Create a deployer acting on behalf of the machine.
	mgr := s.getManager(c, m.EntityName())
	dep := deployer.NewDeployer(s.State, mgr, m.WatchPrincipalUnits())
	defer stop(c, dep)

	// Assign one unit, and wait for it to be deployed.
	err = u0.AssignToMachine(m)
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(mgr, u0.Name()))

	// Assign another unit, and wait for that to be deployed.
	err = u1.AssignToMachine(m)
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(mgr, u0.Name(), u1.Name()))

	// Cause a unit to become Dying, and check no change.
	err = u1.EnsureDying()
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(mgr, u0.Name(), u1.Name()))

	// Cause a unit to become Dead, and check that it is both recalled and
	// removed from state.
	err = u0.EnsureDead()
	c.Assert(err, IsNil)
	s.waitFor(c, isRemoved(s.State, u0.Name()))
	s.waitFor(c, isDeployed(mgr, u1.Name()))

	// Remove the Dying unit from the machine, and check that it is recalled...
	err = u1.UnassignFromMachine()
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(mgr))

	// ...and that the deployer, no longer bearing any responsibility for the
	// Dying unit, does nothing further to it.
	err = u1.Refresh()
	c.Assert(err, IsNil)
	c.Assert(u1.Life(), Equals, state.Dying)
}
Exemplo n.º 9
0
func (s *DeployerSuite) TestDeployRecallRemoveSubordinates(c *C) {
	// Create a deployer acting on behalf of the principal.
	u, rus := s.prepareSubordinates(c)
	ctx := s.getContext(c)
	machineId, err := u.AssignedMachineId()
	c.Assert(err, IsNil)
	dep := deployer.NewDeployer(s.State, ctx, machineId)
	defer stop(c, dep)

	// Add a subordinate, and wait for it to be deployed.
	err = rus[0].EnterScope(nil)
	c.Assert(err, IsNil)
	sub0, err := s.State.Unit("subsvc0/0")
	c.Assert(err, IsNil)
	// Make sure the principal is deployed first, then the subordinate
	s.waitFor(c, isDeployed(ctx, u.Name(), sub0.Name()))

	// And another.
	err = rus[1].EnterScope(nil)
	c.Assert(err, IsNil)
	sub1, err := s.State.Unit("subsvc1/0")
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(ctx, u.Name(), sub0.Name(), sub1.Name()))

	// Set one to Dying; check nothing happens.
	err = sub1.Destroy()
	c.Assert(err, IsNil)
	s.State.StartSync()
	c.Assert(isRemoved(s.State, sub1.Name())(c), Equals, false)
	s.waitFor(c, isDeployed(ctx, u.Name(), sub0.Name(), sub1.Name()))

	// Set the other to Dead; check it's recalled and removed.
	err = sub0.EnsureDead()
	c.Assert(err, IsNil)
	s.waitFor(c, isDeployed(ctx, u.Name(), sub1.Name()))
	s.waitFor(c, isRemoved(s.State, sub0.Name()))
}
Exemplo n.º 10
0
func (s *DeployerSuite) TestNonAliveSubordinates(c *C) {
	// Add two subordinate units and set them to Dead/Dying respectively.
	u, rus := s.prepareSubordinates(c)
	err := rus[0].EnterScope(nil)
	c.Assert(err, IsNil)
	sub0, err := s.State.Unit("subsvc0/0")
	c.Assert(err, IsNil)
	err = sub0.EnsureDead()
	c.Assert(err, IsNil)
	err = rus[1].EnterScope(nil)
	c.Assert(err, IsNil)
	sub1, err := s.State.Unit("subsvc1/0")
	c.Assert(err, IsNil)
	err = sub1.EnsureDying()
	c.Assert(err, IsNil)

	// When we start a new deployer, neither unit will be deployed and
	// both will be removed.
	mgr := s.getManager(c, u.EntityName())
	dep := deployer.NewDeployer(s.State, mgr, u.WatchSubordinateUnits())
	defer stop(c, dep)
	s.waitFor(c, isRemoved(s.State, sub0.Name()))
	s.waitFor(c, isRemoved(s.State, sub1.Name()))
}
Exemplo n.º 11
0
func newDeployer(st *state.State, machineId string, dataDir string) *deployer.Deployer {
	ctx := newDeployContext(st, dataDir)
	return deployer.NewDeployer(st, ctx, machineId)
}