Beispiel #1
0
func (s *AssignSuite) TestAssignUnitToNewMachineBecomesDirty(c *C) {
	_, err := s.State.AddMachine("series", state.JobManageEnviron) // bootstrap machine
	c.Assert(err, IsNil)

	// Set up constraints to specify we want to install into a container.
	econs := constraints.MustParse("container=lxc")
	err = s.State.SetEnvironConstraints(econs)
	c.Assert(err, IsNil)

	// Create some units and a clean machine.
	unit, err := s.wordpress.AddUnit()
	c.Assert(err, IsNil)
	anotherUnit, err := s.wordpress.AddUnit()
	c.Assert(err, IsNil)
	machine, err := s.State.AddMachine("series", state.JobHostUnits)
	c.Assert(err, IsNil)

	makeDirty := state.TransactionHook{
		Before: func() { c.Assert(unit.AssignToMachine(machine), IsNil) },
	}
	defer state.SetTransactionHooks(
		c, s.State, makeDirty,
	).Check()

	err = anotherUnit.AssignToNewMachineOrContainer()
	c.Assert(err, IsNil)

	mid, err := unit.AssignedMachineId()
	c.Assert(err, IsNil)
	c.Assert(mid, Equals, "1")

	mid, err = anotherUnit.AssignedMachineId()
	c.Assert(err, IsNil)
	c.Assert(mid, Equals, "2/lxc/0")
}
Beispiel #2
0
func (s *MachineSuite) TestDestroyContention(c *C) {
	svc, err := s.State.AddService("wordpress", s.AddTestingCharm(c, "wordpress"))
	c.Assert(err, IsNil)
	unit, err := svc.AddUnit()
	c.Assert(err, IsNil)

	perturb := state.TransactionHook{
		Before: func() { c.Assert(unit.AssignToMachine(s.machine), IsNil) },
		After:  func() { c.Assert(unit.UnassignFromMachine(), IsNil) },
	}
	defer state.SetTransactionHooks(
		c, s.State, perturb, perturb, perturb,
	).Check()
	err = s.machine.Destroy()
	c.Assert(err, ErrorMatches, "machine 0 cannot advance lifecycle: state changing too quickly; try again soon")
}
Beispiel #3
0
func (s *AssignSuite) TestAssignUnitToNewMachineBecomesHost(c *C) {
	_, err := s.State.AddMachine("series", state.JobManageEnviron) // bootstrap machine
	c.Assert(err, IsNil)

	// Set up constraints to specify we want to install into a container.
	econs := constraints.MustParse("container=lxc")
	err = s.State.SetEnvironConstraints(econs)
	c.Assert(err, IsNil)

	// Create a unit and a clean machine.
	unit, err := s.wordpress.AddUnit()
	c.Assert(err, IsNil)
	machine, err := s.State.AddMachine("series", state.JobHostUnits)
	c.Assert(err, IsNil)

	addContainer := state.TransactionHook{
		Before: func() {
			params := &state.AddMachineParams{
				Series:        "series",
				ParentId:      machine.Id(),
				ContainerType: instance.LXC,
				Jobs:          []state.MachineJob{state.JobHostUnits},
			}
			_, err := s.State.AddMachineWithConstraints(params)
			c.Assert(err, IsNil)
		},
	}
	defer state.SetTransactionHooks(
		c, s.State, addContainer,
	).Check()

	err = unit.AssignToNewMachineOrContainer()
	c.Assert(err, IsNil)

	mid, err := unit.AssignedMachineId()
	c.Assert(err, IsNil)
	c.Assert(mid, Equals, "2/lxc/0")
}