Exemplo n.º 1
0
func (s *ConstraintsSuite) TestParseConstraints(c *C) {
	for i, t := range parseConstraintsTests {
		c.Logf("test %d: %s", i, t.summary)
		cons0, err := constraints.Parse(t.args...)
		if t.err == "" {
			c.Assert(err, IsNil)
		} else {
			c.Assert(err, ErrorMatches, t.err)
			continue
		}
		cons1, err := constraints.Parse(cons0.String())
		c.Assert(err, IsNil)
		c.Assert(cons1, DeepEquals, cons0)
	}
}
Exemplo n.º 2
0
func (c *SetConstraintsCommand) Init(args []string) (err error) {
	if c.ServiceName != "" && !state.IsServiceName(c.ServiceName) {
		return fmt.Errorf("invalid service name %q", c.ServiceName)
	}
	c.Constraints, err = constraints.Parse(args...)
	return err
}
Exemplo n.º 3
0
func (s *ConstraintsSuite) TestRoundtripString(c *C) {
	for i, t := range constraintsRoundtripTests {
		c.Logf("test %d", i)
		cons, err := constraints.Parse(t.String())
		c.Assert(err, IsNil)
		c.Assert(cons, DeepEquals, t)
	}
}
Exemplo n.º 4
0
func (s *clientSuite) TestClientServiceUpdateAllParams(c *C) {
	store, restore := makeMockCharmStore()
	defer restore()
	s.deployServiceForTests(c, store)
	addCharm(c, store, "wordpress")

	// Update all the service attributes.
	minUnits := 3
	cons, err := constraints.Parse("mem=4096", "cpu-cores=2")
	c.Assert(err, IsNil)
	args := params.ServiceUpdate{
		ServiceName:     "service",
		CharmUrl:        "cs:precise/wordpress-3",
		ForceCharmUrl:   true,
		MinUnits:        &minUnits,
		SettingsStrings: map[string]string{"blog-title": "string-title"},
		SettingsYAML:    "service:\n  blog-title: yaml-title\n",
		Constraints:     &cons,
	}
	err = s.APIState.Client().ServiceUpdate(args)
	c.Assert(err, IsNil)

	// Ensure the service has been correctly updated.
	service, err := s.State.Service("service")
	c.Assert(err, IsNil)

	// Check the charm.
	ch, force, err := service.Charm()
	c.Assert(err, IsNil)
	c.Assert(ch.URL().String(), Equals, "cs:precise/wordpress-3")
	c.Assert(force, Equals, true)

	// Check the minimum number of units.
	c.Assert(service.MinUnits(), Equals, minUnits)

	// Check the settings: also ensure the YAML settings take precedence
	// over strings ones.
	expectedSettings := charm.Settings{"blog-title": "yaml-title"}
	obtainedSettings, err := service.ConfigSettings()
	c.Assert(err, IsNil)
	c.Assert(obtainedSettings, DeepEquals, expectedSettings)

	// Check the constraints.
	obtainedConstraints, err := service.Constraints()
	c.Assert(err, IsNil)
	c.Assert(obtainedConstraints, DeepEquals, cons)
}
Exemplo n.º 5
0
func (s *clientSuite) TestClientServiceUpdateSetConstraints(c *C) {
	service, err := s.State.AddService("dummy", s.AddTestingCharm(c, "dummy"))
	c.Assert(err, IsNil)

	// Update constraints for the service.
	cons, err := constraints.Parse("mem=4096", "cpu-cores=2")
	c.Assert(err, IsNil)
	args := params.ServiceUpdate{
		ServiceName: "dummy",
		Constraints: &cons,
	}
	err = s.APIState.Client().ServiceUpdate(args)
	c.Assert(err, IsNil)

	// Ensure the constraints have been correctly updated.
	obtained, err := service.Constraints()
	c.Assert(err, IsNil)
	c.Assert(obtained, DeepEquals, cons)
}