-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MULTIARCH-3965: Check if PER is enabled in the target PowerVS workspace #7683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,23 @@ var ( | |
| ID: &validRG, | ||
| }, | ||
| } | ||
| regionWithPER = "dal10" | ||
| regionWithoutPER = "foo99" | ||
| regionPERUnknown = "bah77" | ||
| mapWithPERFalse = map[string]bool{ | ||
| "disaster-recover-site": true, | ||
| "power-edge-router": false, | ||
| "vpn-connections": true, | ||
| } | ||
| mapWithPERTrue = map[string]bool{ | ||
| "disaster-recover-site": true, | ||
| "power-edge-router": true, | ||
| "vpn-connections": true, | ||
| } | ||
|
||
| mapPERUnknown = map[string]bool{ | ||
| "disaster-recover-site": true, | ||
| "power-vpn-connections": false, | ||
| } | ||
| ) | ||
|
|
||
| func validInstallConfig() *types.InstallConfig { | ||
|
|
@@ -471,6 +488,74 @@ func createComputes(numComputes int32, compute *machinev1.PowerVSMachineProvider | |
| return computes | ||
| } | ||
|
|
||
| func TestValidatePERAvailability(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| edits editFunctions | ||
| errorMsg string | ||
| }{ | ||
| { | ||
| name: "Region without PER", | ||
| edits: editFunctions{ | ||
| func(ic *types.InstallConfig) { | ||
| ic.Platform.PowerVS.Zone = regionWithoutPER | ||
| }, | ||
| }, | ||
| errorMsg: fmt.Sprintf("power-edge-router is not available at: %s", regionWithoutPER), | ||
| }, | ||
| { | ||
| name: "Region with PER", | ||
| edits: editFunctions{ | ||
| func(ic *types.InstallConfig) { | ||
| ic.Platform.PowerVS.Zone = regionWithPER | ||
| }, | ||
| }, | ||
| errorMsg: "", | ||
| }, | ||
| { | ||
| name: "Region with no PER availability info", | ||
| edits: editFunctions{ | ||
| func(ic *types.InstallConfig) { | ||
| ic.Platform.PowerVS.Zone = regionPERUnknown | ||
| }, | ||
| }, | ||
| errorMsg: fmt.Sprintf("power-edge-router capability unknown at: %s", regionPERUnknown), | ||
| }, | ||
| } | ||
| setMockEnvVars() | ||
|
|
||
| mockCtrl := gomock.NewController(t) | ||
| defer mockCtrl.Finish() | ||
|
|
||
| powervsClient := mock.NewMockAPI(mockCtrl) | ||
|
|
||
| // Mocks: PER-absent region results in false | ||
| powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionWithoutPER).Return(mapWithPERFalse, nil) | ||
|
|
||
| // Mocks: PER-enabled region results in true | ||
| powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionWithPER).Return(mapWithPERTrue, nil) | ||
|
|
||
| // Mocks: PER-unknown region results in false | ||
| powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionPERUnknown).Return(mapPERUnknown, nil) | ||
|
|
||
| // Run tests | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| editedInstallConfig := validInstallConfig() | ||
| for _, edit := range tc.edits { | ||
| edit(editedInstallConfig) | ||
| } | ||
|
|
||
| aggregatedErrors := powervs.ValidatePERAvailability(powervsClient, editedInstallConfig) | ||
| if tc.errorMsg != "" { | ||
| assert.Regexp(t, tc.errorMsg, aggregatedErrors) | ||
| } else { | ||
| assert.NoError(t, aggregatedErrors) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func setMockEnvVars() { | ||
| os.Setenv("POWERVS_AUTH_FILEPATH", "./tmp/powervs/config.json") | ||
| os.Setenv("IBMID", "foo") | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't need to be addressed in this PR, but maybe
powervscan follow the pattern of the other platforms and use aValidateForProvisioningfunction that encapsulates all the different validations needed.