Skip to content

Commit

Permalink
Propagates error from preflight in the claim file even if preflight f…
Browse files Browse the repository at this point in the history
…ails to run due to connectivity issues, missing docker config, etc...
  • Loading branch information
edcdavid committed Dec 4, 2023
1 parent 22fd23a commit b09a40c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}

Expand Down
6 changes: 4 additions & 2 deletions cnf-certification-test/preflight/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package preflight

import (
"fmt"
"strings"

plibRuntime "github.com/redhat-openshift-ecosystem/openshift-preflight/certification"
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/provider/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 10 additions & 2 deletions pkg/provider/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ type TestEnvironment struct { // rename this with testTarget
ExecutedBy string
PartnerName string
CollectorAppPassword string
SkipPreflight bool
}

type MachineConfig struct {
Expand Down

0 comments on commit b09a40c

Please sign in to comment.