Skip to content

Commit

Permalink
feat: model status facade method now handles domain model not found e…
Browse files Browse the repository at this point in the history
…rror;
  • Loading branch information
ycliuhw committed Dec 4, 2024
1 parent 073b66f commit 995193a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
4 changes: 0 additions & 4 deletions apiserver/facades/client/client/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ func (s stateShim) MongoSession() MongoSession {
return MongoSessionShim{s.State.MongoSession()}
}

type modelShim struct {
*state.Model
}

// MongoSessionShim wraps a *mgo.Session to conform to the
// MongoSession interface.
type MongoSessionShim struct {
Expand Down
12 changes: 6 additions & 6 deletions apiserver/facades/client/client/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/juju/juju/core/status"
coreunit "github.com/juju/juju/core/unit"
machineerrors "github.com/juju/juju/domain/machine/errors"
domainmodelerrors "github.com/juju/juju/domain/model/errors"
"github.com/juju/juju/domain/port"
"github.com/juju/juju/internal/charm"
internalerrors "github.com/juju/juju/internal/errors"
Expand Down Expand Up @@ -140,11 +141,6 @@ func (c *Client) machineStatusHistory(machineTag names.MachineTag, filter status
return agentStatusFromStatusInfo(sInfo, kind), nil
}

// modelStatusHistory returns status history for the current model.
func (c *Client) modelStatusHistory(status.StatusHistoryFilter) ([]params.DetailedStatus, error) {
return nil, internalerrors.Errorf("model status history not implemented")
}

// StatusHistory returns a slice of past statuses for several entities.
func (c *Client) StatusHistory(ctx context.Context, request params.StatusHistoryRequests) params.StatusHistoryResults {
results := params.StatusHistoryResults{}
Expand Down Expand Up @@ -181,7 +177,7 @@ func (c *Client) StatusHistory(ctx context.Context, request params.StatusHistory
kind := status.HistoryKind(request.Kind)
switch kind {
case status.KindModel:
hist, err = c.modelStatusHistory(filter)
err = internalerrors.Errorf("model status history not implemented")
case status.KindUnit, status.KindWorkload, status.KindUnitAgent:
var u names.UnitTag
if u, err = names.ParseUnitTag(request.Tag); err == nil {
Expand Down Expand Up @@ -587,6 +583,10 @@ func (c *Client) modelStatus(ctx context.Context) (params.ModelStatusInfo, error
// }

aStatus, err := c.modelInfoService.Status(ctx)
if internalerrors.Is(err, domainmodelerrors.NotFound) {
// This should never happen but just in case.
return params.ModelStatusInfo{}, errors.NotFoundf("model status for %q", modelInfo.Name)
}
if err != nil {
return params.ModelStatusInfo{}, errors.Annotate(err, "cannot obtain model status info")
}
Expand Down
21 changes: 21 additions & 0 deletions apiserver/facades/client/client/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"context"
"time"

"github.com/juju/errors"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/version/v2"
gomock "go.uber.org/mock/gomock"
gc "gopkg.in/check.v1"
Expand All @@ -17,6 +19,7 @@ import (
modeltesting "github.com/juju/juju/core/model/testing"
"github.com/juju/juju/core/status"
domainmodel "github.com/juju/juju/domain/model"
domainmodelerrors "github.com/juju/juju/domain/model/errors"
"github.com/juju/juju/rpc/params"
)

Expand Down Expand Up @@ -70,3 +73,21 @@ func (s *statusSuite) TestModelStatus(c *gc.C) {
},
})
}

func (s *statusSuite) TestModelStatusModelNotFound(c *gc.C) {
defer s.setupMocks(c).Finish()

s.modelInfoService.EXPECT().GetModelInfo(gomock.Any()).Return(model.ReadOnlyModel{
UUID: s.modelUUID,
Name: "model-name",
Type: model.IAAS,
Cloud: "mycloud",
CloudRegion: "region",
AgentVersion: version.MustParse("4.0.0"),
}, nil)
s.modelInfoService.EXPECT().Status(gomock.Any()).Return(domainmodel.StatusInfo{}, domainmodelerrors.NotFound)

client := &Client{modelInfoService: s.modelInfoService}
_, err := client.modelStatus(context.Background())
c.Assert(err, jc.ErrorIs, errors.NotFound)
}
8 changes: 0 additions & 8 deletions apiserver/facades/client/client/statushistory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,6 @@ func (m *mockState) Application(name string) (Application, error) {
}, nil
}

type mockModel struct {
status statuses
}

func (m mockModel) StatusHistory(filter status.StatusHistoryFilter) ([]status.StatusInfo, error) {
return m.status.StatusHistory(filter)
}

type mockApplication struct {
status statuses
Application
Expand Down

0 comments on commit 995193a

Please sign in to comment.