Example #1
0
func (c *ensureAvailabilityCommand) getHAClient() (EnsureAvailabilityClient, error) {
	if c.haClient != nil {
		return c.haClient, nil
	}

	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Annotate(err, "cannot get API connection")
	}

	// NewClient does not return an error, so we'll return nil
	return highavailability.NewClient(root), nil
}
Example #2
0
func newEnableHACommand() cmd.Command {
	haCommand := &enableHACommand{}
	haCommand.newHAClientFunc = func() (MakeHAClient, error) {
		root, err := haCommand.NewAPIRoot()
		if err != nil {
			return nil, errors.Annotate(err, "cannot get API connection")
		}

		// NewClient does not return an error, so we'll return nil
		return highavailability.NewClient(root), nil
	}
	return modelcmd.Wrap(haCommand)
}
Example #3
0
func assertEnableHA(c *gc.C, s *jujutesting.JujuConnSuite) {
	_, err := s.State.AddMachine("quantal", state.JobManageModel)
	c.Assert(err, jc.ErrorIsNil)
	// We have to ensure the agents are alive, or EnableHA will
	// create more to replace them.
	pingerA := setAgentPresence(c, s, "0")
	defer assertKill(c, pingerA)

	emptyCons := constraints.Value{}
	client := highavailability.NewClient(s.APIState)
	result, err := client.EnableHA(3, emptyCons, "", nil)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(result.Maintained, gc.DeepEquals, []string{"machine-0"})
	c.Assert(result.Added, gc.DeepEquals, []string{"machine-1", "machine-2"})
	c.Assert(result.Removed, gc.HasLen, 0)

	machines, err := s.State.AllMachines()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(machines, gc.HasLen, 3)
	c.Assert(machines[0].Series(), gc.Equals, "quantal")
	c.Assert(machines[1].Series(), gc.Equals, "quantal")
	c.Assert(machines[2].Series(), gc.Equals, "quantal")
}
Example #4
0
func (s *clientSuite) TestClientEnableHAVersion(c *gc.C) {
	client := highavailability.NewClient(s.APIState)
	c.Assert(client.BestAPIVersion(), gc.Equals, 2)
}
Example #5
0
func (s *clientLegacySuite) TestEnsureAvailabilityLegacyRejectsPlacement(c *gc.C) {
	client := highavailability.NewClient(s.APIState)
	_, err := client.EnsureAvailability(3, constraints.Value{}, "", []string{"machine"})
	c.Assert(err, gc.ErrorMatches, "placement directives not supported with this version of Juju")
}