From b09a40c78ad5363d5ec009748dab06d9a08b0538 Mon Sep 17 00:00:00 2001 From: David Elie-Dit-Cosaque Date: Fri, 1 Dec 2023 10:17:19 -0600 Subject: [PATCH] Propagates error from preflight in the claim file even if preflight fails to run due to connectivity issues, missing docker config, etc... --- .../lifecycle/podrecreation/podrecreation.go | 4 ++-- cnf-certification-test/preflight/suite.go | 6 ++++-- pkg/provider/containers.go | 13 +++++++++++-- pkg/provider/operators.go | 12 ++++++++++-- pkg/provider/provider.go | 1 + 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cnf-certification-test/lifecycle/podrecreation/podrecreation.go b/cnf-certification-test/lifecycle/podrecreation/podrecreation.go index 8dd2f319b3..3ecc042e50 100644 --- a/cnf-certification-test/lifecycle/podrecreation/podrecreation.go +++ b/cnf-certification-test/lifecycle/podrecreation/podrecreation.go @@ -19,10 +19,10 @@ package podrecreation import ( "context" "fmt" + "os" "sync" "time" - "github.com/onsi/ginkgo/v2" "github.com/sirupsen/logrus" "github.com/test-network-function/cnf-certification-test/internal/clientsholder" "github.com/test-network-function/cnf-certification-test/pkg/provider" @@ -144,7 +144,7 @@ func CordonCleanup(node string) { err := CordonHelper(node, Uncordon) if err != nil { logrus.Errorf("cleanup: error uncordoning the node: %s, err=%s", node, err) - ginkgo.AbortSuite(fmt.Sprintf("cleanup: error uncordoning the node: %s, err=%s", node, err)) + os.Exit(1) } } diff --git a/cnf-certification-test/preflight/suite.go b/cnf-certification-test/preflight/suite.go index 19f33524d2..a6e41c93e4 100644 --- a/cnf-certification-test/preflight/suite.go +++ b/cnf-certification-test/preflight/suite.go @@ -17,6 +17,7 @@ package preflight import ( + "fmt" "strings" plibRuntime "github.com/redhat-openshift-ecosystem/openshift-preflight/certification" @@ -57,6 +58,7 @@ func labelsAllowTestRun(labelFilter string, allowedLabels []string) bool { // time to finish. When they're finished, a checksdb.Check is created for each preflight lib's // check that has run. The CheckFn will simply store the result. func ShouldRun(labelsExpr string) bool { + env = provider.GetTestEnvironment() preflightAllowedLabels := []string{common.PreflightTestKey, identifiers.TagPreflight} if !labelsAllowTestRun(labelsExpr, preflightAllowedLabels) { @@ -67,7 +69,7 @@ func ShouldRun(labelsExpr string) bool { preflightDockerConfigFile := configuration.GetTestParameters().PfltDockerconfig if preflightDockerConfigFile == "" || preflightDockerConfigFile == "NA" { logrus.Warn("Skipping the preflight suite because the Docker Config file is not provided.") - return false + env.SkipPreflight = true } return true @@ -169,7 +171,7 @@ func generatePreflightContainerGinkgoTest(checksGroup *checksdb.ChecksGroup, tes } for _, r := range cut.PreflightResults.Errors { if r.Name() == testName { - nonCompliantObjects = append(nonCompliantObjects, testhelper.NewContainerReportObject(cut.Namespace, cut.Podname, cut.Name, "Container has errored preflight test "+testName, false)) + nonCompliantObjects = append(nonCompliantObjects, testhelper.NewContainerReportObject(cut.Namespace, cut.Podname, cut.Name, fmt.Sprintf("Container has errored preflight test %s, err=%v", testName, r.Err), false)) tnf.Logf(logrus.ErrorLevel, "%s has errored preflight test: %s", cut, testName) } } diff --git a/pkg/provider/containers.go b/pkg/provider/containers.go index 8b0bb33610..e6bb79b2b4 100644 --- a/pkg/provider/containers.go +++ b/pkg/provider/containers.go @@ -120,11 +120,20 @@ func (c *Container) SetPreflightResults(preflightImageCache map[string]plibRunti ctx = logr.NewContext(ctx, logger) check := plibContainer.NewCheck(c.Image, opts...) + results, runtimeErr := check.Run(ctx) logrus.StandardLogger().Out = os.Stderr if runtimeErr != nil { - logrus.Error(runtimeErr) - return runtimeErr + _, checks, err := check.List(ctx) + if err != nil { + return fmt.Errorf("could not get preflight container test list") + } + + results.TestedImage = c.Image + for _, c := range checks { + results.PassedOverall = false + results.Errors = append(results.Errors, plibRuntime.Result{Check: c, ElapsedTime: 0, Err: runtimeErr}) + } } // Take all of the preflight logs and stick them into logrus. diff --git a/pkg/provider/operators.go b/pkg/provider/operators.go index f58dabcfaa..74059a7bc2 100644 --- a/pkg/provider/operators.go +++ b/pkg/provider/operators.go @@ -99,10 +99,18 @@ func (op *Operator) SetPreflightResults(env *TestEnvironment) error { ctx = logr.NewContext(ctx, logger) check := plibOperator.NewCheck(bundleImage, indexImage, oc.KubeConfig, opts...) + results, runtimeErr := check.Run(ctx) + logrus.StandardLogger().Out = os.Stderr if runtimeErr != nil { - logrus.Error(runtimeErr) - return runtimeErr + _, checks, err := check.List(ctx) + if err != nil { + return fmt.Errorf("could not get preflight container test list") + } + for _, c := range checks { + results.PassedOverall = false + results.Errors = append(results.Errors, plibRuntime.Result{Check: c, ElapsedTime: 0, Err: runtimeErr}) + } } // Take all of the preflight logs and stick them into logrus. diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index fb1a8e492c..71a924eacb 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -121,6 +121,7 @@ type TestEnvironment struct { // rename this with testTarget ExecutedBy string PartnerName string CollectorAppPassword string + SkipPreflight bool } type MachineConfig struct {