-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Add list all-tests command for aggregated test listing #31105
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
Open
petr-muller
wants to merge
4
commits into
openshift:main
Choose a base branch
from
petr-muller:ocpbugs-84257-list-tests-vs-run-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aa53685
Defer router test kubeClient init to BeforeEach
petr-muller dc541a2
Add WithPayloadOnly option to ExtractAllTestBinaries
petr-muller f408a27
Add list all-tests command for aggregated test listing
petr-muller ee96fdb
Add e2e test validating payload extension binaries respond to info
petr-muller 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| package list | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "sort" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "github.com/sirupsen/logrus" | ||
| "github.com/spf13/cobra" | ||
| "gopkg.in/yaml.v3" | ||
| "k8s.io/cli-runtime/pkg/genericclioptions" | ||
| "k8s.io/kubectl/pkg/util/templates" | ||
|
|
||
| "github.com/openshift/origin/pkg/test/extensions" | ||
| "github.com/openshift/origin/pkg/testsuites" | ||
| ) | ||
|
|
||
| // resolveSuiteQualifiers finds a suite by name, first checking origin's internal | ||
| // suites, then checking suites advertised by the already-extracted extension binaries. | ||
| func resolveSuiteQualifiers(ctx context.Context, suiteName string, binaries extensions.TestBinaries) ([]string, error) { | ||
| for _, s := range testsuites.InternalTestSuites() { | ||
| if s.Name == suiteName { | ||
| return s.Qualifiers, nil | ||
| } | ||
| } | ||
|
|
||
| extensionInfos, err := binaries.Info(ctx, 4) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get extension info: %w", err) | ||
| } | ||
| for _, e := range extensionInfos { | ||
| for _, s := range e.Suites { | ||
| if s.Name == suiteName { | ||
| return s.Qualifiers, nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nil, fmt.Errorf("suite %q not found", suiteName) | ||
| } | ||
|
|
||
| func NewListAllTestsCommand(streams genericclioptions.IOStreams) *cobra.Command { | ||
| var suiteName string | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "all-tests", | ||
| Short: "List tests from all extension binaries", | ||
| Long: templates.LongDesc(` | ||
| List all tests discovered from all extension binaries in the release payload. | ||
|
|
||
| Unlike 'list tests', which lists tests from a single extension component, | ||
| this command aggregates tests from all extension binaries — the same set | ||
| of tests that 'run' operates on. | ||
|
|
||
| Use --suite to filter tests by a suite's qualifiers. This works with both | ||
| origin-defined suites (like openshift/network/third-party) and suites | ||
| advertised by extension binaries. | ||
|
|
||
| This command does not require cluster access. | ||
| `), | ||
| SilenceUsage: true, | ||
| SilenceErrors: true, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := context.Background() | ||
|
|
||
| const defaultBinaryParallelism = 10 | ||
|
|
||
| extractionContext, extractionContextCancel := context.WithTimeout(ctx, 30*60*1e9) | ||
| defer extractionContextCancel() | ||
| cleanUpFn, allBinaries, _, err := extensions.ExtractAllTestBinaries(extractionContext, defaultBinaryParallelism, extensions.WithPayloadOnly()) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to extract test binaries: %w", err) | ||
| } | ||
| defer cleanUpFn() | ||
|
|
||
| infoContext, infoContextCancel := context.WithTimeout(ctx, 30*60*1e9) | ||
| defer infoContextCancel() | ||
| logrus.Infof("Fetching info from %d extension binaries", len(allBinaries)) | ||
| if _, err := allBinaries.Info(infoContext, defaultBinaryParallelism); err != nil { | ||
| logrus.Warnf("Some extension binaries failed info fetch (they may require cluster access): %v", err) | ||
| } | ||
|
|
||
| // Filter to binaries that successfully returned info, since ListTests | ||
| // requires info to be populated. Binaries that failed info (e.g. due to | ||
| // missing cluster access) are skipped. | ||
| var availableBinaries extensions.TestBinaries | ||
| for _, b := range allBinaries { | ||
| if b.HasInfo() { | ||
| availableBinaries = append(availableBinaries, b) | ||
| } | ||
| } | ||
| logrus.Infof("%d of %d binaries available for listing", len(availableBinaries), len(allBinaries)) | ||
|
|
||
| listContext, listContextCancel := context.WithTimeout(ctx, 10*60*1e9) | ||
| defer listContextCancel() | ||
|
|
||
| specs, err := availableBinaries.ListTests(listContext, defaultBinaryParallelism, nil) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to list tests: %w", err) | ||
| } | ||
|
|
||
| logrus.Infof("Discovered %d total tests", len(specs)) | ||
|
|
||
| if suiteName != "" { | ||
| qualifiers, err := resolveSuiteQualifiers(ctx, suiteName, availableBinaries) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| specs, err = extensions.FilterWrappedSpecs(specs, qualifiers) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to filter tests by suite qualifiers: %w", err) | ||
| } | ||
|
|
||
| logrus.Infof("Suite %q selected %d tests", suiteName, len(specs)) | ||
| } | ||
|
|
||
| outputFormat, err := cmd.Flags().GetString("output") | ||
| if err != nil { | ||
| return errors.Wrapf(err, "error accessing flag output for command %s", cmd.Name()) | ||
| } | ||
|
|
||
| sort.Slice(specs, func(i, j int) bool { | ||
| return specs[i].Name < specs[j].Name | ||
| }) | ||
|
|
||
| switch outputFormat { | ||
| case "": | ||
| for _, spec := range specs { | ||
| fmt.Fprintln(streams.Out, spec.Name) | ||
| } | ||
| case "json": | ||
| data, err := json.MarshalIndent(specs, "", " ") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal tests to JSON: %w", err) | ||
| } | ||
| fmt.Fprintln(streams.Out, string(data)) | ||
| case "yaml": | ||
| data, err := yaml.Marshal(specs) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal tests to YAML: %w", err) | ||
| } | ||
| fmt.Fprintln(streams.Out, string(data)) | ||
| default: | ||
| return fmt.Errorf("invalid output format: %s", outputFormat) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&suiteName, "suite", "", "Filter tests by the qualifiers of the specified suite") | ||
| cmd.Flags().StringP("output", "o", "", "Output format; available options are 'yaml' and 'json'") | ||
| return cmd | ||
| } | ||
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
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,53 @@ | ||
| package extension | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| o "github.com/onsi/gomega" | ||
|
|
||
| "github.com/openshift/origin/pkg/test/extensions" | ||
| "k8s.io/apimachinery/pkg/util/sets" | ||
| ) | ||
|
|
||
| // knownInfoFailures lists extension binaries that are known to fail the | ||
| // "info" command without cluster access. Each entry should have a tracking | ||
| // issue for fixing the upstream binary. Remove entries as fixes land. | ||
| var knownInfoFailures = sets.New[string]( | ||
| "ovn-kubernetes-tests-ext", // https://github.com/openshift/ovn-kubernetes/pull/3170 | ||
| "cloud-controller-manager-aws-tests-ext", // https://github.com/openshift/cluster-cloud-controller-manager-operator/pull/458 | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| var _ = g.Describe("[sig-ci] [OTE] Payload extension binaries [Suite:openshift/conformance/parallel]", func() { | ||
| defer g.GinkgoRecover() | ||
|
|
||
| g.It("should all respond to the info command", func(ctx context.Context) { | ||
| extractCtx, extractCancel := context.WithTimeout(ctx, 30*time.Minute) | ||
| defer extractCancel() | ||
|
|
||
| cleanUpFn, allBinaries, _, err := extensions.ExtractAllTestBinaries(extractCtx, 10, extensions.WithPayloadOnly()) | ||
| o.Expect(err).NotTo(o.HaveOccurred(), "failed to extract test binaries from payload") | ||
| defer cleanUpFn() | ||
|
|
||
| var failures []string | ||
| for _, binary := range allBinaries { | ||
| binName := binary.Name() | ||
| infoCtx, infoCancel := context.WithTimeout(ctx, 10*time.Minute) | ||
| _, err := binary.Info(infoCtx) | ||
| infoCancel() | ||
|
|
||
| if err != nil { | ||
| if knownInfoFailures.Has(binName) { | ||
| g.GinkgoLogr.Info("Skipping known info failure", "binary", binName, "error", err) | ||
| continue | ||
| } | ||
| failures = append(failures, binName+": "+err.Error()) | ||
| } else if knownInfoFailures.Has(binName) { | ||
| failures = append(failures, binName+": listed in knownInfoFailures but info succeeded — remove from exemption list") | ||
| } | ||
| } | ||
|
|
||
| o.Expect(failures).To(o.BeEmpty(), "extension binaries failed the OTE info contract") | ||
| }) | ||
| }) | ||
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
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.