-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return model summaries with new model owner (#1367)
- refactor ModelInfo slightly to use a separate function where we merge the juju model info with JIMM specific data - refactor the test for ModelInfo to reduce duplication - tweak the test dialer to have less surprising behavior
- Loading branch information
Showing
3 changed files
with
92 additions
and
137 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
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 |
---|---|---|
|
@@ -1230,19 +1230,8 @@ const modelInfoTestEnvWithEveryoneAccess = modelInfoTestEnv + ` | |
access: read | ||
` | ||
|
||
var modelInfoTests = []struct { | ||
name string | ||
env string | ||
username string | ||
uuid string | ||
expectModelInfo *jujuparams.ModelInfo | ||
expectError string | ||
}{{ | ||
name: "AdminUser", | ||
env: modelInfoTestEnv, | ||
username: "[email protected]", | ||
uuid: "00000002-0000-0000-0000-000000000001", | ||
expectModelInfo: &jujuparams.ModelInfo{ | ||
func modelInfoTestExpectedModelInfo(canReadMachineInfo bool, limitedExpectedUsers []jujuparams.ModelUserInfo) *jujuparams.ModelInfo { | ||
info := jujuparams.ModelInfo{ | ||
Name: "model-1", | ||
Type: "iaas", | ||
UUID: "00000002-0000-0000-0000-000000000001", | ||
|
@@ -1290,86 +1279,51 @@ var modelInfoTests = []struct { | |
Level: "unsupported", | ||
}, | ||
AgentVersion: newVersion("1.2.3"), | ||
}, | ||
}, { | ||
name: "WriteUser", | ||
env: modelInfoTestEnv, | ||
username: "[email protected]", | ||
uuid: "00000002-0000-0000-0000-000000000001", | ||
expectModelInfo: &jujuparams.ModelInfo{ | ||
Name: "model-1", | ||
Type: "iaas", | ||
UUID: "00000002-0000-0000-0000-000000000001", | ||
ControllerUUID: "00000001-0000-0000-0000-000000000001", | ||
ProviderType: "test-provider", | ||
DefaultSeries: "warty", | ||
CloudTag: names.NewCloudTag("test-cloud").String(), | ||
CloudRegion: "test-cloud-region", | ||
CloudCredentialTag: names.NewCloudCredentialTag("test-cloud/[email protected]/cred-1").String(), | ||
OwnerTag: names.NewUserTag("[email protected]").String(), | ||
Life: life.Value(state.Alive.String()), | ||
Status: jujuparams.EntityStatus{ | ||
Status: "available", | ||
Info: "OK!", | ||
Since: newDate(2020, 2, 20, 20, 2, 20, 0, time.UTC), | ||
}, | ||
Users: []jujuparams.ModelUserInfo{{ | ||
UserName: "[email protected]", | ||
Access: "write", | ||
}}, | ||
Machines: []jujuparams.ModelMachineInfo{{ | ||
Id: "0", | ||
Hardware: jimmtest.ParseMachineHardware("arch=amd64 mem=8096 root-disk=10240 cores=1"), | ||
InstanceId: "00000009-0000-0000-0000-0000000000000", | ||
DisplayName: "Machine 0", | ||
Status: "available", | ||
Message: "OK!", | ||
HasVote: true, | ||
}, { | ||
Id: "1", | ||
Hardware: jimmtest.ParseMachineHardware("arch=amd64 mem=8096 root-disk=10240 cores=2"), | ||
InstanceId: "00000009-0000-0000-0000-0000000000001", | ||
DisplayName: "Machine 1", | ||
Status: "available", | ||
Message: "OK!", | ||
HasVote: true, | ||
}}, | ||
SLA: &jujuparams.ModelSLAInfo{ | ||
Level: "unsupported", | ||
}, | ||
AgentVersion: newVersion("1.2.3"), | ||
}, | ||
}, { | ||
name: "ReadUser", | ||
env: modelInfoTestEnv, | ||
username: "[email protected]", | ||
uuid: "00000002-0000-0000-0000-000000000001", | ||
expectModelInfo: &jujuparams.ModelInfo{ | ||
Name: "model-1", | ||
Type: "iaas", | ||
UUID: "00000002-0000-0000-0000-000000000001", | ||
ControllerUUID: "00000001-0000-0000-0000-000000000001", | ||
ProviderType: "test-provider", | ||
DefaultSeries: "warty", | ||
CloudTag: names.NewCloudTag("test-cloud").String(), | ||
CloudRegion: "test-cloud-region", | ||
CloudCredentialTag: names.NewCloudCredentialTag("test-cloud/[email protected]/cred-1").String(), | ||
OwnerTag: names.NewUserTag("[email protected]").String(), | ||
Life: life.Value(state.Alive.String()), | ||
Status: jujuparams.EntityStatus{ | ||
Status: "available", | ||
Info: "OK!", | ||
Since: newDate(2020, 2, 20, 20, 2, 20, 0, time.UTC), | ||
}, | ||
Users: []jujuparams.ModelUserInfo{{ | ||
UserName: "[email protected]", | ||
Access: "read", | ||
}}, | ||
SLA: &jujuparams.ModelSLAInfo{ | ||
Level: "unsupported", | ||
}, | ||
AgentVersion: newVersion("1.2.3"), | ||
}, | ||
} | ||
if !canReadMachineInfo { | ||
info.Machines = nil | ||
} | ||
if limitedExpectedUsers != nil { | ||
info.Users = limitedExpectedUsers | ||
} | ||
return &info | ||
} | ||
|
||
var modelInfoTests = []struct { | ||
name string | ||
env string | ||
username string | ||
uuid string | ||
originModelOwner string | ||
expectModelInfo *jujuparams.ModelInfo | ||
expectError string | ||
}{{ | ||
name: "AdminUser", | ||
env: modelInfoTestEnv, | ||
username: "[email protected]", | ||
uuid: "00000002-0000-0000-0000-000000000001", | ||
originModelOwner: names.NewUserTag("[email protected]").String(), | ||
expectModelInfo: modelInfoTestExpectedModelInfo(true, nil), | ||
}, { | ||
name: "WriteUser", | ||
env: modelInfoTestEnv, | ||
username: "[email protected]", | ||
uuid: "00000002-0000-0000-0000-000000000001", | ||
originModelOwner: names.NewUserTag("[email protected]").String(), | ||
expectModelInfo: modelInfoTestExpectedModelInfo(true, []jujuparams.ModelUserInfo{{ | ||
UserName: "[email protected]", | ||
Access: "write", | ||
}}), | ||
}, { | ||
name: "ReadUser", | ||
env: modelInfoTestEnv, | ||
username: "[email protected]", | ||
uuid: "00000002-0000-0000-0000-000000000001", | ||
originModelOwner: names.NewUserTag("[email protected]").String(), | ||
expectModelInfo: modelInfoTestExpectedModelInfo(false, []jujuparams.ModelUserInfo{{ | ||
UserName: "[email protected]", | ||
Access: "read", | ||
}}), | ||
}, { | ||
name: "NoAccess", | ||
env: modelInfoTestEnv, | ||
|
@@ -1383,36 +1337,22 @@ var modelInfoTests = []struct { | |
uuid: "00000002-0000-0000-0000-000000000002", | ||
expectError: "model not found", | ||
}, { | ||
name: "Access through everyone user", | ||
env: modelInfoTestEnvWithEveryoneAccess, | ||
username: "[email protected]", | ||
uuid: "00000002-0000-0000-0000-000000000001", | ||
expectModelInfo: &jujuparams.ModelInfo{ | ||
Name: "model-1", | ||
Type: "iaas", | ||
UUID: "00000002-0000-0000-0000-000000000001", | ||
ControllerUUID: "00000001-0000-0000-0000-000000000001", | ||
ProviderType: "test-provider", | ||
DefaultSeries: "warty", | ||
CloudTag: names.NewCloudTag("test-cloud").String(), | ||
CloudRegion: "test-cloud-region", | ||
CloudCredentialTag: names.NewCloudCredentialTag("test-cloud/[email protected]/cred-1").String(), | ||
OwnerTag: names.NewUserTag("[email protected]").String(), | ||
Life: life.Value(state.Alive.String()), | ||
Status: jujuparams.EntityStatus{ | ||
Status: "available", | ||
Info: "OK!", | ||
Since: newDate(2020, 2, 20, 20, 2, 20, 0, time.UTC), | ||
}, | ||
Users: []jujuparams.ModelUserInfo{{ | ||
UserName: "everyone@external", | ||
Access: "read", | ||
}}, | ||
SLA: &jujuparams.ModelSLAInfo{ | ||
Level: "unsupported", | ||
}, | ||
AgentVersion: newVersion("1.2.3"), | ||
}, | ||
name: "Access through everyone user", | ||
env: modelInfoTestEnvWithEveryoneAccess, | ||
username: "[email protected]", | ||
uuid: "00000002-0000-0000-0000-000000000001", | ||
originModelOwner: names.NewUserTag("[email protected]").String(), | ||
expectModelInfo: modelInfoTestExpectedModelInfo(false, []jujuparams.ModelUserInfo{{ | ||
UserName: "everyone@external", | ||
Access: "read", | ||
}}), | ||
}, { | ||
name: "Owner field is replaced", | ||
env: modelInfoTestEnv, | ||
username: "[email protected]", | ||
uuid: "00000002-0000-0000-0000-000000000001", | ||
originModelOwner: names.NewUserTag("bob").String(), | ||
expectModelInfo: modelInfoTestExpectedModelInfo(true, nil), | ||
}, | ||
} | ||
|
||
|
@@ -1443,7 +1383,7 @@ func TestModelInfo(t *testing.T) { | |
mi.CloudTag = names.NewCloudTag("test-cloud").String() | ||
mi.CloudRegion = "test-cloud-region" | ||
mi.CloudCredentialTag = names.NewCloudCredentialTag("test-cloud/[email protected]/cred-1").String() | ||
mi.OwnerTag = names.NewUserTag("[email protected]").String() | ||
mi.OwnerTag = test.originModelOwner | ||
mi.Life = life.Value(state.Alive.String()) | ||
mi.Status = jujuparams.EntityStatus{ | ||
Status: "available", | ||
|
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