Skip to content

Commit

Permalink
Extra test and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Sep 6, 2023
1 parent 8782743 commit 494eef5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/jimm/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions internal/jimm/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 494eef5

Please sign in to comment.