-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(internal/db/cloud.go): add
virtual
field to CloudRegion
When we add a cloud reports no cloud regions we add a virtual "default" region to keep the controller lookup logic the same when adding a model. Then only difference is that we do not send the cloud region name in ModelCreateArgs to the controller.
- Loading branch information
1 parent
8c6df2a
commit 5b8b195
Showing
58 changed files
with
215 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
package cmd_test | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package auth_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
package db_test | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package db_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package dbmodel | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package dbmodel_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package dbmodel | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package dbmodel_test | ||
|
||
|
3 changes: 3 additions & 0 deletions
3
internal/dbmodel/sql/postgres/021_add_virtual_column_to_cloud_regions.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- adds a boolean column to the cloud_regions table. | ||
|
||
ALTER TABLE cloud_regions ADD COLUMN virtual BOOLEAN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package jimm | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package jimm | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package jimm_test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1054,6 +1054,106 @@ users: | |
OwnerTag: names.NewUserTag("[email protected]").String(), | ||
}, | ||
expectError: "no cloud specified for model; please specify one", | ||
}, { | ||
name: "CreateModelOnACloudWithNoRegions", | ||
// test-cloud has one virtual cloud region | ||
env: ` | ||
clouds: | ||
- name: test-cloud | ||
type: test-provider | ||
regions: | ||
- name: default | ||
virtual: true | ||
users: | ||
- user: [email protected] | ||
access: add-model | ||
cloud-credentials: | ||
- name: test-credential-1 | ||
owner: [email protected] | ||
cloud: test-cloud | ||
auth-type: empty | ||
controllers: | ||
- name: controller-1 | ||
uuid: 00000000-0000-0000-0000-0000-0000000000001 | ||
cloud: test-cloud | ||
region: default | ||
cloud-regions: | ||
- cloud: test-cloud | ||
region: default | ||
priority: 0 | ||
- name: controller-2 | ||
uuid: 00000000-0000-0000-0000-0000-0000000000002 | ||
cloud: test-cloud | ||
region: default | ||
cloud-regions: | ||
- cloud: test-cloud | ||
region: default | ||
priority: 2 | ||
`[1:], | ||
updateCredential: func(_ context.Context, _ jujuparams.TaggedCredential) ([]jujuparams.UpdateCredentialModelResult, error) { | ||
return nil, nil | ||
}, | ||
grantJIMMModelAdmin: func(_ context.Context, _ names.ModelTag) error { | ||
return nil | ||
}, | ||
createModel: assertCreateModelArgs(&jujuparams.ModelCreateArgs{ | ||
Name: "test-model", | ||
OwnerTag: names.NewUserTag("[email protected]").String(), | ||
CloudTag: names.NewCloudTag("test-cloud").String(), | ||
// we expect cloud region to be empty, because it is a virtual "default" region | ||
CloudRegion: "", | ||
CloudCredentialTag: names.NewCloudCredentialTag("test-cloud/[email protected]/test-credential-1").String(), | ||
}, createModel(` | ||
uuid: 00000001-0000-0000-0000-0000-000000000001 | ||
status: | ||
status: started | ||
info: running a test | ||
life: alive | ||
users: | ||
- user: [email protected] | ||
access: admin | ||
- user: bob | ||
access: read | ||
`[1:])), | ||
username: "[email protected]", | ||
jimmAdmin: true, | ||
cloudCredTag: names.NewCloudCredentialTag("test-cloud/[email protected]/test-credential-1"), | ||
args: jujuparams.ModelCreateArgs{ | ||
Name: "test-model", | ||
OwnerTag: names.NewUserTag("[email protected]").String(), | ||
CloudTag: names.NewCloudTag("test-cloud").String(), | ||
// Creating a model without specifying the cloud region | ||
CloudRegion: "", | ||
}, | ||
expectModel: dbmodel.Model{ | ||
Name: "test-model", | ||
UUID: sql.NullString{ | ||
String: "00000001-0000-0000-0000-0000-000000000001", | ||
Valid: true, | ||
}, | ||
Owner: dbmodel.Identity{ | ||
Name: "[email protected]", | ||
}, | ||
Controller: dbmodel.Controller{ | ||
Name: "controller-2", | ||
UUID: "00000000-0000-0000-0000-0000-0000000000002", | ||
CloudName: "test-cloud", | ||
CloudRegion: "default", | ||
}, | ||
CloudRegion: dbmodel.CloudRegion{ | ||
Cloud: dbmodel.Cloud{ | ||
Name: "test-cloud", | ||
Type: "test-provider", | ||
}, | ||
Name: "default", | ||
Virtual: true, | ||
}, | ||
CloudCredential: dbmodel.CloudCredential{ | ||
Name: "test-credential-1", | ||
AuthType: "empty", | ||
}, | ||
Life: state.Alive.String(), | ||
}, | ||
}} | ||
|
||
func TestAddModel(t *testing.T) { | ||
|
@@ -1151,11 +1251,32 @@ func assertConfig(config map[string]interface{}, fnc func(context.Context, *juju | |
} | ||
for k, v := range args.Config { | ||
if config[k] != v { | ||
return errors.E(fmt.Sprintf("config value mismatch for key %s", k)) | ||
return errors.E(fmt.Sprintf("config value mismatch for key %s: %s -> %s", k, config[k], v)) | ||
} | ||
} | ||
return fnc(ctx, args, mi) | ||
} | ||
} | ||
|
||
func assertCreateModelArgs(expectedArgs *jujuparams.ModelCreateArgs, fnc func(context.Context, *jujuparams.ModelCreateArgs, *jujuparams.ModelInfo) error) func(context.Context, *jujuparams.ModelCreateArgs, *jujuparams.ModelInfo) error { | ||
return func(ctx context.Context, args *jujuparams.ModelCreateArgs, mi *jujuparams.ModelInfo) error { | ||
if expectedArgs.Name != args.Name { | ||
return fmt.Errorf("name mismatch: expected %q, got %q", expectedArgs.Name, args.Name) | ||
} | ||
if expectedArgs.OwnerTag != args.OwnerTag { | ||
return fmt.Errorf("owner mismatch: expected %q, got %q", expectedArgs.Name, args.Name) | ||
} | ||
if expectedArgs.CloudTag != args.CloudTag { | ||
return fmt.Errorf("cloud mismatch: expected %q, got %q", expectedArgs.Name, args.Name) | ||
} | ||
if expectedArgs.CloudRegion != args.CloudRegion { | ||
return fmt.Errorf("cloud region mismatch: expected %q, got %q", expectedArgs.Name, args.Name) | ||
} | ||
if expectedArgs.CloudCredentialTag != args.CloudCredentialTag { | ||
return fmt.Errorf("credential mismatch: expected %q, got %q", expectedArgs.Name, args.Name) | ||
} | ||
return fnc(ctx, args, mi) | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 Canonical. | ||
// Copyright 2025 Canonical. | ||
|
||
package jimm | ||
|
||
|
Oops, something went wrong.