diff --git a/internal/jimm/controller.go b/internal/jimm/controller.go index 3be35d32f..ea0d16dcc 100644 --- a/internal/jimm/controller.go +++ b/internal/jimm/controller.go @@ -522,7 +522,7 @@ func (j *JIMM) ImportModel(ctx context.Context, u *dbmodel.User, controllerName // models on the incoming cloud. allCredentials, err := j.Database.GetUserCloudCredentials(ctx, &ownerUser, cloudTag.Id()) if err != nil { - errors.E(op, err) + return errors.E(op, err) } if len(allCredentials) == 0 { return errors.E(op, errors.CodeNotFound, fmt.Sprintf("Failed to find cloud credential for user %s on cloud %s", ownerUser.Username, cloudTag.Id())) @@ -557,7 +557,7 @@ func (j *JIMM) ImportModel(ctx context.Context, u *dbmodel.User, controllerName var usersExcludingLocalUsers []dbmodel.UserModelAccess for _, userAccess := range model.Users { - username, err := names.ParseUserTag(userAccess.User.Username) + username, err := names.ParseUserTag("user" + "-" + userAccess.User.Username) if err != nil { zapctx.Error(ctx, "failed to parse user tag", zap.String("username", userAccess.User.Username)) continue diff --git a/internal/jimm/controller_test.go b/internal/jimm/controller_test.go index 4a11d4e42..5db84f37e 100644 --- a/internal/jimm/controller_test.go +++ b/internal/jimm/controller_test.go @@ -879,6 +879,26 @@ func TestImportModel(t *testing.T) { return errors.E(errors.CodeNotFound, "model not found") }, expectedError: "model not found", + }, { + about: "fail import from local user without newOwner flag", + user: "alice@external", + controllerName: "test-controller", + newOwner: "", + modelUUID: "00000002-0000-0000-0000-000000000001", + modelInfo: func(_ context.Context, info *jujuparams.ModelInfo) error { + info.Name = "test-model" + info.Type = "test-type" + info.UUID = "00000002-0000-0000-0000-000000000001" + info.ControllerUUID = "00000001-0000-0000-0000-000000000001" + info.DefaultSeries = "test-series" + info.CloudTag = names.NewCloudTag("test-cloud").String() + info.CloudRegion = "test-region" + info.CloudCredentialTag = names.NewCloudCredentialTag("test-cloud/alice@external/unknown-credential").String() + info.CloudCredentialValidity = &trueValue + info.OwnerTag = names.NewUserTag("local-user").String() + return nil + }, + expectedError: `cannot import model from local user, try --owner to switch the model owner`, }, { about: "cloud credentials not found", user: "alice@external",