Skip to content

Commit

Permalink
Add operator support
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Oct 18, 2022
1 parent cd9ad6a commit a3e727f
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 121 deletions.
90 changes: 81 additions & 9 deletions cnf-certification-test/preflight/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,33 @@ var _ = ginkgo.Describe(common.PreflightTestKey, func() {
})
ginkgo.ReportAfterEach(results.RecordResult)

// Handle Container-based preflight tests
containerTestEntries := gatherTestNamesFromResults(env.Containers)
logrus.Infof("Number of containers to gather results from1: %d", len(env.Containers))

// logrus.Infof("test names: %v", containerTestEntries)
// Handle Container-based preflight tests
containerTestEntries := gatherTestNamesFromContainerResults(env.Containers)
for testName, testEntry := range containerTestEntries {
// Store the test names into the Catalog map for results to be dynamically printed
aID := identifiers.AddCatalogEntry(testName, common.PreflightTestKey, testEntry.description, testEntry.suggestion, "", "", "", "", "common")
testID, tags := identifiers.GetGinkgoTestIDAndLabels(aID)

logrus.Infof("Testing ginkgo test: %s ID: %s", testName, testID)
GeneratePreflightGinkgoTest(testName, testID, tags, env.Containers)
GeneratePreflightContainerGinkgoTest(testName, testID, tags, env.Containers)
}

// Handle Operator-based preflight tests
logrus.Infof("Number of operators to gather results from: %d", len(env.Operators))
operatorTestEntries := gatherTestNamesFromOperatorResults(env.Operators)
for testName, testEntry := range operatorTestEntries {
// Store the test names into the Catalog map for results to be dynamically printed
aID := identifiers.AddCatalogEntry(testName, common.PreflightTestKey, testEntry.description, testEntry.suggestion, "", "", "", "", "common")
testID, tags := identifiers.GetGinkgoTestIDAndLabels(aID)

logrus.Infof("Testing ginkgo test: %s ID: %s", testName, testID)
GeneratePreflightOperatorGinkgoTest(testName, testID, tags, env.Operators)
}
})

func GeneratePreflightGinkgoTest(testName, testID string, tags []string, containers []*provider.Container) {
func GeneratePreflightContainerGinkgoTest(testName, testID string, tags []string, containers []*provider.Container) {
// Based on a single test "name", we will be passing/failing in Ginkgo.
// Brute force-ish type of method.
ginkgo.It(testID, ginkgo.Label(tags...), func() {
Expand Down Expand Up @@ -89,18 +101,51 @@ func GeneratePreflightGinkgoTest(testName, testID string, tags []string, contain
})
}

func gatherTestNamesFromResults(containers []*provider.Container) map[string]dynamicTestEntry {
func GeneratePreflightOperatorGinkgoTest(testName, testID string, tags []string, operators []provider.Operator) {
// Based on a single test "name", we will be passing/failing in Ginkgo.
// Brute force-ish type of method.
ginkgo.It(testID, ginkgo.Label(tags...), func() {
// Collect all of the failed and errored containers
var failedContainers []string
var erroredContainers []string
for _, op := range operators {

logrus.Info(op)
for _, i := range op.PreflightResults.Results.Passed {
if i.Name == testName {
logrus.Infof("%s has passed preflight test: %s", op.String(), testName)
}
}
for _, i := range op.PreflightResults.Results.Failed {
if i.Name == testName {
logrus.Infof("%s has failed preflight test: %s", op.String(), testName)
tnf.ClaimFilePrintf("%s has failed preflight test: %s", op.String(), testName)
failedContainers = append(failedContainers, op.String())
}
}
for _, i := range op.PreflightResults.Results.Errors {
if i.Name == testName {
logrus.Infof("%s has errored preflight test: %s", op.String(), testName)
tnf.ClaimFilePrintf("%s has errored preflight test: %s", op.String(), testName)
erroredContainers = append(erroredContainers, op.String())
}
}
}
testhelper.AddTestResultLog("Non-compliant", failedContainers, tnf.ClaimFilePrintf, ginkgo.Fail)
testhelper.AddTestResultLog("Error", erroredContainers, tnf.ClaimFilePrintf, ginkgo.Fail)
})
}

func gatherTestNamesFromContainerResults(containers []*provider.Container) map[string]dynamicTestEntry {
testEntries := make(map[string]dynamicTestEntry)
for _, cut := range containers {
for _, i := range cut.PreflightResults.Results.Passed {
// logrus.Infof("PASSED NAME: %s", i.Name)
testEntries[i.Name] = dynamicTestEntry{
description: i.Description,
}
}
// Failed Results have more information than the rest
for _, i := range cut.PreflightResults.Results.Failed {
// logrus.Infof("FAILED NAME: %s", i.Name)
testEntries[i.Name] = dynamicTestEntry{
description: i.Description,
checkURL: i.CheckURL,
Expand All @@ -109,11 +154,38 @@ func gatherTestNamesFromResults(containers []*provider.Container) map[string]dyn
}
}
for _, i := range cut.PreflightResults.Results.Errors {
// logrus.Infof("ERRORED NAME: %s", i.Name)
testEntries[i.Name] = dynamicTestEntry{
description: i.Description,
}
}
}
return testEntries
}

func gatherTestNamesFromOperatorResults(operators []provider.Operator) map[string]dynamicTestEntry {
testEntries := make(map[string]dynamicTestEntry)
logrus.Debugf("OPERATORS: %v", operators)
for _, op := range operators {
for _, i := range op.PreflightResults.Results.Passed {
testEntries[i.Name] = dynamicTestEntry{
description: i.Description,
}
}
// Failed Results have more information than the rest
for _, i := range op.PreflightResults.Results.Failed {
testEntries[i.Name] = dynamicTestEntry{
description: i.Description,
checkURL: i.CheckURL,
kbURL: i.KnowledgebaseURL,
suggestion: i.Suggestion,
}
}
for _, i := range op.PreflightResults.Results.Errors {
testEntries[i.Name] = dynamicTestEntry{
description: i.Description,
}
}
}
logrus.Debugf("TEST ENTRIES: %v", testEntries)
return testEntries
}
38 changes: 19 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/basgys/goxml2json v1.1.0
github.com/sebrandon1/openshift-preflight v0.0.18
github.com/sebrandon1/openshift-preflight v0.0.21
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.0
github.com/stretchr/testify v1.8.0
Expand Down Expand Up @@ -48,12 +48,12 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/containerd/containerd v1.6.6 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.12.0 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.12.1 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v20.10.18+incompatible // indirect
github.com/docker/cli v20.10.19+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.18+incompatible // indirect
github.com/docker/docker v20.10.19+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
Expand All @@ -64,7 +64,7 @@ require (
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-gorp/gorp/v3 v3.0.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
Expand All @@ -87,7 +87,7 @@ require (
github.com/gorilla/mux v1.8.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.13 // indirect
Expand Down Expand Up @@ -162,19 +162,19 @@ require (
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20221012135044-0b7e1fb9d458 // indirect
golang.org/x/oauth2 v0.0.0-20221006150949-b44042a4b9c1 // indirect
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0 // indirect
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect
golang.org/x/text v0.3.8 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/net v0.0.0-20221017152216-f25eb7ecb193 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.0.0-20221017184919-83659145692c // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.1.12 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221010155953-15ba04fc1c0e // indirect
google.golang.org/grpc v1.50.0 // indirect
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand All @@ -186,11 +186,11 @@ require (
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.12 // indirect
modernc.org/libc v1.20.3 // indirect
modernc.org/libc v1.20.4 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.19.1 // indirect
modernc.org/sqlite v1.19.2 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
oras.land/oras-go v1.2.0 // indirect
Expand All @@ -205,7 +205,7 @@ require (

require (
github.com/hashicorp/go-version v1.6.0
k8s.io/apiextensions-apiserver v0.25.2
k8s.io/apiextensions-apiserver v0.25.3
)

require (
Expand All @@ -219,7 +219,7 @@ require (

replace github.com/openshift/machine-config-operator => github.com/openshift/machine-config-operator v0.0.1-0.20200913004441-7eba765c69c9

replace github.com/redhat-openshift-ecosystem/openshift-preflight => github.com/sebrandon1/openshift-preflight v0.0.18
replace github.com/redhat-openshift-ecosystem/openshift-preflight => github.com/sebrandon1/openshift-preflight v0.0.21

replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.26.0-alpha.1

Expand Down
Loading

0 comments on commit a3e727f

Please sign in to comment.