func (s *serviceSuite) TestClientServiceDeploySubordinate(c *gc.C) { curl, ch := s.UploadCharm(c, "utopic/logging-47", "logging") err := service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{URL: curl.String()}) c.Assert(err, jc.ErrorIsNil) results, err := s.serviceApi.ServicesDeploy(params.ServicesDeploy{ Services: []params.ServiceDeploy{{ CharmUrl: curl.String(), ServiceName: "service-name", }}}) c.Assert(err, jc.ErrorIsNil) c.Assert(results.Results, gc.HasLen, 1) c.Assert(results.Results[0].Error, gc.IsNil) service, err := s.State.Service("service-name") c.Assert(err, jc.ErrorIsNil) charm, force, err := service.Charm() c.Assert(err, jc.ErrorIsNil) c.Assert(force, jc.IsFalse) c.Assert(charm.URL(), gc.DeepEquals, curl) c.Assert(charm.Meta(), gc.DeepEquals, ch.Meta()) c.Assert(charm.Config(), gc.DeepEquals, ch.Config()) units, err := service.AllUnits() c.Assert(err, jc.ErrorIsNil) c.Assert(units, gc.HasLen, 0) }
func (s *serviceSuite) TestClientServiceSetCharmForceUnits(c *gc.C) { curl, _ := s.UploadCharm(c, "precise/dummy-0", "dummy") err := service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{URL: curl.String()}) c.Assert(err, jc.ErrorIsNil) results, err := s.serviceApi.ServicesDeploy(params.ServicesDeploy{ Services: []params.ServiceDeploy{{ CharmUrl: curl.String(), ServiceName: "service", NumUnits: 3, }}}) c.Assert(err, jc.ErrorIsNil) c.Assert(results.Results, gc.HasLen, 1) c.Assert(results.Results[0].Error, gc.IsNil) curl, _ = s.UploadCharm(c, "precise/wordpress-3", "wordpress") err = service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{URL: curl.String()}) c.Assert(err, jc.ErrorIsNil) err = s.serviceApi.ServiceSetCharm(params.ServiceSetCharm{ ServiceName: "service", CharmUrl: curl.String(), ForceUnits: true, }) c.Assert(err, jc.ErrorIsNil) // Ensure that the charm is marked as forced. service, err := s.State.Service("service") c.Assert(err, jc.ErrorIsNil) charm, force, err := service.Charm() c.Assert(err, jc.ErrorIsNil) c.Assert(charm.URL().String(), gc.Equals, curl.String()) c.Assert(force, jc.IsTrue) }
func (s *serviceSuite) TestBlockServiceUpdateForced(c *gc.C) { curl := s.setupServiceUpdate(c) // block all changes. Force should ignore block :) s.BlockAllChanges(c, "TestBlockServiceUpdateForced") s.BlockDestroyEnvironment(c, "TestBlockServiceUpdateForced") s.BlockRemoveObject(c, "TestBlockServiceUpdateForced") // Update the charm for the service. args := params.ServiceUpdate{ ServiceName: "service", CharmUrl: curl, ForceCharmUrl: true, } err := s.serviceApi.ServiceUpdate(args) c.Assert(err, jc.ErrorIsNil) // Ensure the charm has been updated and and the force flag correctly set. service, err := s.State.Service("service") c.Assert(err, jc.ErrorIsNil) ch, force, err := service.Charm() c.Assert(err, jc.ErrorIsNil) c.Assert(ch.URL().String(), gc.Equals, curl) c.Assert(force, jc.IsTrue) }
func (s *serviceSuite) assertServiceSetCharm(c *gc.C, forceUnits bool) { err := s.serviceApi.ServiceSetCharm(params.ServiceSetCharm{ ServiceName: "service", CharmUrl: "cs:~who/precise/wordpress-3", ForceUnits: forceUnits, }) c.Assert(err, jc.ErrorIsNil) // Ensure that the charm is not marked as forced. service, err := s.State.Service("service") c.Assert(err, jc.ErrorIsNil) charm, _, err := service.Charm() c.Assert(err, jc.ErrorIsNil) c.Assert(charm.URL().String(), gc.Equals, "cs:~who/precise/wordpress-3") }
func (s *serviceSuite) TestClientServiceUpdateAllParams(c *gc.C) { s.deployServiceForUpdateTests(c) curl, _ := s.UploadCharm(c, "precise/wordpress-3", "wordpress") err := service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{URL: curl.String()}) c.Assert(err, jc.ErrorIsNil) // Update all the service attributes. minUnits := 3 cons, err := constraints.Parse("mem=4096", "cpu-cores=2") c.Assert(err, jc.ErrorIsNil) args := params.ServiceUpdate{ ServiceName: "service", CharmUrl: curl.String(), ForceCharmUrl: true, MinUnits: &minUnits, SettingsStrings: map[string]string{"blog-title": "string-title"}, SettingsYAML: "service:\n blog-title: yaml-title\n", Constraints: &cons, } err = s.serviceApi.ServiceUpdate(args) c.Assert(err, jc.ErrorIsNil) // Ensure the service has been correctly updated. service, err := s.State.Service("service") c.Assert(err, jc.ErrorIsNil) // Check the charm. ch, force, err := service.Charm() c.Assert(err, jc.ErrorIsNil) c.Assert(ch.URL().String(), gc.Equals, curl.String()) c.Assert(force, jc.IsTrue) // Check the minimum number of units. c.Assert(service.MinUnits(), gc.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, jc.ErrorIsNil) c.Assert(obtainedSettings, gc.DeepEquals, expectedSettings) // Check the constraints. obtainedConstraints, err := service.Constraints() c.Assert(err, jc.ErrorIsNil) c.Assert(obtainedConstraints, gc.DeepEquals, cons) }
func (s *serviceSuite) TestClientServiceDeployToMachine(c *gc.C) { curl, ch := s.UploadCharm(c, "precise/dummy-0", "dummy") err := service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{URL: curl.String()}) c.Assert(err, jc.ErrorIsNil) machine, err := s.State.AddMachine("precise", state.JobHostUnits) c.Assert(err, jc.ErrorIsNil) results, err := s.serviceApi.ServicesDeploy(params.ServicesDeploy{ Services: []params.ServiceDeploy{{ CharmUrl: curl.String(), ServiceName: "service-name", NumUnits: 1, ConfigYAML: "service-name:\n username: fred", }}}) c.Assert(err, jc.ErrorIsNil) c.Assert(results.Results, gc.HasLen, 1) c.Assert(results.Results[0].Error, gc.IsNil) service, err := s.State.Service("service-name") c.Assert(err, jc.ErrorIsNil) charm, force, err := service.Charm() c.Assert(err, jc.ErrorIsNil) c.Assert(force, jc.IsFalse) c.Assert(charm.URL(), gc.DeepEquals, curl) c.Assert(charm.Meta(), gc.DeepEquals, ch.Meta()) c.Assert(charm.Config(), gc.DeepEquals, ch.Config()) errs, err := s.APIState.UnitAssigner().AssignUnits([]names.UnitTag{names.NewUnitTag("service-name/0")}) c.Assert(errs, gc.DeepEquals, []error{nil}) c.Assert(err, jc.ErrorIsNil) units, err := service.AllUnits() c.Assert(err, jc.ErrorIsNil) c.Assert(units, gc.HasLen, 1) mid, err := units[0].AssignedMachineId() c.Assert(err, jc.ErrorIsNil) c.Assert(mid, gc.Equals, machine.Id()) }
func (s *serviceSuite) checkClientServiceUpdateSetCharm(c *gc.C, forceCharmUrl bool) { s.deployServiceForUpdateTests(c) curl, _ := s.UploadCharm(c, "precise/wordpress-3", "wordpress") err := service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{URL: curl.String()}) c.Assert(err, jc.ErrorIsNil) // Update the charm for the service. args := params.ServiceUpdate{ ServiceName: "service", CharmUrl: curl.String(), ForceCharmUrl: forceCharmUrl, } err = s.serviceApi.ServiceUpdate(args) c.Assert(err, jc.ErrorIsNil) // Ensure the charm has been updated and and the force flag correctly set. service, err := s.State.Service("service") c.Assert(err, jc.ErrorIsNil) ch, force, err := service.Charm() c.Assert(err, jc.ErrorIsNil) c.Assert(ch.URL().String(), gc.Equals, curl.String()) c.Assert(force, gc.Equals, forceCharmUrl) }