-
Notifications
You must be signed in to change notification settings - Fork 294
Implement multi-stage test registry interface #98
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
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
AlexNPavel:test-flow-imp
Aug 27, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| package registry | ||
|
|
||
| import ( | ||
| api "github.com/openshift/ci-tools/pkg/api" | ||
| types "github.com/openshift/ci-tools/pkg/steps/types" | ||
| "k8s.io/apimachinery/pkg/util/errors" | ||
| ) | ||
|
|
||
| type Resolver interface { | ||
| Resolve(config api.MultiStageTestConfiguration) (types.TestFlow, error) | ||
| } | ||
|
|
||
| // Registry will hold all the registry information needed to convert between the | ||
| // user provided configs referencing the registry and the internal, complete | ||
| // representation | ||
| type registry struct{} | ||
|
|
||
| func NewResolver() Resolver { | ||
| return ®istry{} | ||
| } | ||
|
|
||
| func (r *registry) Resolve(config api.MultiStageTestConfiguration) (types.TestFlow, error) { | ||
| var resolveErrors []error | ||
| expandedFlow := types.TestFlow{ | ||
| ClusterProfile: config.ClusterProfile, | ||
| } | ||
| for _, external := range config.Pre { | ||
| newStep := toInternal(external) | ||
| expandedFlow.Pre = append(expandedFlow.Pre, newStep) | ||
| } | ||
| for _, external := range config.Test { | ||
| newStep := toInternal(external) | ||
| expandedFlow.Test = append(expandedFlow.Test, newStep) | ||
| } | ||
| for _, external := range config.Post { | ||
| newStep := toInternal(external) | ||
| expandedFlow.Post = append(expandedFlow.Post, newStep) | ||
| } | ||
| // This currently never gets run as we don't have any situations that can result in errors yet. | ||
| // This will become used as we add more functionality. | ||
| if resolveErrors != nil { | ||
| return types.TestFlow{}, errors.NewAggregate(resolveErrors) | ||
| } | ||
| return expandedFlow, nil | ||
| } | ||
|
|
||
| func toInternal(input api.TestStep) types.TestStep { | ||
| return types.TestStep{ | ||
| Name: input.Name, | ||
| Image: input.Image, | ||
| Commands: input.Commands, | ||
| ArtifactDir: input.ArtifactDir, | ||
| Resources: input.Resources, | ||
| } | ||
| } |
This file contains hidden or 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,96 @@ | ||
| package registry | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| api "github.com/openshift/ci-tools/pkg/api" | ||
| types "github.com/openshift/ci-tools/pkg/steps/types" | ||
| "k8s.io/apimachinery/pkg/util/diff" | ||
| ) | ||
|
|
||
| func TestResolve(t *testing.T) { | ||
| for _, testCase := range []struct { | ||
| name string | ||
| config api.MultiStageTestConfiguration | ||
| expectedRes types.TestFlow | ||
| expectErr bool | ||
| }{{ | ||
| // This is a full config that should not change (other than struct) when passed to the Resolver | ||
| name: "Full AWS IPI", | ||
| config: api.MultiStageTestConfiguration{ | ||
| ClusterProfile: api.ClusterProfileAWS, | ||
| Pre: []api.TestStep{{ | ||
| Name: "ipi-install", | ||
| Image: "installer", | ||
| Commands: "openshift-cluster install", | ||
| Resources: api.ResourceRequirements{ | ||
| Requests: api.ResourceList{"cpu": "1000m"}, | ||
| Limits: api.ResourceList{"memory": "2Gi"}, | ||
| }, | ||
| }}, | ||
| Test: []api.TestStep{{ | ||
| Name: "e2e", | ||
| Image: "my-image", | ||
| Commands: "make custom-e2e", | ||
| Resources: api.ResourceRequirements{ | ||
| Requests: api.ResourceList{"cpu": "1000m"}, | ||
| Limits: api.ResourceList{"memory": "2Gi"}, | ||
| }, | ||
| }}, | ||
| Post: []api.TestStep{{ | ||
| Name: "ipi-teardown", | ||
| Image: "installer", | ||
| Commands: "openshift-cluster destroy", | ||
| Resources: api.ResourceRequirements{ | ||
| Requests: api.ResourceList{"cpu": "1000m"}, | ||
| Limits: api.ResourceList{"memory": "2Gi"}, | ||
| }, | ||
| }}, | ||
| }, | ||
| expectedRes: types.TestFlow{ | ||
| ClusterProfile: api.ClusterProfileAWS, | ||
| Pre: []types.TestStep{{ | ||
| Name: "ipi-install", | ||
| Image: "installer", | ||
| Commands: "openshift-cluster install", | ||
| Resources: api.ResourceRequirements{ | ||
| Requests: api.ResourceList{"cpu": "1000m"}, | ||
| Limits: api.ResourceList{"memory": "2Gi"}, | ||
| }, | ||
| }}, | ||
| Test: []types.TestStep{{ | ||
| Name: "e2e", | ||
| Image: "my-image", | ||
| Commands: "make custom-e2e", | ||
| Resources: api.ResourceRequirements{ | ||
| Requests: api.ResourceList{"cpu": "1000m"}, | ||
| Limits: api.ResourceList{"memory": "2Gi"}, | ||
| }, | ||
| }}, | ||
| Post: []types.TestStep{{ | ||
| Name: "ipi-teardown", | ||
| Image: "installer", | ||
| Commands: "openshift-cluster destroy", | ||
| Resources: api.ResourceRequirements{ | ||
| Requests: api.ResourceList{"cpu": "1000m"}, | ||
| Limits: api.ResourceList{"memory": "2Gi"}, | ||
| }, | ||
| }}, | ||
| }, | ||
| expectErr: false, | ||
| }, {}} { | ||
| t.Run(testCase.name, func(t *testing.T) { | ||
| ret, err := NewResolver().Resolve(testCase.config) | ||
| if !testCase.expectErr && err != nil { | ||
| t.Errorf("%s: expected no error but got: %s", testCase.name, err) | ||
| } | ||
| if testCase.expectErr && err == nil { | ||
| t.Errorf("%s: expected error but got none", testCase.name) | ||
| } | ||
| if !reflect.DeepEqual(ret, testCase.expectedRes) { | ||
| t.Errorf("%s: fo incorrect output: %s", testCase.name, diff.ObjectReflectDiff(ret, testCase.expectedRes)) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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,23 @@ | ||
| package steptypes | ||
|
|
||
| import ( | ||
| api "github.com/openshift/ci-tools/pkg/api" | ||
| ) | ||
|
|
||
| // TestStep contains a full definition of a test step from a MultiStageTestConfiguration | ||
| type TestStep struct { | ||
AlexNPavel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Name string | ||
| Image string | ||
| Commands string | ||
| ArtifactDir string | ||
| Resources api.ResourceRequirements | ||
| } | ||
|
|
||
| // TestFlow contains the separate stages of a MultiStageTestConfigurations with full TestSteps in each stage | ||
| // ClusterProfile can be used to define an infrastructure/profile to use (i.e. aws, azure4, gcp, etc.) | ||
| type TestFlow struct { | ||
AlexNPavel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ClusterProfile api.ClusterProfile | ||
| Pre []TestStep | ||
| Test []TestStep | ||
| Post []TestStep | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.