From 3d792b1394e6ff99cf66530fc662df51be59a0ac Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Wed, 27 Nov 2024 14:15:19 +0100 Subject: [PATCH] *** WIP. ROLL BACK. *** --- agent/agentbootstrap/bootstrap.go | 34 ++++--- .../facades/client/client/status_test.go | 2 +- .../client/modelmanager/mocks/service_mock.go | 6 +- .../client/modelmanager/modelmanager.go | 22 ++--- .../client/modelmanager/modelmanager_test.go | 6 +- .../facades/client/modelmanager/services.go | 2 +- domain/agentprovisioner/state/state_test.go | 2 +- domain/cloud/state/state_test.go | 2 +- domain/keyupdater/keyupdater_test.go | 4 +- domain/keyupdater/state/state_test.go | 2 +- domain/model/bootstrap/bootstrap.go | 67 ++++++-------- domain/model/bootstrap/bootstrap_test.go | 14 +-- domain/model/modelmigration/import.go | 2 +- domain/model/modelmigration/import_test.go | 8 +- domain/model/service/modelservice.go | 5 +- domain/model/service/modelservice_test.go | 10 +- domain/model/service/service.go | 12 +-- domain/model/service/service_test.go | 48 +++++----- domain/model/service/state_test.go | 2 +- domain/model/state/controllerstate.go | 8 +- domain/model/state/controllerstate_test.go | 46 +++++----- domain/model/state/modelstate.go | 62 ++++++------- domain/model/state/modelstate_test.go | 14 +-- domain/model/state/testing/model.go | 2 +- domain/model/types.go | 92 ++++++++++--------- domain/model/types_test.go | 22 ++--- .../modelconfig/bootstrap/bootstrap_test.go | 4 +- domain/modelconfig/modelconfig_test.go | 4 +- domain/modelmigration/state/state_test.go | 2 +- domain/secretbackend/state/state_test.go | 2 +- domain/services/testing/suite.go | 12 +-- 31 files changed, 261 insertions(+), 259 deletions(-) diff --git a/agent/agentbootstrap/bootstrap.go b/agent/agentbootstrap/bootstrap.go index 3f7b2ac3c46..3cfc8dd90f3 100644 --- a/agent/agentbootstrap/bootstrap.go +++ b/agent/agentbootstrap/bootstrap.go @@ -6,6 +6,9 @@ package agentbootstrap import ( stdcontext "context" "fmt" + jujuversion "github.com/juju/juju/core/version" + modelerrors "github.com/juju/juju/domain/model/errors" + "github.com/juju/version/v2" "github.com/juju/clock" "github.com/juju/errors" @@ -225,15 +228,14 @@ func (b *AgentBootstrap) Initialize(ctx stdcontext.Context) (_ *state.Controller }, ) - controllerModelArgs := modeldomain.ModelCreationArgs{ - AgentVersion: stateParams.AgentVersion, - Name: stateParams.ControllerModelConfig.Name(), - Owner: adminUserUUID, - Cloud: stateParams.ControllerCloud.Name, - CloudRegion: stateParams.ControllerCloudRegion, - Credential: credential.KeyFromTag(cloudCredTag), + controllerModelArgs := modeldomain.ControllerDBModelCreationArgs{ + Name: stateParams.ControllerModelConfig.Name(), + Owner: adminUserUUID, + Cloud: stateParams.ControllerCloud.Name, + CloudRegion: stateParams.ControllerCloudRegion, + Credential: credential.KeyFromTag(cloudCredTag), } - controllerModelCreateFunc := modelbootstrap.CreateModel(controllerModelUUID, controllerModelArgs) + controllerModelCreateFunc := modelbootstrap.CreateControllerDBModelRecord(controllerModelUUID, controllerModelArgs) controllerModelDefaults := modeldefaultsbootstrap.ModelDefaultsProvider( stateParams.ControllerInheritedConfig, @@ -247,6 +249,14 @@ func (b *AgentBootstrap) Initialize(ctx stdcontext.Context) (_ *state.Controller modelType = state.ModelTypeCAAS } + agentVersion := stateParams.AgentVersion + if agentVersion == version.Zero { + agentVersion = jujuversion.Current + } + if agentVersion.Major != jujuversion.Current.Major || agentVersion.Minor != jujuversion.Current.Minor { + return nil, fmt.Errorf("%w %q during bootstrap", modelerrors.AgentVersionNotSupported, agentVersion) + } + databaseBootstrapOptions := []database.BootstrapOpt{ // The controller config needs to be inserted before the admin users // because the admin users permissions require the controller UUID. @@ -259,15 +269,17 @@ func (b *AgentBootstrap) Initialize(ctx stdcontext.Context) (_ *state.Controller modeldefaultsbootstrap.SetCloudDefaults(stateParams.ControllerCloud.Name, stateParams.ControllerInheritedConfig), secretbackendbootstrap.CreateDefaultBackends(model.ModelType(modelType)), controllerModelCreateFunc, - modelbootstrap.CreateReadOnlyModel(controllerModelUUID, controllerUUID), - modelconfigbootstrap.SetModelConfig(controllerModelUUID, stateParams.ControllerModelConfig.AllAttrs(), controllerModelDefaults), + modelbootstrap.CreateModelDBModelRecord(controllerModelUUID, controllerUUID, agentVersion), + modelconfigbootstrap.SetModelConfig( + controllerModelUUID, stateParams.ControllerModelConfig.AllAttrs(), controllerModelDefaults), } if !isCAAS { databaseBootstrapOptions = append(databaseBootstrapOptions, // TODO(wallyworld) - this is just a placeholder for now machinebootstrap.InsertMachine(agent.BootstrapControllerId), - cloudimagemetadatabootstrap.AddCustomImageMetadata(clock.WallClock, stateParams.ControllerModelConfig.ImageStream(), stateParams.CustomImageMetadata), + cloudimagemetadatabootstrap.AddCustomImageMetadata( + clock.WallClock, stateParams.ControllerModelConfig.ImageStream(), stateParams.CustomImageMetadata), ) } diff --git a/apiserver/facades/client/client/status_test.go b/apiserver/facades/client/client/status_test.go index 4bdc9f79165..5026f10a489 100644 --- a/apiserver/facades/client/client/status_test.go +++ b/apiserver/facades/client/client/status_test.go @@ -529,7 +529,7 @@ func (s *statusUnitTestSuite) TestMigrationInProgress(c *gc.C) { // Double-write model information to dqlite. // Add the model to the model database. err = s.ModelTxnRunner(c, model2.UUID()).Txn(context.Background(), func(ctx context.Context, tx *sqlair.TX) error { - return modelstate.CreateReadOnlyModel(ctx, domainmodel.ReadOnlyModelCreationArgs{ + return modelstate.CreateReadOnlyModel(ctx, domainmodel.ReadOnlyModelRecordArgs{ UUID: coremodel.UUID(model2.UUID()), Name: model2.Name(), Cloud: "dummy", diff --git a/apiserver/facades/client/modelmanager/mocks/service_mock.go b/apiserver/facades/client/modelmanager/mocks/service_mock.go index 26291ba1ffe..1b71d78fb1d 100644 --- a/apiserver/facades/client/modelmanager/mocks/service_mock.go +++ b/apiserver/facades/client/modelmanager/mocks/service_mock.go @@ -359,7 +359,7 @@ func (m *MockModelService) EXPECT() *MockModelServiceMockRecorder { } // CreateModel mocks base method. -func (m *MockModelService) CreateModel(arg0 context.Context, arg1 model0.ModelCreationArgs) (model.UUID, func(context.Context) error, error) { +func (m *MockModelService) CreateModel(arg0 context.Context, arg1 model0.ControllerDBModelCreationArgs) (model.UUID, func(context.Context) error, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateModel", arg0, arg1) ret0, _ := ret[0].(model.UUID) @@ -387,13 +387,13 @@ func (c *MockModelServiceCreateModelCall) Return(arg0 model.UUID, arg1 func(cont } // Do rewrite *gomock.Call.Do -func (c *MockModelServiceCreateModelCall) Do(f func(context.Context, model0.ModelCreationArgs) (model.UUID, func(context.Context) error, error)) *MockModelServiceCreateModelCall { +func (c *MockModelServiceCreateModelCall) Do(f func(context.Context, model0.ControllerDBModelCreationArgs) (model.UUID, func(context.Context) error, error)) *MockModelServiceCreateModelCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockModelServiceCreateModelCall) DoAndReturn(f func(context.Context, model0.ModelCreationArgs) (model.UUID, func(context.Context) error, error)) *MockModelServiceCreateModelCall { +func (c *MockModelServiceCreateModelCall) DoAndReturn(f func(context.Context, model0.ControllerDBModelCreationArgs) (model.UUID, func(context.Context) error, error)) *MockModelServiceCreateModelCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/apiserver/facades/client/modelmanager/modelmanager.go b/apiserver/facades/client/modelmanager/modelmanager.go index cf4aa832454..53fe747716e 100644 --- a/apiserver/facades/client/modelmanager/modelmanager.go +++ b/apiserver/facades/client/modelmanager/modelmanager.go @@ -205,7 +205,7 @@ func (m *ModelManagerAPI) createModelNew( // if there was an error. If a failure to rollback occurs, then the endpoint // should at least be somewhat idempotent. - creationArgs := model.ModelCreationArgs{ + creationArgs := model.ControllerDBModelCreationArgs{ CloudRegion: args.CloudRegion, Name: args.Name, } @@ -216,7 +216,7 @@ func (m *ModelManagerAPI) createModelNew( // we will try and apply the defaults where authorisation allows us to. defaultCloudName, _, err := m.modelService.DefaultModelCloudNameAndCredential(ctx) if errors.Is(err, modelerrors.NotFound) { - return coremodel.UUID(""), errors.New("failed to find default model cloud and credential for controller") + return "", errors.New("failed to find default model cloud and credential for controller") } var cloudTag names.CloudTag @@ -224,7 +224,7 @@ func (m *ModelManagerAPI) createModelNew( var err error cloudTag, err = names.ParseCloudTag(args.CloudTag) if err != nil { - return coremodel.UUID(""), errors.Trace(err) + return "", errors.Trace(err) } } else { cloudTag = names.NewCloudTag(defaultCloudName) @@ -233,33 +233,33 @@ func (m *ModelManagerAPI) createModelNew( err = m.authorizer.HasPermission(ctx, permission.SuperuserAccess, m.state.ControllerTag()) if err != nil && !errors.Is(err, authentication.ErrorEntityMissingPermission) { - return coremodel.UUID(""), errors.Trace(err) + return "", errors.Trace(err) } if err != nil { canAddModel, err := m.checkAddModelPermission(ctx, cloudTag.Id(), m.apiUser) if err != nil { - return coremodel.UUID(""), errors.Trace(err) + return "", errors.Trace(err) } if !canAddModel { - return coremodel.UUID(""), apiservererrors.ErrPerm + return "", apiservererrors.ErrPerm } } ownerTag, err := names.ParseUserTag(args.OwnerTag) if err != nil { - return coremodel.UUID(""), errors.Trace(err) + return "", errors.Trace(err) } // a special case of ErrPerm will happen if the user has add-model permission but is trying to // create a model for another person, which is not yet supported. if !m.isAdmin && ownerTag != m.apiUser { - return coremodel.UUID(""), errors.Annotatef(apiservererrors.ErrPerm, "%q permission does not permit creation of models for different owners", permission.AddModelAccess) + return "", errors.Annotatef(apiservererrors.ErrPerm, "%q permission does not permit creation of models for different owners", permission.AddModelAccess) } user, err := m.accessService.GetUserByName(ctx, user.NameFromTag(ownerTag)) if err != nil { // TODO handle error properly - return coremodel.UUID(""), errors.Trace(err) + return "", errors.Trace(err) } creationArgs.Owner = user.UUID @@ -268,7 +268,7 @@ func (m *ModelManagerAPI) createModelNew( var err error cloudCredentialTag, err = names.ParseCloudCredentialTag(args.CloudCredentialTag) if err != nil { - return coremodel.UUID(""), errors.Trace(err) + return "", errors.Trace(err) } creationArgs.Credential = credential.KeyFromTag(cloudCredentialTag) @@ -277,7 +277,7 @@ func (m *ModelManagerAPI) createModelNew( // Create the model in the controller database. modelID, activator, err := m.modelService.CreateModel(ctx, creationArgs) if err != nil { - return coremodel.UUID(""), errors.Annotatef(err, "failed to create model %q", modelID) + return "", errors.Annotatef(err, "failed to create model %q", modelID) } // We need to get the model domain services from the newly created model diff --git a/apiserver/facades/client/modelmanager/modelmanager_test.go b/apiserver/facades/client/modelmanager/modelmanager_test.go index 7da8b80491b..700af8cd0d6 100644 --- a/apiserver/facades/client/modelmanager/modelmanager_test.go +++ b/apiserver/facades/client/modelmanager/modelmanager_test.go @@ -330,7 +330,7 @@ func (s *modelManagerSuite) expectCreateModel( ).Return(user.User{UUID: ownerUUID}, nil) // Create model in controller database. - s.modelService.EXPECT().CreateModel(gomock.Any(), model.ModelCreationArgs{ + s.modelService.EXPECT().CreateModel(gomock.Any(), model.ControllerDBModelCreationArgs{ Name: modelCreateArgs.Name, Owner: ownerUUID, Cloud: expectedCloudName, @@ -564,7 +564,7 @@ func (s *modelManagerSuite) TestCreateModelNoDefaultCredentialNonAdmin(c *gc.C) // //s.accessService.EXPECT().GetUserByName( // // gomock.Any(), ownerName, // //).Return(user.User{UUID: ownerUUID}, nil) -// //s.modelService.EXPECT().CreateModel(gomock.Any(), model.ModelCreationArgs{ +// //s.modelService.EXPECT().CreateModel(gomock.Any(), model.ControllerDBModelCreationArgs{ // // Name: "existing-ns", // // Owner: ownerUUID, // // Cloud: "k8s-cloud", @@ -1097,7 +1097,7 @@ func (s *modelManagerStateSuite) expectCreateModelStateSuite( ).Return(user.User{UUID: ownerUUID}, nil) // Create model in controller database. - s.modelService.EXPECT().CreateModel(gomock.Any(), model.ModelCreationArgs{ + s.modelService.EXPECT().CreateModel(gomock.Any(), model.ControllerDBModelCreationArgs{ Name: modelCreateArgs.Name, Owner: ownerUUID, Cloud: "dummy", diff --git a/apiserver/facades/client/modelmanager/services.go b/apiserver/facades/client/modelmanager/services.go index b9f22ae70ee..97e4c152337 100644 --- a/apiserver/facades/client/modelmanager/services.go +++ b/apiserver/facades/client/modelmanager/services.go @@ -75,7 +75,7 @@ type ModelConfigService interface { // ModelService defines an interface for interacting with the model service. type ModelService interface { // CreateModel creates a model returning the resultant model's new id. - CreateModel(context.Context, model.ModelCreationArgs) (coremodel.UUID, func(context.Context) error, error) + CreateModel(context.Context, model.ControllerDBModelCreationArgs) (coremodel.UUID, func(context.Context) error, error) // DefaultModelCloudNameAndCredential returns the default cloud name and // credential that should be used for newly created models that haven't had diff --git a/domain/agentprovisioner/state/state_test.go b/domain/agentprovisioner/state/state_test.go index 78054ed22e8..a91752768ca 100644 --- a/domain/agentprovisioner/state/state_test.go +++ b/domain/agentprovisioner/state/state_test.go @@ -107,7 +107,7 @@ func (s *suite) TestModelID(c *gc.C) { // Create a read-only model 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.ReadOnlyModelRecordArgs{ UUID: modelID, AgentVersion: version.Number{Major: 4, Minor: 21, Patch: 67}, ControllerUUID: uuid.MustNewUUID(), diff --git a/domain/cloud/state/state_test.go b/domain/cloud/state/state_test.go index f962f204a6e..41fd9730e78 100644 --- a/domain/cloud/state/state_test.go +++ b/domain/cloud/state/state_test.go @@ -349,7 +349,7 @@ func (s *stateSuite) TestCloudIsControllerCloud(c *gc.C) { context.Background(), modelUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: testCloud.Name, Name: coremodel.ControllerModelName, Owner: user.UUID(s.adminUUID.String()), diff --git a/domain/keyupdater/keyupdater_test.go b/domain/keyupdater/keyupdater_test.go index 7281ee4ee4a..119febbd49c 100644 --- a/domain/keyupdater/keyupdater_test.go +++ b/domain/keyupdater/keyupdater_test.go @@ -90,7 +90,7 @@ func (s *keyUpdaterSuite) SetUpTest(c *gc.C) { testing.CreateInternalSecretBackend(c, s.ControllerTxnRunner()) modelUUID := modeltesting.GenModelUUID(c) - modelFn := modelbootstrap.CreateModel(modelUUID, domainmodel.ModelCreationArgs{ + modelFn := modelbootstrap.CreateControllerDBModelRecord(modelUUID, domainmodel.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: cloudName, Credential: credential.Key{ @@ -106,7 +106,7 @@ func (s *keyUpdaterSuite) SetUpTest(c *gc.C) { err = modelFn(context.Background(), s.ControllerTxnRunner(), s.ControllerSuite.NoopTxnRunner()) c.Assert(err, jc.ErrorIsNil) - err = modelbootstrap.CreateReadOnlyModel(modelUUID, uuid.MustNewUUID())(context.Background(), s.ControllerTxnRunner(), s.ModelTxnRunner()) + err = modelbootstrap.CreateModelDBModelRecord(modelUUID, uuid.MustNewUUID())(context.Background(), s.ControllerTxnRunner(), s.ModelTxnRunner()) c.Assert(err, jc.ErrorIsNil) err = machinebootstrap.InsertMachine("0")( diff --git a/domain/keyupdater/state/state_test.go b/domain/keyupdater/state/state_test.go index 57f424d40af..969c30b13f1 100644 --- a/domain/keyupdater/state/state_test.go +++ b/domain/keyupdater/state/state_test.go @@ -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.ReadOnlyModelRecordArgs{ UUID: modelUUID, AgentVersion: jujuversion.Current, ControllerUUID: uuid.MustNewUUID(), diff --git a/domain/model/bootstrap/bootstrap.go b/domain/model/bootstrap/bootstrap.go index c64d609b64e..29d01c043db 100644 --- a/domain/model/bootstrap/bootstrap.go +++ b/domain/model/bootstrap/bootstrap.go @@ -30,13 +30,10 @@ func (m modelTypeStateFunc) CloudType(c context.Context, n string) (string, erro return m(c, n) } -// CreateModel is responsible for making a new model with all of its associated -// metadata during the bootstrap process. -// If the ModelCreationArgs does not have a credential name set then no cloud -// credential will be associated with the model. -// -// The only supported agent version during bootstrap is that of the current -// controller. This will be the default if no agent version is supplied. +// CreateControllerDBModelRecord is responsible for making a new model with all +// of its associated metadata during the bootstrap process. +// If the ControllerDBModelCreationArgs does not have a credential name set then +// no cloud credential will be associated with the model. // // The following error types can be expected to be returned: // - modelerrors.AlreadyExists: When the model uuid is already in use or a model @@ -48,14 +45,14 @@ func (m modelTypeStateFunc) CloudType(c context.Context, n string) (string, erro // - [secretbackenderrors.NotFound] When the secret backend for the model // cannot be found. // -// CreateModel expects the caller to generate their own model id and pass it to -// this function. In an ideal world we want to have this stopped and make this -// function generate a new id and return the value. This can only be achieved -// once we have the Juju client stop generating id's for controller models in -// the bootstrap process. -func CreateModel( +// CreateControllerDBModelRecord expects the caller to generate their own model +// ID and pass it to this function. In an ideal world we want to have this +// stopped and make this function generate a new id and return the value. +// This can only be achieved once we have the Juju client stop generating ID's +// for controller models in the bootstrap process. +func CreateControllerDBModelRecord( modelID coremodel.UUID, - args model.ModelCreationArgs, + args model.ControllerDBModelCreationArgs, ) internaldatabase.BootstrapOpt { return func(ctx context.Context, controller, model database.TxnRunner) error { if err := args.Validate(); err != nil { @@ -68,16 +65,6 @@ func CreateModel( ) } - agentVersion := args.AgentVersion - if args.AgentVersion == version.Zero { - agentVersion = jujuversion.Current - } - - if agentVersion.Major != jujuversion.Current.Major || agentVersion.Minor != jujuversion.Current.Minor { - return fmt.Errorf("%w %q during bootstrap", modelerrors.AgentVersionNotSupported, agentVersion) - } - args.AgentVersion = agentVersion - activator := state.GetActivator() return controller.Txn(ctx, func(ctx context.Context, tx *sqlair.TX) error { modelTypeState := modelTypeStateFunc( @@ -114,12 +101,12 @@ func CreateModel( } } -// CreateReadOnlyModel creates a new model within the model database with all of -// its associated metadata. The data will be read-only and cannot be modified -// once created. -func CreateReadOnlyModel( +// CreateModelDBModelRecord creates a new model within the model database with +// all of its associated metadata. +func CreateModelDBModelRecord( id coremodel.UUID, controllerUUID uuid.UUID, + agentVersion version.Number, ) internaldatabase.BootstrapOpt { return func(ctx context.Context, controllerDB, modelDB database.TxnRunner) error { if err := id.Validate(); err != nil { @@ -136,17 +123,19 @@ func CreateReadOnlyModel( return fmt.Errorf("getting model for id %q: %w", id, err) } - args := model.ReadOnlyModelCreationArgs{ - UUID: m.UUID, - AgentVersion: m.AgentVersion, - ControllerUUID: controllerUUID, - Name: m.Name, - Type: m.ModelType, - Cloud: m.Cloud, - CloudRegion: m.CloudRegion, - CredentialOwner: m.Credential.Owner, - CredentialName: m.Credential.Name, - IsControllerModel: true, + args := model.ModelDBModelCreationArgs{ + ReadOnlyModelRecordArgs: model.ReadOnlyModelRecordArgs{ + UUID: m.UUID, + ControllerUUID: controllerUUID, + Name: m.Name, + Type: m.ModelType, + Cloud: m.Cloud, + CloudRegion: m.CloudRegion, + CredentialOwner: m.Credential.Owner, + CredentialName: m.Credential.Name, + IsControllerModel: true, + }, + AgentVersion: agentVersion, } return modelDB.Txn(ctx, func(ctx context.Context, tx *sqlair.TX) error { diff --git a/domain/model/bootstrap/bootstrap_test.go b/domain/model/bootstrap/bootstrap_test.go index 51b3b22ce63..341e960ced3 100644 --- a/domain/model/bootstrap/bootstrap_test.go +++ b/domain/model/bootstrap/bootstrap_test.go @@ -92,9 +92,9 @@ type bootstrapSuite struct { var _ = gc.Suite(&bootstrapSuite{}) func (s *bootstrapSuite) TestUUIDIsRespected(c *gc.C) { - fn := CreateModel( + fn := CreateControllerDBModelRecord( modeltesting.GenModelUUID(c), - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: s.cloudName, Credential: credential.Key{ @@ -126,7 +126,7 @@ func (s *modelBootstrapSuite) TestCreateReadOnlyModel(c *gc.C) { controllerUUID := uuid.MustNewUUID() modelUUID := modeltesting.GenModelUUID(c) - args := model.ModelCreationArgs{ + args := model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: s.cloudName, Credential: credential.Key{ @@ -139,11 +139,11 @@ func (s *modelBootstrapSuite) TestCreateReadOnlyModel(c *gc.C) { } // Create a model and then create a read-only model from it. - fn := CreateModel(modelUUID, args) + fn := CreateControllerDBModelRecord(modelUUID, args) err := fn(context.Background(), s.ControllerTxnRunner(), s.NoopTxnRunner()) c.Assert(err, jc.ErrorIsNil) - fn = CreateReadOnlyModel(modelUUID, controllerUUID) + fn = CreateModelDBModelRecord(modelUUID, controllerUUID) err = fn(context.Background(), s.ControllerTxnRunner(), s.ModelTxnRunner()) c.Assert(err, jc.ErrorIsNil) @@ -166,7 +166,7 @@ func (s *modelBootstrapSuite) TestCreateModelWithDifferingBuildNumber(c *gc.C) { v := jujuversion.Current v.Build++ - args := model.ModelCreationArgs{ + args := model.ControllerDBModelCreationArgs{ AgentVersion: v, Cloud: s.cloudName, Credential: credential.Key{ @@ -179,7 +179,7 @@ func (s *modelBootstrapSuite) TestCreateModelWithDifferingBuildNumber(c *gc.C) { } // Create a model and then create a read-only model from it. - fn := CreateModel(modeltesting.GenModelUUID(c), args) + fn := CreateControllerDBModelRecord(modeltesting.GenModelUUID(c), args) err := fn(context.Background(), s.ControllerTxnRunner(), s.ModelTxnRunner()) c.Assert(err, jc.ErrorIsNil) } diff --git a/domain/model/modelmigration/import.go b/domain/model/modelmigration/import.go index 6ceb20e9ca1..8822f6d4d11 100644 --- a/domain/model/modelmigration/import.go +++ b/domain/model/modelmigration/import.go @@ -183,7 +183,7 @@ func (i *importOperation) Execute(ctx context.Context, model description.Model) } args := domainmodel.ModelImportArgs{ - ModelCreationArgs: domainmodel.ModelCreationArgs{ + ControllerDBModelCreationArgs: domainmodel.ControllerDBModelCreationArgs{ AgentVersion: agentVersion, Cloud: model.Cloud(), CloudRegion: model.CloudRegion(), diff --git a/domain/model/modelmigration/import_test.go b/domain/model/modelmigration/import_test.go index f6df49b1fcf..781f93bfdae 100644 --- a/domain/model/modelmigration/import_test.go +++ b/domain/model/modelmigration/import_test.go @@ -134,7 +134,7 @@ func (i *importSuite) TestModelCreate(c *gc.C) { i.controllerConfigService.EXPECT().ControllerConfig(gomock.Any()).Return(testing.FakeControllerConfig(), nil) args := model.ModelImportArgs{ - ModelCreationArgs: model.ModelCreationArgs{ + ControllerDBModelCreationArgs: model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: "AWS", CloudRegion: "region1", @@ -210,7 +210,7 @@ func (i *importSuite) TestModelCreateRollbacksOnFailure(c *gc.C) { i.controllerConfigService.EXPECT().ControllerConfig(gomock.Any()).Return(testing.FakeControllerConfig(), nil) args := model.ModelImportArgs{ - ModelCreationArgs: model.ModelCreationArgs{ + ControllerDBModelCreationArgs: model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: "AWS", CloudRegion: "region1", @@ -297,7 +297,7 @@ func (i *importSuite) TestModelCreateRollbacksOnFailureIgnoreNotFoundModel(c *gc i.controllerConfigService.EXPECT().ControllerConfig(gomock.Any()).Return(testing.FakeControllerConfig(), nil) args := model.ModelImportArgs{ - ModelCreationArgs: model.ModelCreationArgs{ + ControllerDBModelCreationArgs: model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: "AWS", CloudRegion: "region1", @@ -383,7 +383,7 @@ func (i *importSuite) TestModelCreateRollbacksOnFailureIgnoreNotFoundReadOnlyMod } args := model.ModelImportArgs{ - ModelCreationArgs: model.ModelCreationArgs{ + ControllerDBModelCreationArgs: model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: "AWS", CloudRegion: "region1", diff --git a/domain/model/service/modelservice.go b/domain/model/service/modelservice.go index 9a71701da43..519c5c001e4 100644 --- a/domain/model/service/modelservice.go +++ b/domain/model/service/modelservice.go @@ -19,7 +19,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.ReadOnlyModelRecordArgs) error // Delete deletes a model. Delete(context.Context, coremodel.UUID) error @@ -81,9 +81,8 @@ func (s *ModelService) CreateModel( return err } - args := model.ReadOnlyModelCreationArgs{ + args := model.ReadOnlyModelRecordArgs{ UUID: m.UUID, - AgentVersion: m.AgentVersion, ControllerUUID: controllerUUID, Name: m.Name, Type: m.ModelType, diff --git a/domain/model/service/modelservice_test.go b/domain/model/service/modelservice_test.go index ae36431706c..e61dbe7a20d 100644 --- a/domain/model/service/modelservice_test.go +++ b/domain/model/service/modelservice_test.go @@ -22,13 +22,13 @@ import ( ) type dummyModelState struct { - models map[coremodel.UUID]model.ReadOnlyModelCreationArgs + models map[coremodel.UUID]model.ReadOnlyModelRecordArgs setID coremodel.UUID modelState map[coremodel.UUID]model.ModelState } -func (d *dummyModelState) Create(ctx context.Context, args model.ReadOnlyModelCreationArgs) error { +func (d *dummyModelState) Create(ctx context.Context, args model.ReadOnlyModelRecordArgs) error { if d.setID != coremodel.UUID("") { return modelerrors.AlreadyExists } @@ -104,7 +104,7 @@ var _ = gc.Suite(&modelServiceSuite{}) func (s *modelServiceSuite) SetUpTest(c *gc.C) { s.state = &dummyModelState{ - models: map[coremodel.UUID]model.ReadOnlyModelCreationArgs{}, + models: map[coremodel.UUID]model.ReadOnlyModelRecordArgs{}, modelState: map[coremodel.UUID]model.ModelState{}, } @@ -115,7 +115,7 @@ func (s *modelServiceSuite) TestModelCreation(c *gc.C) { id := modeltesting.GenModelUUID(c) svc := NewModelService(id, s.state, s.state) - s.state.models[id] = model.ReadOnlyModelCreationArgs{ + s.state.models[id] = model.ReadOnlyModelRecordArgs{ UUID: id, Name: "my-awesome-model", Cloud: "aws", @@ -143,7 +143,7 @@ func (s *modelServiceSuite) TestModelDeletion(c *gc.C) { id := modeltesting.GenModelUUID(c) svc := NewModelService(id, s.state, s.state) - s.state.models[id] = model.ReadOnlyModelCreationArgs{ + s.state.models[id] = model.ReadOnlyModelRecordArgs{ UUID: id, Name: "my-awesome-model", Cloud: "aws", diff --git a/domain/model/service/service.go b/domain/model/service/service.go index 84f8f72a661..e83b7222a44 100644 --- a/domain/model/service/service.go +++ b/domain/model/service/service.go @@ -46,7 +46,7 @@ type State interface { ModelTypeState // Create creates a new model with all of its associated metadata. - Create(context.Context, coremodel.UUID, coremodel.ModelType, model.ModelCreationArgs) error + Create(context.Context, coremodel.UUID, coremodel.ModelType, model.ControllerDBModelCreationArgs) error // Activate is responsible for setting a model as fully constructed and // indicates the final system state for the model is ready for use. @@ -205,7 +205,7 @@ func (s *Service) DefaultModelCloudNameAndCredential( // CreateModel is responsible for creating a new model from start to finish with // its associated metadata. The function will return the created model's id. -// If the ModelCreationArgs does not have a credential name set then no cloud +// If the ControllerDBModelCreationArgs does not have a credential name set then no cloud // credential will be associated with model. // // If the caller has not prescribed a specific agent version to use for the @@ -229,7 +229,7 @@ func (s *Service) DefaultModelCloudNameAndCredential( // cannot be found. func (s *Service) CreateModel( ctx context.Context, - args model.ModelCreationArgs, + args model.ControllerDBModelCreationArgs, ) (coremodel.UUID, func(context.Context) error, error) { if err := args.Validate(); err != nil { return "", nil, fmt.Errorf( @@ -251,7 +251,7 @@ func (s *Service) CreateModel( // createModel is responsible for creating a new model from start to finish with // its associated metadata. The function takes the model id to be used as part // of the creation. This helps serve both new model creation and model -// importing. If the ModelCreationArgs does not have a credential name set then +// importing. If the ControllerDBModelCreationArgs does not have a credential name set then // no cloud credential will be associated with model. // // If the caller has not prescribed a specific agent version to use for the @@ -277,7 +277,7 @@ func (s *Service) CreateModel( func (s *Service) createModel( ctx context.Context, id coremodel.UUID, - args model.ModelCreationArgs, + args model.ControllerDBModelCreationArgs, ) (func(context.Context) error, error) { modelType, err := ModelTypeForCloud(ctx, s.st, args.Cloud) if err != nil { @@ -359,7 +359,7 @@ func (s *Service) ImportModel( ) } - return s.createModel(ctx, args.ID, args.ModelCreationArgs) + return s.createModel(ctx, args.ID, args.ControllerDBModelCreationArgs) } // ControllerModel returns the model used for housing the Juju controller. diff --git a/domain/model/service/service_test.go b/domain/model/service/service_test.go index 08725366811..3b459005d55 100644 --- a/domain/model/service/service_test.go +++ b/domain/model/service/service_test.go @@ -88,7 +88,7 @@ func (s *serviceSuite) TestControllerModelOwnerUsername(c *gc.C) { func (s *serviceSuite) TestCreateModelInvalidArgs(c *gc.C) { svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - _, _, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{}) + _, _, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{}) c.Assert(err, jc.ErrorIs, errors.NotValid) } @@ -106,7 +106,7 @@ func (s *serviceSuite) TestModelCreation(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Credential: cred, @@ -147,7 +147,7 @@ func (s *serviceSuite) TestModelCreationSecretBackendNotFound(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - _, _, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + _, _, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Credential: cred, @@ -162,7 +162,7 @@ func (s *serviceSuite) TestModelCreationSecretBackendNotFound(c *gc.C) { func (s *serviceSuite) TestModelCreationInvalidCloud(c *gc.C) { s.state.clouds["aws"] = dummyStateCloud{} svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - _, _, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + _, _, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Owner: s.userUUID, @@ -178,7 +178,7 @@ func (s *serviceSuite) TestModelCreationNoCloudRegion(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - _, _, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + _, _, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "noexist", Owner: s.userUUID, @@ -200,7 +200,7 @@ func (s *serviceSuite) TestModelCreationOwnerNotFound(c *gc.C) { c.Assert(err, jc.ErrorIsNil) svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - _, _, err = svc.CreateModel(context.Background(), model.ModelCreationArgs{ + _, _, err = svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Owner: notFoundUser, @@ -217,7 +217,7 @@ func (s *serviceSuite) TestModelCreationNoCloudCredential(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - _, _, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + _, _, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Credential: credential.Key{ @@ -239,7 +239,7 @@ func (s *serviceSuite) TestModelCreationNameOwnerConflict(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - _, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + _, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Owner: s.userUUID, @@ -248,7 +248,7 @@ func (s *serviceSuite) TestModelCreationNameOwnerConflict(c *gc.C) { c.Assert(err, jc.ErrorIsNil) c.Assert(activator(context.Background()), jc.ErrorIsNil) - _, _, err = svc.CreateModel(context.Background(), model.ModelCreationArgs{ + _, _, err = svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Owner: s.userUUID, @@ -285,7 +285,7 @@ func (s *serviceSuite) TestUpdateModelCredential(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Owner: s.userUUID, @@ -319,7 +319,7 @@ func (s *serviceSuite) TestUpdateModelCredentialReplace(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Credential: cred, @@ -348,7 +348,7 @@ func (s *serviceSuite) TestUpdateModelCredentialZeroValue(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Owner: s.userUUID, @@ -387,7 +387,7 @@ func (s *serviceSuite) TestUpdateModelCredentialDifferentCloud(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Credential: cred, @@ -421,7 +421,7 @@ func (s *serviceSuite) TestUpdateModelCredentialNotFound(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Credential: cred, @@ -449,7 +449,7 @@ func (s *serviceSuite) TestDeleteModel(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Credential: cred, @@ -503,7 +503,7 @@ func (s *serviceSuite) TestAgentVersionUnsupportedGreater(c *gc.C) { c.Assert(err, jc.ErrorIsNil) svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id, _, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id, _, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ AgentVersion: agentVersion, Cloud: "aws", CloudRegion: "myregion", @@ -536,7 +536,7 @@ func (s *serviceSuite) TestAgentVersionUnsupportedLess(c *gc.C) { c.Assert(err, jc.ErrorIsNil) svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id, _, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id, _, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ AgentVersion: agentVersion, Cloud: "aws", CloudRegion: "myregion", @@ -578,7 +578,7 @@ func (s *serviceSuite) TestListAllModels(c *gc.C) { s.state.users[usr1] = usertesting.GenNewName(c, "tlm") svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id1, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id1, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: "aws", CloudRegion: "myregion", @@ -589,7 +589,7 @@ func (s *serviceSuite) TestListAllModels(c *gc.C) { c.Assert(err, jc.ErrorIsNil) c.Assert(activator(context.Background()), jc.ErrorIsNil) - id2, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id2, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: "aws", CloudRegion: "myregion", @@ -662,7 +662,7 @@ func (s *serviceSuite) TestListModelsForUser(c *gc.C) { s.state.users[usr1] = usertesting.GenNewName(c, "tlm") svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - id1, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id1, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: "aws", CloudRegion: "myregion", @@ -673,7 +673,7 @@ func (s *serviceSuite) TestListModelsForUser(c *gc.C) { c.Assert(err, jc.ErrorIsNil) c.Assert(activator(context.Background()), jc.ErrorIsNil) - id2, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + id2, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: "aws", CloudRegion: "myregion", @@ -739,7 +739,7 @@ func (s *serviceSuite) TestImportModelWithMissingAgentVersion(c *gc.C) { svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) _, err := svc.ImportModel(context.Background(), model.ModelImportArgs{ - ModelCreationArgs: model.ModelCreationArgs{ + ControllerDBModelCreationArgs: model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Credential: cred, @@ -772,7 +772,7 @@ func (s *serviceSuite) TestImportModel(c *gc.C) { svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) activator, err := svc.ImportModel(context.Background(), model.ModelImportArgs{ - ModelCreationArgs: model.ModelCreationArgs{ + ControllerDBModelCreationArgs: model.ControllerDBModelCreationArgs{ Cloud: "aws", CloudRegion: "myregion", Credential: cred, @@ -817,7 +817,7 @@ func (s *serviceSuite) TestControllerModel(c *gc.C) { } svc := NewService(s.state, s.deleter, DefaultAgentBinaryFinder(), loggertesting.WrapCheckLog(c)) - modelID, activator, err := svc.CreateModel(context.Background(), model.ModelCreationArgs{ + modelID, activator, err := svc.CreateModel(context.Background(), model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: "aws", CloudRegion: "myregion", diff --git a/domain/model/service/state_test.go b/domain/model/service/state_test.go index 3bbadf7921c..71f44a263d4 100644 --- a/domain/model/service/state_test.go +++ b/domain/model/service/state_test.go @@ -64,7 +64,7 @@ func (d *dummyState) Create( _ context.Context, modelID coremodel.UUID, modelType coremodel.ModelType, - args model.ModelCreationArgs, + args model.ControllerDBModelCreationArgs, ) error { if _, exists := d.models[modelID]; exists { return fmt.Errorf("%w %q", modelerrors.AlreadyExists, modelID) diff --git a/domain/model/state/controllerstate.go b/domain/model/state/controllerstate.go index 4a5f772c946..d9491a91d18 100644 --- a/domain/model/state/controllerstate.go +++ b/domain/model/state/controllerstate.go @@ -109,7 +109,7 @@ func (s *State) Create( ctx context.Context, modelID coremodel.UUID, modelType coremodel.ModelType, - input model.ModelCreationArgs, + input model.ControllerDBModelCreationArgs, ) error { db, err := s.DB() if err != nil { @@ -138,7 +138,7 @@ func Create( tx *sqlair.TX, modelID coremodel.UUID, modelType coremodel.ModelType, - input model.ModelCreationArgs, + input model.ControllerDBModelCreationArgs, ) error { // This function is responsible for driving all of the facets of model // creation. @@ -454,7 +454,7 @@ INSERT INTO model_secret_backend (*) VALUES ($dbModelSecretBackend.*) // // Should the provided cloud and region not be found an error matching // errors.NotFound will be returned. -// If the ModelCreationArgs contains a non zero value cloud credential this func +// If the ControllerDBModelCreationArgs contains a non zero value cloud credential this func // will also attempt to set the model cloud credential using updateCredential. In // this scenario the errors from updateCredential are also possible. // If the model owner does not exist an error satisfying [usererrors.NotFound] @@ -465,7 +465,7 @@ func createModel( tx *sqlair.TX, modelUUID coremodel.UUID, modelType coremodel.ModelType, - input model.ModelCreationArgs, + input model.ControllerDBModelCreationArgs, ) error { cloudName := dbName{Name: input.Cloud} diff --git a/domain/model/state/controllerstate_test.go b/domain/model/state/controllerstate_test.go index b9d9c92a91f..700e0e8e7e6 100644 --- a/domain/model/state/controllerstate_test.go +++ b/domain/model/state/controllerstate_test.go @@ -134,7 +134,7 @@ func (m *stateSuite) SetUpTest(c *gc.C) { context.Background(), m.uuid, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", @@ -203,7 +203,7 @@ func (m *stateSuite) TestModelCloudNameAndCredentialController(c *gc.C) { context.Background(), modelUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", Credential: corecredential.Key{ @@ -331,7 +331,7 @@ func (m *stateSuite) TestCreateModelWithExisting(c *gc.C) { tx, m.uuid, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Name: "fantasticmodel", @@ -353,7 +353,7 @@ func (m *stateSuite) TestCreateModelWithSameNameAndOwner(c *gc.C) { context.Background(), testUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Name: "my-test-model", @@ -371,7 +371,7 @@ func (m *stateSuite) TestCreateModelWithInvalidCloudRegion(c *gc.C) { context.Background(), testUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "noexist", Name: "noregion", @@ -389,7 +389,7 @@ func (m *stateSuite) TestCreateWithEmptyRegion(c *gc.C) { context.Background(), testUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "my-cloud", Name: "noregion", Owner: m.userUUID, @@ -418,7 +418,7 @@ func (m *stateSuite) TestCreateWithEmptyRegionUsesControllerRegion(c *gc.C) { context.Background(), modeltesting.GenModelUUID(c), coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Name: "controller", @@ -438,7 +438,7 @@ func (m *stateSuite) TestCreateWithEmptyRegionUsesControllerRegion(c *gc.C) { context.Background(), testUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "my-cloud", Name: "noregion", Owner: m.userUUID, @@ -469,7 +469,7 @@ func (m *stateSuite) TestCreateWithEmptyRegionDoesNotUseControllerRegionForDiffe context.Background(), controllerUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Name: "controller", @@ -496,7 +496,7 @@ func (m *stateSuite) TestCreateWithEmptyRegionDoesNotUseControllerRegionForDiffe context.Background(), testUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "other-cloud", Name: "noregion", Owner: m.userUUID, @@ -532,7 +532,7 @@ func (m *stateSuite) TestCreateModelWithNonExistentOwner(c *gc.C) { context.Background(), testUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "noexist", Name: "noregion", @@ -557,7 +557,7 @@ func (m *stateSuite) TestCreateModelWithRemovedOwner(c *gc.C) { context.Background(), testUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "noexist", Name: "noregion", @@ -578,7 +578,7 @@ func (m *stateSuite) TestCreateModelVerifyPermissionSet(c *gc.C) { ctx, testUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", @@ -610,7 +610,7 @@ func (m *stateSuite) TestCreateModelWithInvalidCloud(c *gc.C) { context.Background(), testUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "noexist", CloudRegion: "my-region", Name: "noregion", @@ -710,7 +710,7 @@ func (m *stateSuite) TestSetModelCloudCredentialWithoutRegion(c *gc.C) { context.Background(), m.uuid, coremodel.CAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ Cloud: "minikube", Credential: corecredential.Key{ Cloud: "minikube", @@ -799,7 +799,7 @@ func (m *stateSuite) TestListModelIDs(c *gc.C) { context.Background(), uuid1, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", @@ -822,7 +822,7 @@ func (m *stateSuite) TestListModelIDs(c *gc.C) { context.Background(), uuid2, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", @@ -912,7 +912,7 @@ func (m *stateSuite) TestModelsOwnedByUser(c *gc.C) { context.Background(), uuid1, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", @@ -934,7 +934,7 @@ func (m *stateSuite) TestModelsOwnedByUser(c *gc.C) { context.Background(), uuid2, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", @@ -1061,7 +1061,7 @@ func (m *stateSuite) TestSecretBackendNotFoundForModelCreate(c *gc.C) { context.Background(), uuid, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", @@ -1134,7 +1134,7 @@ func (m *stateSuite) TestCleanupBrokenModel(c *gc.C) { context.Background(), modelID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", @@ -1158,7 +1158,7 @@ func (m *stateSuite) TestCleanupBrokenModel(c *gc.C) { context.Background(), newModelID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", @@ -1435,7 +1435,7 @@ func (m *stateSuite) createTestModel(c *gc.C, modelSt *State, name string, creat context.Background(), modelUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", diff --git a/domain/model/state/modelstate.go b/domain/model/state/modelstate.go index 368cc165262..76ae1686ef2 100644 --- a/domain/model/state/modelstate.go +++ b/domain/model/state/modelstate.go @@ -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.ReadOnlyModelRecordArgs) error { db, err := s.DB() if err != nil { return errors.Trace(err) @@ -162,7 +162,9 @@ func (s *ModelState) Model(ctx context.Context) (coremodel.ReadOnlyModel, error) // CreateReadOnlyModel is responsible for creating a new model within the model // database. -func CreateReadOnlyModel(ctx context.Context, args model.ReadOnlyModelCreationArgs, preparer domain.Preparer, tx *sqlair.TX) error { +func CreateReadOnlyModel( + ctx context.Context, args model.ModelDBModelCreationArgs, 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. @@ -172,16 +174,13 @@ func CreateReadOnlyModel(ctx context.Context, args model.ReadOnlyModelCreationAr agentVersion.Valid = true } - uuid := dbUUID{UUID: args.UUID.String()} - checkExistsStmt, err := preparer.Prepare(` -SELECT &dbUUID.uuid -FROM model - `, uuid) + mID := dbUUID{UUID: args.UUID.String()} + checkExistsStmt, err := preparer.Prepare("SELECT &dbUUID.uuid FROM model", mID) if err != nil { return errors.Annotatef(err, "preparing check model exists statement") } - err = tx.Query(ctx, checkExistsStmt).Get(&uuid) + err = tx.Query(ctx, checkExistsStmt).Get(&mID) if err != nil && !errors.Is(err, sqlair.ErrNoRows) { return internalerrors.Errorf("checking if model already exists: %w", err) } else if err == nil { @@ -189,38 +188,33 @@ FROM model } m := dbReadOnlyModel{ - UUID: args.UUID.String(), - ControllerUUID: args.ControllerUUID.String(), - Name: args.Name, - Type: args.Type.String(), - TargetAgentVersion: agentVersion, - Cloud: args.Cloud, - CloudType: args.CloudType, - CloudRegion: args.CloudRegion, - CredentialOwner: args.CredentialOwner.Name(), - CredentialName: args.CredentialName, - IsControllerModel: args.IsControllerModel, - } - - insertStmt, err := preparer.Prepare(` -INSERT INTO model (*) VALUES ($dbReadOnlyModel.*) -`, dbReadOnlyModel{}) + UUID: args.UUID.String(), + ControllerUUID: args.ControllerUUID.String(), + Name: args.Name, + Type: args.Type.String(), + Cloud: args.Cloud, + CloudType: args.CloudType, + CloudRegion: args.CloudRegion, + CredentialOwner: args.CredentialOwner.Name(), + CredentialName: args.CredentialName, + IsControllerModel: args.IsControllerModel, + } + + roStmt, err := preparer.Prepare("INSERT INTO model (*) VALUES ($dbReadOnlyModel.*)", m) if err != nil { return errors.Annotatef(err, "preparing insert model statement") } - var outcome sqlair.Outcome - if err := tx.Query(ctx, insertStmt, m).Get(&outcome); err != nil { - return fmt.Errorf("creating model %q: %w", args.UUID, err) - } + v := sqlair.M{"target_version": agentVersion} + vStmt, err := preparer.Prepare("INSERT INTO agent_version (*) VALUES ($M)", v) - // Double check that it was actually created. - affected, err := outcome.Result().RowsAffected() - if err != nil { - return fmt.Errorf("creating model %q: %w", args.UUID, err) + if err := tx.Query(ctx, roStmt, m).Run(); err != nil { + return fmt.Errorf("creating model read-only record for %q: %w", args.UUID, err) } - if affected != 1 { - return modelerrors.AlreadyExists + + if err := tx.Query(ctx, vStmt, v).Run(); err != nil { + return fmt.Errorf("creating agent_version record for %q: %w", args.UUID, err) } + return nil } diff --git a/domain/model/state/modelstate_test.go b/domain/model/state/modelstate_test.go index a8491ac0cc7..7eed94c989b 100644 --- a/domain/model/state/modelstate_test.go +++ b/domain/model/state/modelstate_test.go @@ -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.ReadOnlyModelRecordArgs{ UUID: id, AgentVersion: jujuversion.Current, ControllerUUID: s.controllerUUID, @@ -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.ReadOnlyModelRecordArgs{ UUID: id, AgentVersion: jujuversion.Current, ControllerUUID: s.controllerUUID, @@ -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.ReadOnlyModelRecordArgs{ UUID: id, AgentVersion: jujuversion.Current, ControllerUUID: s.controllerUUID, @@ -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.ReadOnlyModelRecordArgs{ UUID: modeltesting.GenModelUUID(c), AgentVersion: jujuversion.Current, Name: "my-awesome-model", @@ -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.ReadOnlyModelRecordArgs{ UUID: modeltesting.GenModelUUID(c), AgentVersion: jujuversion.Current, Name: "my-awesome-model", @@ -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.ReadOnlyModelRecordArgs{ UUID: id, AgentVersion: jujuversion.Current, ControllerUUID: s.controllerUUID, @@ -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.ReadOnlyModelRecordArgs{ UUID: id, AgentVersion: jujuversion.Current, Name: "my-awesome-model", diff --git a/domain/model/state/testing/model.go b/domain/model/state/testing/model.go index 08e72c5ff42..d4cc552e048 100644 --- a/domain/model/state/testing/model.go +++ b/domain/model/state/testing/model.go @@ -152,7 +152,7 @@ func CreateTestModel( context.Background(), modelUUID, coremodel.IAAS, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: name, CloudRegion: regionName, diff --git a/domain/model/types.go b/domain/model/types.go index 5e41b5747c5..ec29b089c99 100644 --- a/domain/model/types.go +++ b/domain/model/types.go @@ -5,11 +5,10 @@ package model import ( "fmt" + "github.com/juju/version/v2" "time" "github.com/juju/errors" - "github.com/juju/version/v2" - "github.com/juju/juju/core/credential" coremodel "github.com/juju/juju/core/model" corestatus "github.com/juju/juju/core/status" @@ -17,12 +16,9 @@ import ( "github.com/juju/juju/internal/uuid" ) -// ModelCreationArgs supplies the information required for instantiating a new -// model. -type ModelCreationArgs struct { - // AgentVersion is the target version for agents running under this model. - AgentVersion version.Number - +// ControllerDBModelCreationArgs supplies the information required for +// recording details of a new model in the controller database. +type ControllerDBModelCreationArgs struct { // Cloud is the name of the cloud to associate with the model. // Must not be empty for a valid struct. Cloud string @@ -49,10 +45,11 @@ type ModelCreationArgs struct { SecretBackend string } -// Validate is responsible for checking all of the fields of ModelCreationArgs -// are in a set state that is valid for use. If a validation failure happens an -// error satisfying [errors.NotValid] is returned. -func (m ModelCreationArgs) Validate() error { +// Validate is responsible for checking all of the fields of +// ControllerDBModelCreationArgs are in a set state that is valid for use. +// If a validation failure happens an error satisfying [errors.NotValid] +// is returned. +func (m ControllerDBModelCreationArgs) Validate() error { if m.Cloud == "" { return fmt.Errorf("%w cloud cannot be empty", errors.NotValid) } @@ -70,36 +67,9 @@ func (m ModelCreationArgs) Validate() error { return nil } -// ModelImportArgs supplies the information needed for importing a model into a -// Juju controller. -type ModelImportArgs struct { - // ID represents the unique id of the model to import. - ID coremodel.UUID - - // ModelCreationArgs supplies the information needed for importing the new - // model into Juju. - ModelCreationArgs -} - -// Validate is responsible for checking all of the fields of [ModelImportArgs] -// are in a set state valid for use. If a validation failure happens an error -// satisfying [errors.NotValid] is returned. -func (m ModelImportArgs) Validate() error { - if err := m.ModelCreationArgs.Validate(); err != nil { - return fmt.Errorf("ModelCreationArgs %w", err) - } - - if err := m.ID.Validate(); err != nil { - return fmt.Errorf("validating model import args id: %w", err) - } - - return nil -} - -// ReadOnlyModelCreationArgs 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 { +// ReadOnlyModelRecordArgs is a struct that is used to create the single +// read-only model record in the model database. +type ReadOnlyModelRecordArgs 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. @@ -128,6 +98,9 @@ type ReadOnlyModelCreationArgs struct { // Optional and can be empty. CloudRegion string + // TODO (manadart 2024-11-27): Credential concerns are *not* read-only! + // A model can be updated to use a new credential. + // CredentialOwner is the name of the credential owner for this model in // the Juju controller. // Optional and can be empty. @@ -143,6 +116,41 @@ type ReadOnlyModelCreationArgs struct { IsControllerModel bool } +// ModelDBModelCreationArgs supplies the information required for +// recording details of a new model in the controller database. +type ModelDBModelCreationArgs struct { + ReadOnlyModelRecordArgs + + // AgentVersion is the target version for agents running under this model. + AgentVersion version.Number +} + +// ModelImportArgs supplies the information needed for importing a model into a +// Juju controller. +type ModelImportArgs struct { + // ID represents the unique id of the model to import. + ID coremodel.UUID + + // ControllerDBModelCreationArgs supplies the information needed for importing the new + // model into Juju. + ControllerDBModelCreationArgs +} + +// Validate is responsible for checking all of the fields of [ModelImportArgs] +// are in a set state valid for use. If a validation failure happens an error +// satisfying [errors.NotValid] is returned. +func (m ModelImportArgs) Validate() error { + if err := m.ControllerDBModelCreationArgs.Validate(); err != nil { + return fmt.Errorf("ControllerDBModelCreationArgs %w", err) + } + + if err := m.ID.Validate(); err != nil { + return fmt.Errorf("validating model import args id: %w", err) + } + + return nil +} + // DeleteModelOptions is a struct that is used to modify the behavior of the // DeleteModel function. type DeleteModelOptions struct { diff --git a/domain/model/types_test.go b/domain/model/types_test.go index ef73a4ac6ba..df19ff616f5 100644 --- a/domain/model/types_test.go +++ b/domain/model/types_test.go @@ -21,18 +21,18 @@ type typesSuite struct { var _ = gc.Suite(&typesSuite{}) // TestModelCreationArgsValidation is aserting all the validation cases that the -// [ModelCreationArgs.Validate] function checks for. +// [ControllerDBModelCreationArgs.Validate] function checks for. func (*typesSuite) TestModelCreationArgsValidation(c *gc.C) { userUUID := usertesting.GenUserUUID(c) tests := []struct { - Args ModelCreationArgs + Args ControllerDBModelCreationArgs Name string ErrTest error }{ { Name: "Test invalid name", - Args: ModelCreationArgs{ + Args: ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Name: "", @@ -42,7 +42,7 @@ func (*typesSuite) TestModelCreationArgsValidation(c *gc.C) { }, { Name: "Test invalid owner", - Args: ModelCreationArgs{ + Args: ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Name: "my-awesome-model", @@ -52,7 +52,7 @@ func (*typesSuite) TestModelCreationArgsValidation(c *gc.C) { }, { Name: "Test invalid cloud", - Args: ModelCreationArgs{ + Args: ControllerDBModelCreationArgs{ Cloud: "", CloudRegion: "my-region", Name: "my-awesome-model", @@ -62,7 +62,7 @@ func (*typesSuite) TestModelCreationArgsValidation(c *gc.C) { }, { Name: "Test invalid cloud region", - Args: ModelCreationArgs{ + Args: ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "", Name: "my-awesome-model", @@ -72,7 +72,7 @@ func (*typesSuite) TestModelCreationArgsValidation(c *gc.C) { }, { Name: "Test invalid credential key", - Args: ModelCreationArgs{ + Args: ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Credential: credential.Key{ @@ -85,7 +85,7 @@ func (*typesSuite) TestModelCreationArgsValidation(c *gc.C) { }, { Name: "Test happy path without credential key", - Args: ModelCreationArgs{ + Args: ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Name: "my-awesome-model", @@ -95,7 +95,7 @@ func (*typesSuite) TestModelCreationArgsValidation(c *gc.C) { }, { Name: "Test happy path with credential key", - Args: ModelCreationArgs{ + Args: ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Credential: credential.Key{ @@ -135,7 +135,7 @@ func (*typesSuite) TestModelImportArgsValidation(c *gc.C) { { Name: "Test happy path with valid model id", Args: ModelImportArgs{ - ModelCreationArgs: ModelCreationArgs{ + ControllerDBModelCreationArgs: ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Credential: credential.Key{ @@ -152,7 +152,7 @@ func (*typesSuite) TestModelImportArgsValidation(c *gc.C) { { Name: "Test invalid model id", Args: ModelImportArgs{ - ModelCreationArgs: ModelCreationArgs{ + ControllerDBModelCreationArgs: ControllerDBModelCreationArgs{ Cloud: "my-cloud", CloudRegion: "my-region", Credential: credential.Key{ diff --git a/domain/modelconfig/bootstrap/bootstrap_test.go b/domain/modelconfig/bootstrap/bootstrap_test.go index 818e846c5a9..bc71a040215 100644 --- a/domain/modelconfig/bootstrap/bootstrap_test.go +++ b/domain/modelconfig/bootstrap/bootstrap_test.go @@ -93,9 +93,9 @@ func (s *bootstrapSuite) SetUpTest(c *gc.C) { testing.CreateInternalSecretBackend(c, s.ControllerTxnRunner()) modelUUID := modeltesting.GenModelUUID(c) - modelFn := modelbootstrap.CreateModel( + modelFn := modelbootstrap.CreateControllerDBModelRecord( modelUUID, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: cloudName, Credential: credential.Key{ diff --git a/domain/modelconfig/modelconfig_test.go b/domain/modelconfig/modelconfig_test.go index 186efce6957..24cd5eadf73 100644 --- a/domain/modelconfig/modelconfig_test.go +++ b/domain/modelconfig/modelconfig_test.go @@ -95,7 +95,7 @@ func (s *modelConfigSuite) SetUpTest(c *gc.C) { testing.CreateInternalSecretBackend(c, s.ControllerTxnRunner()) modelUUID := modeltesting.GenModelUUID(c) - modelFn := modelbootstrap.CreateModel(modelUUID, domainmodel.ModelCreationArgs{ + modelFn := modelbootstrap.CreateControllerDBModelRecord(modelUUID, domainmodel.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: cloudName, Credential: credential.Key{ @@ -111,7 +111,7 @@ func (s *modelConfigSuite) SetUpTest(c *gc.C) { err = modelFn(context.Background(), s.ControllerTxnRunner(), s.ControllerSuite.NoopTxnRunner()) c.Assert(err, jc.ErrorIsNil) - err = modelbootstrap.CreateReadOnlyModel(modelUUID, uuid.MustNewUUID())(context.Background(), s.ControllerTxnRunner(), s.ModelTxnRunner()) + err = modelbootstrap.CreateModelDBModelRecord(modelUUID, uuid.MustNewUUID())(context.Background(), s.ControllerTxnRunner(), s.ModelTxnRunner()) c.Assert(err, jc.ErrorIsNil) } diff --git a/domain/modelmigration/state/state_test.go b/domain/modelmigration/state/state_test.go index 99a2c7acc03..1554f3c029e 100644 --- a/domain/modelmigration/state/state_test.go +++ b/domain/modelmigration/state/state_test.go @@ -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.ReadOnlyModelRecordArgs{ UUID: id, AgentVersion: jujuversion.Current, ControllerUUID: s.controllerUUID, diff --git a/domain/secretbackend/state/state_test.go b/domain/secretbackend/state/state_test.go index 573009e01e4..13c9d303c45 100644 --- a/domain/secretbackend/state/state_test.go +++ b/domain/secretbackend/state/state_test.go @@ -218,7 +218,7 @@ func (s *stateSuite) createModelWithName(c *gc.C, modelType coremodel.ModelType, context.Background(), modelUUID, modelType, - model.ModelCreationArgs{ + model.ControllerDBModelCreationArgs{ AgentVersion: version.Current, Cloud: "my-cloud", CloudRegion: "my-region", diff --git a/domain/services/testing/suite.go b/domain/services/testing/suite.go index 41bd6c12daf..6e1c930da4c 100644 --- a/domain/services/testing/suite.go +++ b/domain/services/testing/suite.go @@ -184,7 +184,7 @@ func (s *DomainServicesSuite) SeedModelDatabases(c *gc.C) { controllerUUID, err := uuid.UUIDFromString(jujutesting.ControllerTag.Id()) c.Assert(err, jc.ErrorIsNil) - controllerArgs := modeldomain.ModelCreationArgs{ + controllerArgs := modeldomain.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: s.CloudName, CloudRegion: "dummy-region", @@ -193,13 +193,13 @@ func (s *DomainServicesSuite) SeedModelDatabases(c *gc.C) { Owner: s.AdminUserUUID, } - fn := modelbootstrap.CreateModel(s.ControllerModelUUID, controllerArgs) + fn := modelbootstrap.CreateControllerDBModelRecord(s.ControllerModelUUID, controllerArgs) c.Assert(backendbootstrap.CreateDefaultBackends(coremodel.IAAS)( ctx, s.ControllerTxnRunner(), s.ModelTxnRunner(c, s.ControllerModelUUID.String())), jc.ErrorIsNil) err = fn(ctx, s.ControllerTxnRunner(), s.NoopTxnRunner()) c.Assert(err, jc.ErrorIsNil) - err = modelbootstrap.CreateReadOnlyModel(s.ControllerModelUUID, controllerUUID)(ctx, s.ControllerTxnRunner(), s.ModelTxnRunner(c, s.ControllerModelUUID.String())) + err = modelbootstrap.CreateModelDBModelRecord(s.ControllerModelUUID, controllerUUID)(ctx, s.ControllerTxnRunner(), s.ModelTxnRunner(c, s.ControllerModelUUID.String())) c.Assert(err, jc.ErrorIsNil) fn = modelconfigbootstrap.SetModelConfig( @@ -210,7 +210,7 @@ func (s *DomainServicesSuite) SeedModelDatabases(c *gc.C) { err = fn(ctx, s.ControllerTxnRunner(), s.ModelTxnRunner(c, s.ControllerModelUUID.String())) c.Assert(err, jc.ErrorIsNil) - modelArgs := modeldomain.ModelCreationArgs{ + modelArgs := modeldomain.ControllerDBModelCreationArgs{ AgentVersion: jujuversion.Current, Cloud: s.CloudName, Credential: s.CredentialKey, @@ -218,11 +218,11 @@ func (s *DomainServicesSuite) SeedModelDatabases(c *gc.C) { Owner: s.AdminUserUUID, } - fn = modelbootstrap.CreateModel(s.DefaultModelUUID, modelArgs) + fn = modelbootstrap.CreateControllerDBModelRecord(s.DefaultModelUUID, modelArgs) err = fn(ctx, s.ControllerTxnRunner(), s.NoopTxnRunner()) c.Assert(err, jc.ErrorIsNil) - err = modelbootstrap.CreateReadOnlyModel(s.DefaultModelUUID, controllerUUID)(ctx, s.ControllerTxnRunner(), s.ModelTxnRunner(c, s.DefaultModelUUID.String())) + err = modelbootstrap.CreateModelDBModelRecord(s.DefaultModelUUID, controllerUUID)(ctx, s.ControllerTxnRunner(), s.ModelTxnRunner(c, s.DefaultModelUUID.String())) c.Assert(err, jc.ErrorIsNil) fn = modelconfigbootstrap.SetModelConfig(