Skip to content

Commit

Permalink
Merge pull request juju#18744 from manadart/dqlite-model-detail-args
Browse files Browse the repository at this point in the history
juju#18744

The container type `ReadOnlyModelCreationArgs` was poorly named in that it reflects a detail from the underlying data store and easily becomes misnamed should that detail change.

This is the case due to requiring an `AgentVersion` member (patch forthcoming), which is not a read-only aspect.

Accordingly is is renamed `ModelDetailArgs`.
  • Loading branch information
jujubot authored Jan 29, 2025
2 parents 8c14e07 + 18cc059 commit e6c0c3e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion domain/agentprovisioner/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *suite) TestModelID(c *gc.C) {
// Create model info.
modelID := modeltesting.GenModelUUID(c)
modelSt := modelstate.NewModelState(s.TxnRunnerFactory(), loggertesting.WrapCheckLog(c))
err := modelSt.Create(context.Background(), model.ReadOnlyModelCreationArgs{
err := modelSt.Create(context.Background(), model.ModelDetailArgs{
UUID: modelID,
AgentVersion: version.Number{Major: 4, Minor: 21, Patch: 67},
ControllerUUID: uuid.MustNewUUID(),
Expand Down
2 changes: 1 addition & 1 deletion domain/keyupdater/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *stateSuite) TestGetModelId(c *gc.C) {
mst := modelstate.NewModelState(s.TxnRunnerFactory(), loggertesting.WrapCheckLog(c))

modelUUID := modeltesting.GenModelUUID(c)
args := model.ReadOnlyModelCreationArgs{
args := model.ModelDetailArgs{
UUID: modelUUID,
AgentVersion: jujuversion.Current,
ControllerUUID: uuid.MustNewUUID(),
Expand Down
2 changes: 1 addition & 1 deletion domain/model/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func CreateReadOnlyModel(
return fmt.Errorf("getting model for id %q: %w", id, err)
}

args := model.ReadOnlyModelCreationArgs{
args := model.ModelDetailArgs{
UUID: m.UUID,
AgentVersion: m.AgentVersion,
ControllerUUID: controllerUUID,
Expand Down
4 changes: 2 additions & 2 deletions domain/model/service/modelservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// database state, not the controller state.
type ModelState interface {
// Create creates a new model with all of its associated metadata.
Create(context.Context, model.ReadOnlyModelCreationArgs) error
Create(context.Context, model.ModelDetailArgs) error

// Delete deletes a model.
Delete(context.Context, coremodel.UUID) error
Expand Down Expand Up @@ -146,7 +146,7 @@ func (s *ModelService) CreateModel(
return err
}

args := model.ReadOnlyModelCreationArgs{
args := model.ModelDetailArgs{
UUID: m.UUID,
AgentVersion: m.AgentVersion,
ControllerUUID: controllerUUID,
Expand Down
16 changes: 8 additions & 8 deletions domain/model/service/modelservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ var _ = gc.Suite(&legacyModelServiceSuite{})

func (s *legacyModelServiceSuite) SetUpTest(c *gc.C) {
s.controllerState = &dummyControllerModelState{
models: map[coremodel.UUID]model.ReadOnlyModelCreationArgs{},
models: map[coremodel.UUID]model.ModelDetailArgs{},
modelState: map[coremodel.UUID]model.ModelState{},
}
s.modelState = &dummyModelState{
models: map[coremodel.UUID]model.ReadOnlyModelCreationArgs{},
models: map[coremodel.UUID]model.ModelDetailArgs{},
}

s.controllerUUID = uuid.MustNewUUID()
Expand All @@ -247,7 +247,7 @@ func (s *legacyModelServiceSuite) TestModelCreation(c *gc.C) {
id := modeltesting.GenModelUUID(c)
svc := NewModelService(id, s.controllerState, s.modelState, nil)

m := model.ReadOnlyModelCreationArgs{
m := model.ModelDetailArgs{
UUID: id,
Name: "my-awesome-model",
Cloud: "aws",
Expand Down Expand Up @@ -279,7 +279,7 @@ func (s *legacyModelServiceSuite) TestGetModelMetrics(c *gc.C) {
id := modeltesting.GenModelUUID(c)
svc := NewModelService(id, s.controllerState, s.modelState, nil)

m := model.ReadOnlyModelCreationArgs{
m := model.ModelDetailArgs{
UUID: id,
Name: "my-awesome-model",
Cloud: "aws",
Expand Down Expand Up @@ -312,7 +312,7 @@ func (s *legacyModelServiceSuite) TestModelDeletion(c *gc.C) {
id := modeltesting.GenModelUUID(c)
svc := NewModelService(id, s.controllerState, s.modelState, nil)

m := model.ReadOnlyModelCreationArgs{
m := model.ModelDetailArgs{
UUID: id,
Name: "my-awesome-model",
Cloud: "aws",
Expand Down Expand Up @@ -426,7 +426,7 @@ func (s *legacyModelServiceSuite) TestStatusFailedModelNotFound(c *gc.C) {
}

type dummyControllerModelState struct {
models map[coremodel.UUID]model.ReadOnlyModelCreationArgs
models map[coremodel.UUID]model.ModelDetailArgs
modelState map[coremodel.UUID]model.ModelState
}

Expand Down Expand Up @@ -462,7 +462,7 @@ func (d *dummyControllerModelState) GetModelState(_ context.Context, modelUUID c
}

type dummyModelState struct {
models map[coremodel.UUID]model.ReadOnlyModelCreationArgs
models map[coremodel.UUID]model.ModelDetailArgs
setID coremodel.UUID
}

Expand All @@ -474,7 +474,7 @@ func (d *dummyModelState) SetModelConstraints(_ context.Context, cons constraint
return nil
}

func (d *dummyModelState) Create(ctx context.Context, args model.ReadOnlyModelCreationArgs) error {
func (d *dummyModelState) Create(ctx context.Context, args model.ModelDetailArgs) error {
if d.setID != coremodel.UUID("") {
return modelerrors.AlreadyExists
}
Expand Down
6 changes: 3 additions & 3 deletions domain/model/service/package_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions domain/model/state/modelstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewModelState(
}

// Create creates a new read-only model.
func (s *ModelState) Create(ctx context.Context, args model.ReadOnlyModelCreationArgs) error {
func (s *ModelState) Create(ctx context.Context, args model.ModelDetailArgs) error {
db, err := s.DB()
if err != nil {
return errors.Capture(err)
Expand Down Expand Up @@ -274,7 +274,7 @@ func (s *ModelState) GetModelCloudType(ctx context.Context) (string, error) {
// CreateReadOnlyModel is responsible for creating a new model within the model
// database. If the model already exists then an error satisfying
// [modelerrors.AlreadyExists] is returned.
func CreateReadOnlyModel(ctx context.Context, args model.ReadOnlyModelCreationArgs, preparer domain.Preparer, tx *sqlair.TX) error {
func CreateReadOnlyModel(ctx context.Context, args model.ModelDetailArgs, preparer domain.Preparer, tx *sqlair.TX) error {
// This is some defensive programming. The zero value of agent version is
// still valid but should really be considered null for the purposes of
// allowing the DDL to assert constraints.
Expand Down
18 changes: 9 additions & 9 deletions domain/model/state/modelstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *modelSuite) TestCreateAndReadModel(c *gc.C) {
state := NewModelState(runner, loggertesting.WrapCheckLog(c))

id := modeltesting.GenModelUUID(c)
args := model.ReadOnlyModelCreationArgs{
args := model.ModelDetailArgs{
UUID: id,
AgentVersion: jujuversion.Current,
ControllerUUID: s.controllerUUID,
Expand Down Expand Up @@ -75,7 +75,7 @@ func (s *modelSuite) TestDeleteModel(c *gc.C) {
state := NewModelState(runner, loggertesting.WrapCheckLog(c))

id := modeltesting.GenModelUUID(c)
args := model.ReadOnlyModelCreationArgs{
args := model.ModelDetailArgs{
UUID: id,
AgentVersion: jujuversion.Current,
ControllerUUID: s.controllerUUID,
Expand Down Expand Up @@ -108,7 +108,7 @@ func (s *modelSuite) TestCreateModelMultipleTimesWithSameUUID(c *gc.C) {
// Ensure that we can't create the same model twice.

id := modeltesting.GenModelUUID(c)
args := model.ReadOnlyModelCreationArgs{
args := model.ModelDetailArgs{
UUID: id,
AgentVersion: jujuversion.Current,
ControllerUUID: s.controllerUUID,
Expand All @@ -130,7 +130,7 @@ func (s *modelSuite) TestCreateModelMultipleTimesWithDifferentUUID(c *gc.C) {

// Ensure that you can only ever insert one model.

err := state.Create(context.Background(), model.ReadOnlyModelCreationArgs{
err := state.Create(context.Background(), model.ModelDetailArgs{
UUID: modeltesting.GenModelUUID(c),
AgentVersion: jujuversion.Current,
Name: "my-awesome-model",
Expand All @@ -141,7 +141,7 @@ func (s *modelSuite) TestCreateModelMultipleTimesWithDifferentUUID(c *gc.C) {
})
c.Assert(err, jc.ErrorIsNil)

err = state.Create(context.Background(), model.ReadOnlyModelCreationArgs{
err = state.Create(context.Background(), model.ModelDetailArgs{
UUID: modeltesting.GenModelUUID(c),
AgentVersion: jujuversion.Current,
Name: "my-awesome-model",
Expand All @@ -160,7 +160,7 @@ func (s *modelSuite) TestCreateModelAndUpdate(c *gc.C) {
// Ensure that you can't update it.

id := modeltesting.GenModelUUID(c)
err := state.Create(context.Background(), model.ReadOnlyModelCreationArgs{
err := state.Create(context.Background(), model.ModelDetailArgs{
UUID: id,
AgentVersion: jujuversion.Current,
ControllerUUID: s.controllerUUID,
Expand All @@ -184,7 +184,7 @@ func (s *modelSuite) TestCreateModelAndDelete(c *gc.C) {
// Ensure that you can't update it.

id := modeltesting.GenModelUUID(c)
err := state.Create(context.Background(), model.ReadOnlyModelCreationArgs{
err := state.Create(context.Background(), model.ModelDetailArgs{
UUID: id,
AgentVersion: jujuversion.Current,
Name: "my-awesome-model",
Expand Down Expand Up @@ -213,7 +213,7 @@ func (s *modelSuite) TestGetModelMetrics(c *gc.C) {
state := NewModelState(runner, loggertesting.WrapCheckLog(c))

id := modeltesting.GenModelUUID(c)
args := model.ReadOnlyModelCreationArgs{
args := model.ModelDetailArgs{
UUID: id,
AgentVersion: jujuversion.Current,
ControllerUUID: s.controllerUUID,
Expand Down Expand Up @@ -274,7 +274,7 @@ func (s *modelSuite) TestGetModelCloudType(c *gc.C) {

id := modeltesting.GenModelUUID(c)
cloudType := "ec2"
args := model.ReadOnlyModelCreationArgs{
args := model.ModelDetailArgs{
UUID: id,
AgentVersion: jujuversion.Current,
ControllerUUID: s.controllerUUID,
Expand Down
4 changes: 2 additions & 2 deletions domain/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func (m ModelImportArgs) Validate() error {
return nil
}

// ReadOnlyModelCreationArgs is a struct that is used to create a model
// ModelDetailArgs is a struct that is used to create a model
// within the model database. This struct is used to create a model with all of
// its associated metadata.
type ReadOnlyModelCreationArgs struct {
type ModelDetailArgs struct {
// UUID represents the unique id for the model when being created. This
// value is optional and if omitted will be generated for the caller. Use
// this value when you are trying to import a model during model migration.
Expand Down
2 changes: 1 addition & 1 deletion domain/modelmigration/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *migrationSuite) SetUpTest(c *gc.C) {
state := modelstate.NewModelState(runner, loggertesting.WrapCheckLog(c))

id := modeltesting.GenModelUUID(c)
args := model.ReadOnlyModelCreationArgs{
args := model.ModelDetailArgs{
UUID: id,
AgentVersion: jujuversion.Current,
ControllerUUID: s.controllerUUID,
Expand Down

0 comments on commit e6c0c3e

Please sign in to comment.