Skip to content

Commit

Permalink
Fix unit tests and rename common facade helper
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Oct 20, 2020
1 parent cf261d7 commit a3ce027
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package caas
package unitcommon

import (
"github.com/juju/errors"
Expand Down Expand Up @@ -38,9 +38,9 @@ func (b backend) ApplicationExists(name string) error {
return err
}

// CAASUnitAccessor returns an auth function which determines if the
// UnitAccessor returns an auth function which determines if the
// authenticated entity can access a unit or application.
func CAASUnitAccessor(authorizer facade.Authorizer, st ApplicationGetter) common.GetAuthFunc {
func UnitAccessor(authorizer facade.Authorizer, st ApplicationGetter) common.GetAuthFunc {
return func() (common.AuthFunc, error) {
switch tag := authorizer.GetAuthTag().(type) {
case names.ApplicationTag:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package caas_test
package unitcommon_test

import (
"github.com/juju/errors"
Expand All @@ -10,15 +10,15 @@ import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

"github.com/juju/juju/apiserver/common/caas"
"github.com/juju/juju/apiserver/common/unitcommon"
apiservertesting "github.com/juju/juju/apiserver/testing"
)

type CaasSuite struct {
type UnitAccessorSuite struct {
testing.IsolationSuite
}

var _ = gc.Suite(&CaasSuite{})
var _ = gc.Suite(&UnitAccessorSuite{})

type appGetter struct {
exits bool
Expand All @@ -31,11 +31,11 @@ func (a appGetter) ApplicationExists(name string) error {
return errors.NotFoundf("application %q", name)
}

func (s *CaasSuite) TestApplicationAgent(c *gc.C) {
func (s *UnitAccessorSuite) TestApplicationAgent(c *gc.C) {
auth := apiservertesting.FakeAuthorizer{
Tag: names.NewApplicationTag("gitlab"),
}
getAuthFunc := caas.CAASUnitAccessor(auth, appGetter{true})
getAuthFunc := unitcommon.UnitAccessor(auth, appGetter{true})
authFunc, err := getAuthFunc()
c.Assert(err, jc.ErrorIsNil)
ok := authFunc(names.NewUnitTag("gitlab/0"))
Expand All @@ -44,20 +44,20 @@ func (s *CaasSuite) TestApplicationAgent(c *gc.C) {
c.Assert(ok, jc.IsFalse)
}

func (s *CaasSuite) TestApplicationNotFound(c *gc.C) {
func (s *UnitAccessorSuite) TestApplicationNotFound(c *gc.C) {
auth := apiservertesting.FakeAuthorizer{
Tag: names.NewApplicationTag("gitlab"),
}
getAuthFunc := caas.CAASUnitAccessor(auth, appGetter{false})
getAuthFunc := unitcommon.UnitAccessor(auth, appGetter{false})
_, err := getAuthFunc()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}

func (s *CaasSuite) TestUnitAgent(c *gc.C) {
func (s *UnitAccessorSuite) TestUnitAgent(c *gc.C) {
auth := apiservertesting.FakeAuthorizer{
Tag: names.NewUnitTag("gitlab/0"),
}
getAuthFunc := caas.CAASUnitAccessor(auth, appGetter{true})
getAuthFunc := unitcommon.UnitAccessor(auth, appGetter{true})
authFunc, err := getAuthFunc()
c.Assert(err, jc.ErrorIsNil)
ok := authFunc(names.NewUnitTag("gitlab/0"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package caas_test
package unitcommon_test

import (
"testing"
Expand Down
8 changes: 4 additions & 4 deletions apiserver/facades/agent/caasoperator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/juju/names/v4"

"github.com/juju/juju/apiserver/common"
caasapi "github.com/juju/juju/apiserver/common/caas"
"github.com/juju/juju/apiserver/common/unitcommon"
"github.com/juju/juju/apiserver/facade"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/caas"
Expand Down Expand Up @@ -57,7 +57,7 @@ func NewStateFacade(ctx facade.Context) (*Facade, error) {
}
return NewFacade(resources, authorizer,
stateShim{ctx.State()},
caasapi.Backend(ctx.State()),
unitcommon.Backend(ctx.State()),
caasBroker, leadershipRevoker)
}

Expand All @@ -66,7 +66,7 @@ func NewFacade(
resources facade.Resources,
authorizer facade.Authorizer,
st CAASOperatorState,
appGetter caasapi.ApplicationGetter,
appGetter unitcommon.ApplicationGetter,
broker CAASBrokerInterface,
leadershipRevoker leadership.Revoker,
) (*Facade, error) {
Expand All @@ -81,7 +81,7 @@ func NewFacade(
common.AuthFuncForTagKind(names.ApplicationTagKind),
common.AuthFuncForTagKind(names.UnitTagKind),
)
accessUnit := caasapi.CAASUnitAccessor(authorizer, appGetter)
accessUnit := unitcommon.UnitAccessor(authorizer, appGetter)
return &Facade{
LifeGetter: common.NewLifeGetter(st, canRead),
APIAddresser: common.NewAPIAddresser(st, resources),
Expand Down
4 changes: 2 additions & 2 deletions apiserver/facades/agent/meterstatus/meterstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/juju/names/v4"

"github.com/juju/juju/apiserver/common"
caasapi "github.com/juju/juju/apiserver/common/caas"
"github.com/juju/juju/apiserver/common/unitcommon"
"github.com/juju/juju/apiserver/facade"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/controller"
Expand Down Expand Up @@ -86,7 +86,7 @@ func NewMeterStatusAPI(
return nil, common.ErrPerm
}

accessUnit := caasapi.CAASUnitAccessor(authorizer, caasapi.Backend(st))
accessUnit := unitcommon.UnitAccessor(authorizer, unitcommon.Backend(st))
return &MeterStatusAPI{
state: st,
accessUnit: accessUnit,
Expand Down
6 changes: 3 additions & 3 deletions apiserver/facades/agent/uniter/uniter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/juju/names/v4"

"github.com/juju/juju/apiserver/common"
caasapi "github.com/juju/juju/apiserver/common/caas"
"github.com/juju/juju/apiserver/common/cloudspec"
"github.com/juju/juju/apiserver/common/unitcommon"
"github.com/juju/juju/apiserver/facade"
leadershipapiserver "github.com/juju/juju/apiserver/facades/agent/leadership"
"github.com/juju/juju/apiserver/facades/agent/meterstatus"
Expand Down Expand Up @@ -179,7 +179,7 @@ func NewUniterAPI(context facade.Context) (*UniterAPI, error) {
return nil, errors.Trace(err)
}

accessUnit := caasapi.CAASUnitAccessor(authorizer, caasapi.Backend(st))
accessUnit := unitcommon.UnitAccessor(authorizer, unitcommon.Backend(st))
accessApplication := applicationAccessor(authorizer, st)
accessMachine := machineAccessor(authorizer, st)
accessCloudSpec := cloudSpecAccessor(authorizer, st)
Expand Down Expand Up @@ -304,7 +304,7 @@ func NewUniterAPIV11(context facade.Context) (*UniterAPIV11, error) {
authorizer := context.Auth()
st := context.State()
resources := context.Resources()
accessUnit := caasapi.CAASUnitAccessor(authorizer, caasapi.Backend(st))
accessUnit := unitcommon.UnitAccessor(authorizer, unitcommon.Backend(st))
return &UniterAPIV11{
LXDProfileAPI: NewExternalLXDProfileAPI(st, resources, authorizer, accessUnit, logger),
UniterAPIV12: *uniterAPI,
Expand Down
6 changes: 3 additions & 3 deletions apiserver/facades/client/client/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ func (s *CAASStatusSuite) TestStatusOperatorNotReady(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
c.Assert(status.Applications, gc.HasLen, 1)
clearSinceTimes(status)
s.assertUnitStatus(c, status.Applications[s.app.Name()], "waiting", "agent initializing")
s.assertUnitStatus(c, status.Applications[s.app.Name()], "waiting", "installing agent")
}

func (s *CAASStatusSuite) TestStatusPodSpecNotSet(c *gc.C) {
Expand All @@ -885,7 +885,7 @@ func (s *CAASStatusSuite) TestStatusPodSpecNotSet(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
c.Assert(status.Applications, gc.HasLen, 1)
clearSinceTimes(status)
s.assertUnitStatus(c, status.Applications[s.app.Name()], "waiting", "agent initializing")
s.assertUnitStatus(c, status.Applications[s.app.Name()], "waiting", "installing agent")
}

func (s *CAASStatusSuite) TestStatusPodSpecSet(c *gc.C) {
Expand Down Expand Up @@ -938,7 +938,7 @@ func (s *CAASStatusSuite) TestStatusCloudContainerSet(c *gc.C) {
func (s *CAASStatusSuite) assertUnitStatus(c *gc.C, appStatus params.ApplicationStatus, status, info string) {
curl, _ := s.app.CharmURL()
workloadVersion := ""
if info != "agent initializing" && info != "blocked" {
if info != "installing agent" && info != "blocked" {
workloadVersion = "gitlab/latest"
}
c.Assert(appStatus, jc.DeepEquals, params.ApplicationStatus{
Expand Down
2 changes: 1 addition & 1 deletion core/cache/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *ApplicationSuite) TestDisplayStatusOperatorWaiting(c *gc.C) {
Name: "test",
})
expected := s.status(status.Waiting, time.Now())
expected.Message = status.MessageInitializingAgent
expected.Message = status.MessageInstallingAgent
model.UpdateApplication(cache.ApplicationChange{
Name: "app",
Status: s.status(status.Active, time.Now()),
Expand Down
2 changes: 1 addition & 1 deletion core/status/caas.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ApplicationDisplayStatus(applicationStatus, operatorStatus StatusInfo, expe
}

if operatorStatus.Status == Waiting && !expectWorkload {
operatorStatus.Message = MessageInitializingAgent
operatorStatus.Message = MessageInstallingAgent
}
return operatorStatus

Expand Down
2 changes: 1 addition & 1 deletion core/status/caas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (s *UnitCloudStatusSuite) TestApplicatoinOpeartorStatusChoice(c *gc.C) {
Message: "unit",
},
expectWorkload: false,
messageCheck: "agent initializing",
messageCheck: "installing agent",
},
{
operatorStatus: status.StatusInfo{
Expand Down
2 changes: 1 addition & 1 deletion state/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func (op *DestroyUnitOperation) destroyOps() ([]txn.Op, error) {
}
// For CAAS models, check to see if the unit agent has started.
if agentStatusInfo.Status != status.Allocating {
return false
return true
}
// If the agent is still allocating, it may still be queued to run the install hook
// so check that the unit agent has started.
Expand Down

0 comments on commit a3ce027

Please sign in to comment.