Skip to content

Commit

Permalink
state/service: GetOwnerTag return user tag
Browse files Browse the repository at this point in the history
Update service.GetOwnerTag() to return a names.UserTag instead of a
string.
  • Loading branch information
waigani committed Sep 9, 2014
1 parent 5a90b1c commit 9be2839
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
4 changes: 3 additions & 1 deletion apiserver/client/client_test.go
Expand Up @@ -893,7 +893,9 @@ func (s *clientSuite) TestClientServiceDeployServiceOwner(c *gc.C) {

service, err := s.State.Service("service")
c.Assert(err, gc.IsNil)
c.Assert(service.GetOwnerTag(), gc.Equals, user.Tag().String())
tag, err := service.GetOwnerTag()
c.Assert(err, gc.IsNil)
c.Assert(tag, gc.Equals, user.Tag())
}

func (s *clientSuite) deployServiceForTests(c *gc.C, store *charmtesting.MockCharmStore) {
Expand Down
6 changes: 5 additions & 1 deletion apiserver/uniter/uniter.go
Expand Up @@ -1250,8 +1250,12 @@ func (u *UniterAPI) GetOwnerTag(args params.Entities) (params.StringResult, erro
if err != nil {
return nothing, err
}
ownerTag, err := service.GetOwnerTag()
if err != nil {
return params.StringResult{}, errors.Trace(err)
}
return params.StringResult{
Result: service.GetOwnerTag(),
Result: ownerTag.String(),
}, nil
}

Expand Down
10 changes: 7 additions & 3 deletions juju/deploy_test.go
Expand Up @@ -69,19 +69,23 @@ func (s *DeployLocalSuite) TestDeployMinimal(c *gc.C) {
s.assertSettings(c, service, charm.Settings{})
s.assertConstraints(c, service, constraints.Value{})
s.assertMachines(c, service, constraints.Value{})
c.Assert(service.GetOwnerTag(), gc.Equals, s.AdminUserTag(c).String())
tag, err := service.GetOwnerTag()
c.Assert(err, gc.IsNil)
c.Assert(tag, gc.Equals, s.AdminUserTag(c))
}

func (s *DeployLocalSuite) TestDeployOwnerTag(c *gc.C) {
s.Factory.MakeUser(c, &factory.UserParams{Name: "foobar"})
user := s.Factory.MakeUser(c, &factory.UserParams{Name: "foobar"})
service, err := juju.DeployService(s.State,
juju.DeployServiceParams{
ServiceName: "bobwithowner",
Charm: s.charm,
ServiceOwner: "user-foobar",
})
c.Assert(err, gc.IsNil)
c.Assert(service.GetOwnerTag(), gc.Equals, "user-foobar")
tag, err := service.GetOwnerTag()
c.Assert(err, gc.IsNil)
c.Assert(tag, gc.Equals, user.Tag())
}

func (s *DeployLocalSuite) TestDeploySettings(c *gc.C) {
Expand Down
10 changes: 7 additions & 3 deletions state/service.go
Expand Up @@ -620,14 +620,18 @@ func (s *Service) addUnitOps(principalName string, asserts bson.D) (string, []tx

// SCHEMACHANGE
// TODO(mattyw) remove when schema upgrades are possible
func (s *Service) GetOwnerTag() string {
func (s *Service) GetOwnerTag() (names.UserTag, error) {
owner := s.doc.OwnerTag
if owner == "" {
// We know that if there was no owner, it was created with an early
// version of juju, and that admin was the only user.
owner = names.NewUserTag("admin").String()
return names.NewUserTag("admin"), nil
}
return owner
tag, err := names.ParseUserTag(s.doc.OwnerTag)
if err != nil {
return names.UserTag{}, errors.Trace(err)
}
return tag, nil
}

// AddUnit adds a new principal unit to the service.
Expand Down
4 changes: 3 additions & 1 deletion state/service_test.go
Expand Up @@ -1484,7 +1484,9 @@ func (s *ServiceSuite) TestOwnerTagSchemaProtection(c *gc.C) {
service := s.AddTestingService(c, "foobar", s.charm)
state.SetServiceOwnerTag(service, "")
c.Assert(state.GetServiceOwnerTag(service), gc.Equals, "")
c.Assert(service.GetOwnerTag(), gc.Equals, "user-admin")
tag, err := service.GetOwnerTag()
c.Assert(err, gc.IsNil)
c.Assert(tag, gc.Equals, s.owner)
}

func (s *ServiceSuite) TestNetworks(c *gc.C) {
Expand Down
4 changes: 3 additions & 1 deletion testing/factory/factory_test.go
Expand Up @@ -285,7 +285,9 @@ func (s *factorySuite) TestMakeService(c *gc.C) {
c.Assert(service, gc.NotNil)

c.Assert(service.Name(), gc.Equals, "wordpress")
c.Assert(service.GetOwnerTag(), gc.Equals, creator)
tag, err := service.GetOwnerTag()
c.Assert(err, gc.IsNil)
c.Assert(tag.String(), gc.Equals, creator)
curl, _ := service.CharmURL()
c.Assert(curl, gc.DeepEquals, charm.URL())

Expand Down

0 comments on commit 9be2839

Please sign in to comment.