本文整理匯總了Golang中github.com/juju/juju/apiserver/service.AddCharmWithAuthorization函數的典型用法代碼示例。如果您正苦於以下問題:Golang AddCharmWithAuthorization函數的具體用法?Golang AddCharmWithAuthorization怎麽用?Golang AddCharmWithAuthorization使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AddCharmWithAuthorization函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestClientServiceSetCharmUnsupportedSeriesForce
func (s *serviceSuite) TestClientServiceSetCharmUnsupportedSeriesForce(c *gc.C) {
curl, _ := s.UploadCharmMultiSeries(c, "~who/multi-series", "multi-series")
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",
Series: "precise",
}}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Assert(results.Results[0].Error, gc.IsNil)
curl, _ = s.UploadCharmMultiSeries(c, "~who/multi-series2", "multi-series2")
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(),
ForceSeries: true,
})
c.Assert(err, jc.ErrorIsNil)
svc, err := s.State.Service("service")
c.Assert(err, jc.ErrorIsNil)
ch, _, err := svc.Charm()
c.Assert(err, jc.ErrorIsNil)
c.Assert(ch.URL().String(), gc.Equals, "cs:~who/multi-series2-0")
}
示例2: TestClientServiceSetCharmLegacy
func (s *serviceSuite) TestClientServiceSetCharmLegacy(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",
}}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Assert(results.Results[0].Error, gc.IsNil)
curl, _ = s.UploadCharm(c, "trusty/dummy-1", "dummy")
err = service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{URL: curl.String()})
c.Assert(err, jc.ErrorIsNil)
// Even with forceSeries = true, we can't change a charm where
// the series is sepcified in the URL.
err = s.serviceApi.ServiceSetCharm(params.ServiceSetCharm{
ServiceName: "service",
CharmUrl: curl.String(),
ForceSeries: true,
})
c.Assert(err, gc.ErrorMatches, "cannot change a service's series")
}
示例3: TestClientServiceSetCharmForceUnits
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)
}
示例4: TestClientServiceDeploySubordinate
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)
}
示例5: setupServiceDeploy
func (s *serviceSuite) setupServiceDeploy(c *gc.C, args string) (*charm.URL, charm.Charm, constraints.Value) {
curl, ch := s.UploadCharm(c, "precise/dummy-42", "dummy")
err := service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{URL: curl.String()})
c.Assert(err, jc.ErrorIsNil)
cons := constraints.MustParse(args)
return curl, ch, cons
}
示例6: setupServiceUpdate
func (s *serviceSuite) setupServiceUpdate(c *gc.C) string {
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)
return curl.String()
}
示例7: TestClientServiceDeployWithPlacement
func (s *serviceSuite) TestClientServiceDeployWithPlacement(c *gc.C) {
curl, ch := s.UploadCharm(c, "precise/dummy-42", "dummy")
err := service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{URL: curl.String()})
c.Assert(err, jc.ErrorIsNil)
var cons constraints.Value
args := params.ServiceDeploy{
ServiceName: "service",
CharmUrl: curl.String(),
NumUnits: 1,
Constraints: cons,
Placement: []*instance.Placement{
{"deadbeef-0bad-400d-8000-4b1d0d06f00d", "valid"},
},
ToMachineSpec: "will be ignored",
}
results, err := s.serviceApi.ServicesDeploy(params.ServicesDeploy{
Services: []params.ServiceDeploy{args}},
)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{{Error: nil}},
})
svc := apiservertesting.AssertPrincipalServiceDeployed(c, s.State, "service", curl, false, ch, cons)
units, err := svc.AllUnits()
c.Assert(err, jc.ErrorIsNil)
c.Assert(units, gc.HasLen, 1)
}
示例8: setupServiceSetCharm
func (s *serviceSuite) setupServiceSetCharm(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)
}
示例9: TestClientServiceSetCharmUnsupportedSeries
func (s *serviceSuite) TestClientServiceSetCharmUnsupportedSeries(c *gc.C) {
curl, _ := s.UploadCharmMultiSeries(c, "~who/multi-series", "multi-series")
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",
Series: "precise",
}}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Assert(results.Results[0].Error, gc.IsNil)
curl, _ = s.UploadCharmMultiSeries(c, "~who/multi-series", "multi-series2")
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(),
})
c.Assert(err, gc.ErrorMatches, "cannot upgrade charm, only these series are supported: trusty, wily")
}
示例10: TestClientServiceAddCharmErrors
func (s *serviceSuite) TestClientServiceAddCharmErrors(c *gc.C) {
for url, expect := range map[string]string{
"wordpress": "charm URL must include revision",
"cs:wordpress": "charm URL must include revision",
"cs:precise/wordpress": "charm URL must include revision",
"cs:precise/wordpress-999999": `cannot retrieve "cs:precise/wordpress-999999": charm not found`,
} {
c.Logf("test %s", url)
err := service.AddCharmWithAuthorization(s.State, params.AddCharmWithAuthorization{
URL: url,
})
c.Check(err, gc.ErrorMatches, expect)
}
}
示例11: TestClientServiceSetCharmWrongOS
func (s *serviceSuite) TestClientServiceSetCharmWrongOS(c *gc.C) {
curl, _ := s.UploadCharmMultiSeries(c, "~who/multi-series", "multi-series")
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",
Series: "precise",
}}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Assert(results.Results[0].Error, gc.IsNil)
curl, _ = s.UploadCharmMultiSeries(c, "~who/multi-series-windows", "multi-series-windows")
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(),
ForceSeries: true,
})
c.Assert(err, gc.ErrorMatches, `cannot upgrade charm, OS "Ubuntu" not supported by charm`)
}
示例12: TestClientServiceUpdateAllParams
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)
}
示例13: TestClientServiceDeployConfigError
func (s *serviceSuite) TestClientServiceDeployConfigError(c *gc.C) {
// TODO(fwereade): test Config/ConfigYAML handling directly on srvClient.
// Can't be done cleanly until it's extracted similarly to Machiner.
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-name",
NumUnits: 1,
ConfigYAML: "service-name:\n skill-level: fred",
}}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Assert(results.Results[0].Error, gc.ErrorMatches, `option "skill-level" expected int, got "fred"`)
_, err = s.State.Service("service-name")
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
示例14: TestClientServiceDeployServiceOwner
func (s *serviceSuite) TestClientServiceDeployServiceOwner(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)
service, err := s.State.Service("service")
c.Assert(err, jc.ErrorIsNil)
c.Assert(service.GetOwnerTag(), gc.Equals, s.authorizer.GetAuthTag().String())
}
示例15: TestClientServiceDeployConfig
func (s *serviceSuite) TestClientServiceDeployConfig(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-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)
settings, err := service.ConfigSettings()
c.Assert(err, jc.ErrorIsNil)
c.Assert(settings, gc.DeepEquals, charm.Settings{"username": "fred"})
}