Exemplo n.º 1
0
func (s *AddUnitsSuite) TestAddServiceUnits(c *C) {
	charm := s.AddTestingCharm(c, "dummy")
	svc, err := s.State.AddService("dummy-service", charm)
	c.Assert(err, IsNil)

	for i, t := range addUnitsTests {
		c.Logf("test %d. %s", i, t.about)
		units, err := statecmd.AddServiceUnits(s.State, params.AddServiceUnits{
			ServiceName:   t.service,
			ToMachineSpec: t.forceMachineSpec,
			NumUnits:      t.numUnits,
		})
		if t.err != "" {
			c.Assert(err, ErrorMatches, t.err)
		} else {
			c.Assert(err, IsNil)
			c.Assert(units, HasLen, t.numUnits)
			for _, unit := range units {
				c.Assert(unit.ServiceName(), Equals, t.service)
			}
			service, err := s.State.Service(t.service)
			c.Assert(err, IsNil)
			unitCount, err := service.AllUnits()
			c.Assert(err, IsNil)
			c.Assert(len(unitCount), Equals, t.expectedUnits)
		}
	}

	err = svc.Destroy()
	c.Assert(err, IsNil)
}
Exemplo n.º 2
0
// AddServiceUnits adds a given number of units to a service.
func (c *Client) AddServiceUnits(args params.AddServiceUnits) (params.AddServiceUnitsResults, error) {
	units, err := statecmd.AddServiceUnits(c.api.state, args)
	if err != nil {
		return params.AddServiceUnitsResults{}, err
	}
	unitNames := make([]string, len(units))
	for i, unit := range units {
		unitNames[i] = unit.String()
	}
	return params.AddServiceUnitsResults{Units: unitNames}, nil
}
Exemplo n.º 3
0
// Run connects to the environment specified on the command line
// and calls conn.AddUnits.
func (c *AddUnitCommand) Run(_ *cmd.Context) error {
	conn, err := juju.NewConnFromName(c.EnvName)
	if err != nil {
		return err
	}
	defer conn.Close()

	params := params.AddServiceUnits{
		ServiceName:   c.ServiceName,
		NumUnits:      c.NumUnits,
		ToMachineSpec: c.ToMachineSpec,
	}
	_, err = statecmd.AddServiceUnits(conn.State, params)
	return err
}