示例#1
0
func (s *workerSuite) TestErrorKillsWorker(c *gc.C) {
	s.AssertConfigParameterUpdated(c, "broken", "ReleaseAddress")
	w, err := addresser.NewWorker(s.State)
	c.Assert(err, jc.ErrorIsNil)
	defer worker.Stop(w)

	// The worker should have died with an error.

	stopErr := make(chan error)
	go func() {
		w.Wait()
		stopErr <- worker.Stop(w)
	}()

	select {
	case err := <-stopErr:
		msg := "failed to release address .*: dummy.ReleaseAddress is broken"
		c.Assert(err, gc.ErrorMatches, msg)
	case <-time.After(coretesting.LongWait):
		c.Fatalf("worker did not stop as expected")
	}

	// As we failed to release addresses they should not have been removed
	// from state.
	for _, digit := range []int{3, 4, 5, 6} {
		rawAddr := fmt.Sprintf("0.1.2.%d", digit)
		_, err := s.State.IPAddress(rawAddr)
		c.Assert(err, jc.ErrorIsNil)
	}
}
示例#2
0
func (s *workerSuite) TestWorkerRemovesDeadAddress(c *gc.C) {
	w, err := addresser.NewWorker(s.State)
	c.Assert(err, jc.ErrorIsNil)
	defer s.assertStop(c, w)
	s.waitForInitialDead(c)
	opsChan := dummyListen()

	addr, err := s.State.IPAddress("0.1.2.3")
	c.Assert(err, jc.ErrorIsNil)
	err = addr.EnsureDead()
	c.Assert(err, jc.ErrorIsNil)

	// Wait for ReleaseAddress attempt.
	op := waitForReleaseOp(c, opsChan)
	c.Assert(op, jc.DeepEquals, makeReleaseOp(3))

	// The address should have been removed from state.
	for a := common.ShortAttempt.Start(); a.Next(); {
		_, err := s.State.IPAddress("0.1.2.3")
		if errors.IsNotFound(err) {
			break
		}
		if !a.HasNext() {
			c.Fatalf("IP address not removed")
		}
	}
}
示例#3
0
func (s *workerSuite) TestMachineRemovalTriggersWorker(c *gc.C) {
	w, err := addresser.NewWorker(s.State)
	c.Assert(err, jc.ErrorIsNil)
	defer s.assertStop(c, w)
	s.waitForInitialDead(c)
	opsChan := dummyListen()

	machine, err := s.State.AddMachine("quantal", state.JobHostUnits)
	c.Assert(err, jc.ErrorIsNil)
	err = machine.SetProvisioned("foo", "really-fake", nil)
	c.Assert(err, jc.ErrorIsNil)
	s.State.StartSync()

	addr, err := s.State.AddIPAddress(network.NewAddress("0.1.2.9"), "foobar")
	c.Assert(err, jc.ErrorIsNil)
	err = addr.AllocateTo(machine.Id(), "foo")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(addr.InstanceId(), gc.Equals, instance.Id("foo"))
	s.State.StartSync()

	err = machine.EnsureDead()
	c.Assert(err, jc.ErrorIsNil)
	err = machine.Remove()
	c.Assert(err, jc.ErrorIsNil)

	err = addr.Refresh()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(addr.Life(), gc.Equals, state.Dead)

	// Wait for ReleaseAddress attempt.
	op := waitForReleaseOp(c, opsChan)
	c.Assert(op, jc.DeepEquals, makeReleaseOp(9))

	// The address should have been removed from state.
	for a := common.ShortAttempt.Start(); a.Next(); {
		_, err := s.State.IPAddress("0.1.2.9")
		if errors.IsNotFound(err) {
			break
		}
		if !a.HasNext() {
			c.Fatalf("IP address not removed")
		}
	}
}
示例#4
0
func (s *workerSuite) TestWorkerIgnoresAliveAddresses(c *gc.C) {
	w, err := addresser.NewWorker(s.State)
	c.Assert(err, jc.ErrorIsNil)
	defer s.assertStop(c, w)
	s.waitForInitialDead(c)

	// Add a new alive address.
	addr := network.NewAddress("0.1.2.9")
	ipAddr, err := s.State.AddIPAddress(addr, "foobar")
	c.Assert(err, jc.ErrorIsNil)
	err = ipAddr.AllocateTo(s.machine.Id(), "wobble")
	c.Assert(err, jc.ErrorIsNil)

	// The worker must not kill this address.
	for a := common.ShortAttempt.Start(); a.Next(); {
		ipAddr, err := s.State.IPAddress("0.1.2.9")
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(ipAddr.Life(), gc.Equals, state.Alive)
	}
}
示例#5
0
func (s *workerSuite) TestWorkerReleasesAlreadyDead(c *gc.C) {
	// we start with two dead addresses
	dead, err := s.State.DeadIPAddresses()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(dead, gc.HasLen, 2)

	opsChan := dummyListen()

	w, err := addresser.NewWorker(s.State)
	c.Assert(err, jc.ErrorIsNil)
	defer s.assertStop(c, w)
	s.waitForInitialDead(c)

	op1 := waitForReleaseOp(c, opsChan)
	op2 := waitForReleaseOp(c, opsChan)
	expected := []dummy.OpReleaseAddress{makeReleaseOp(4), makeReleaseOp(6)}

	// The machines are dead, so ReleaseAddress should be called with
	// instance.UnknownId.
	expected[0].InstanceId = instance.UnknownId
	expected[1].InstanceId = instance.UnknownId
	c.Assert([]dummy.OpReleaseAddress{op1, op2}, jc.SameContents, expected)
}
示例#6
0
func (s *workerSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)
	if s.Enabled {
		s.SetFeatureFlags(feature.AddressAllocation)
	}

	// Unbreak dummy provider methods.
	s.AssertConfigParameterUpdated(c, "broken", "")

	s.APIConnection, _ = s.OpenAPIAsNewMachine(c, state.JobManageModel)
	s.API = s.APIConnection.Addresser()

	machineA, err := s.State.AddMachine("quantal", state.JobHostUnits)
	s.MachineA = machineA
	c.Assert(err, jc.ErrorIsNil)
	err = s.MachineA.SetProvisioned("foo", "fake_nonce", nil)
	c.Assert(err, jc.ErrorIsNil)

	// This machine will be destroyed after address creation to test the
	// handling of addresses for machines that have gone.
	machineB, err := s.State.AddMachine("quantal", state.JobHostUnits)
	s.MachineB = machineB
	c.Assert(err, jc.ErrorIsNil)

	s.createAddresses(c)
	s.State.StartSync()

	s.OpsChan = make(chan dummy.Operation, 10)
	dummy.Listen(s.OpsChan)

	// Start the Addresser worker.
	w, err := addresser.NewWorker(s.API)
	c.Assert(err, jc.ErrorIsNil)
	s.Worker = w

	s.waitForInitialDead(c)
}