Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit e6d20f7

Browse files
aabughoshedcdavid
andauthored
cnfcert-203: check csi certified (#570)
* cnfcert-203: check csi certified * cnfcert-203: check csi certified * cnfcert-203: check csi certified init test * cnfcert-203: fix the linter * cnfcert-203: command updates * cnfcert-203: remove the sh file * cnfcert-203: fux linter * cnfcert-203: update the command timeout * cnfcert-203: updates for javeir comments * cnfcert-203: updates for jUN comments * cnfcert-203: updates for jUN comments * cnfcert-203: updates the function verrables * adding cert-check tool * unmarshaling embeeded file to match csi driver * renamed csi-mapping.json file * Improving operator check to include ocp version * linter * update the oc version * update the os line for the linter * update the split * update the split * remove the html file * remove the not needed comments * check all the operators on the cluster * check all the operator that have certified-operators in org * remove not relevant files * remove not relevant calls of csi * remove not relevant calls of csi * fix the conflict * fix the linet * fix the unit test * fix the unit test * fix the unit test * fix the unit test * few updates * few updates * few updates * few updates * few updates * few updates * few updates * updating with jun PR Co-authored-by: David Elie-Dit-Cosaque <[email protected]> Co-authored-by: edcdavid <[email protected]>
1 parent d6710c3 commit e6d20f7

File tree

10 files changed

+507
-42
lines changed

10 files changed

+507
-42
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,9 @@ For example:
543543
```shell script
544544
TNF_DEFAULT_BUFFER_SIZE=32768 ./run-cnf-suites.sh -f diagnostic
545545
```
546+
547+
# Testing certified operator
548+
to test if operator certified need to label it with this command
549+
```shell script
550+
oc label csv <name> -n <namespace> "test-network-function.com/operator=target"
551+
```

internal/api/api.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ func CreateContainerCatalogQueryURL(id configsections.ContainerImageIdentifier)
195195

196196
// IsOperatorCertified get operator bundle by package name and check if package details is present
197197
// If present then returns `true` as certified operators.
198-
func (api CertAPIClient) IsOperatorCertified(org, packageName string) (bool, error) {
199-
imageID, err := api.GetOperatorBundleIDByPackageName(org, packageName)
198+
func (api CertAPIClient) IsOperatorCertified(org, packageName, version string) (bool, error) {
199+
imageID, err := api.GetOperatorBundleIDByPackageName(org, packageName, version)
200200
if err == nil {
201201
if imageID == "" {
202202
return false, nil
@@ -219,9 +219,14 @@ func (api CertAPIClient) GetImageByID(id string) (string, error) {
219219

220220
// GetOperatorBundleIDByPackageName get published operator bundle Id by organization and package name.
221221
// Returns (ImageID, error).
222-
func (api CertAPIClient) GetOperatorBundleIDByPackageName(org, name string) (string, error) {
222+
func (api CertAPIClient) GetOperatorBundleIDByPackageName(org, name, vsersion string) (string, error) {
223223
var imageID string
224-
url := fmt.Sprintf("%s/bundles?page_size=1&organization=%s&package=%s", apiOperatorCatalogExternalBaseEndPoint, org, name)
224+
url := ""
225+
if vsersion != "" {
226+
url = fmt.Sprintf("%s/bundles?page_size=1&filter=organization==%s;csv_name==%s;ocp_version==%s", apiOperatorCatalogExternalBaseEndPoint, org, name, vsersion)
227+
} else {
228+
url = fmt.Sprintf("%s/bundles?page_size=1&filter=organization==%s;csv_name==%s", apiOperatorCatalogExternalBaseEndPoint, org, name)
229+
}
225230
responseData, err := api.getRequest(url)
226231
if err == nil {
227232
imageID, err = api.getIDFromResponse(responseData)

internal/api/api_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
unKnownRepository = "wrong_repo"
2323
unKnownImageName = "wrong_id"
2424
unknownPackageName = "unknownPackage"
25+
version = "4.8"
2526
jsonResponseFound = `{
2627
"data": [
2728
{
@@ -502,11 +503,12 @@ var (
502503
expectedResult bool
503504
responseData string
504505
responseStatus int
506+
version string
505507
}{
506508
{packageName: packageName, org: redHatOrg, expectedError: nil, id: "", expectedResult: true,
507-
responseData: jsonResponseFound, responseStatus: http.StatusAccepted},
509+
responseData: jsonResponseFound, responseStatus: http.StatusAccepted, version: version},
508510
{packageName: unknownPackageName, org: marketPlaceOrg, expectedError: nil, id: "", expectedResult: false,
509-
responseData: jsonResponseNotFound, responseStatus: http.StatusNotFound},
511+
responseData: jsonResponseNotFound, responseStatus: http.StatusNotFound, version: version},
510512
}
511513

512514
containerQueryURLTestCases = []struct {
@@ -552,7 +554,7 @@ func TestApiClient_GetContainerCatalogEntry(t *testing.T) {
552554
func TestApiClient_IsOperatorCertified(t *testing.T) {
553555
for _, c := range operatorTestCases {
554556
GetDoFunc = getDoFunc(c.responseData, c.responseStatus) //nolint:bodyclose
555-
result, err := client.IsOperatorCertified(c.org, c.packageName)
557+
result, err := client.IsOperatorCertified(c.org, c.packageName, c.version)
556558
assert.Equal(t, c.expectedResult, result)
557559
assert.Equal(t, c.expectedError, err)
558560
}

pkg/config/autodiscover/autodiscover.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const (
3737
anyLabelValue = ""
3838
ocCommand = "oc get %s -n %s -o json -l %s"
3939
ocAllCommand = "oc get %s -A -o json -l %s"
40-
ocCommandTimeOut = time.Second * 10
40+
ocCommandTimeOut = time.Second * 15
4141
)
4242

4343
var (

pkg/config/autodiscover/autodiscover_targets.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func FindTestTarget(labels []configsections.Label, target *configsections.TestTa
8383
for _, csv := range csvs.Items {
8484
if ns[csv.Metadata.Namespace] {
8585
csv := csv
86-
target.Operators = append(target.Operators, buildOperatorFromCSVResource(&csv))
86+
target.Operators = append(target.Operators, buildOperatorFromCSVResource(&csv, false))
8787
}
8888
}
8989
dps := FindTestPodSetsByLabel(labels, string(configsections.Deployment))
@@ -216,7 +216,7 @@ func buildPodUnderTest(pr *PodResource) (podUnderTest *configsections.Pod) {
216216
}
217217

218218
// buildOperatorFromCSVResource builds a single `configsections.Operator` from a CSVResource
219-
func buildOperatorFromCSVResource(csv *CSVResource) (op configsections.Operator) {
219+
func buildOperatorFromCSVResource(csv *CSVResource, istest bool) (op configsections.Operator) {
220220
var err error
221221
op.Name = csv.Metadata.Name
222222
op.Namespace = csv.Metadata.Namespace
@@ -237,6 +237,10 @@ func buildOperatorFromCSVResource(csv *CSVResource) (op configsections.Operator)
237237
} else {
238238
op.SubscriptionName = subscriptionName[0]
239239
}
240+
if !istest {
241+
op.Packag, op.Org, op.Version = csv.PackOrgVersion(op.Name)
242+
}
243+
240244
return op
241245
}
242246

pkg/config/autodiscover/csv_info.go

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package autodiscover
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
log "github.com/sirupsen/logrus"
2324

@@ -61,6 +62,17 @@ func (csv *CSVResource) GetAnnotationValue(annotationKey string, v interface{})
6162
}
6263
return err
6364
}
65+
func (csv *CSVResource) PackOrgVersion(subscription string) (org, packag, version string) {
66+
ocCmd := fmt.Sprintf("oc get subscriptions.operators.coreos.com -A -o go-template='{{range .items}}{{if eq .status.installedCSV %q}}{{.spec.source}} {{.status.currentCSV}}{{end}}{{end}}'", subscription)
67+
out := execCommandOutput(ocCmd)
68+
orgNameVer := strings.Split(out, " ")
69+
org = orgNameVer[0]
70+
nameVersion := strings.SplitN(orgNameVer[1], ".", 2) //nolint:gomnd // ok
71+
packag = orgNameVer[1]
72+
version = nameVersion[1]
73+
74+
return packag, org, version
75+
}
6476

6577
func (csv *CSVResource) annotationUnmarshalError(annotationKey string, err error) error {
6678
return fmt.Errorf("error (%s) attempting to unmarshal value of annotation '%s' on CSV '%s/%s'",

pkg/config/autodiscover/operator_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
func TestBuildOperatorFromCSVResource(t *testing.T) {
2626
csvResource := loadCSVResource(csvFilePath)
27-
operator := buildOperatorFromCSVResource(&csvResource)
27+
operator := buildOperatorFromCSVResource(&csvResource, true)
2828

2929
assert.Equal(t, "CSVNamespace", operator.Namespace)
3030
assert.Equal(t, "CSVName", operator.Name)

pkg/config/configsections/common.go

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ type Operator struct {
3838

3939
// Subscription name is required field, Name of used subscription.
4040
SubscriptionName string `yaml:"subscriptionName" json:"subscriptionName"`
41+
42+
Packag string `yaml:"packag" json:"packag"`
43+
44+
Org string `yaml:"Org" json:"Org"`
45+
46+
Version string `yaml:"Version" json:"Version"`
4147
}
4248

4349
// Namespace struct defines namespace properties
@@ -91,6 +97,7 @@ type TestTarget struct {
9197
ExcludeContainersFromConnectivityTests []ContainerIdentifier `yaml:"excludeContainersFromConnectivityTests" json:"excludeContainersFromConnectivityTests"`
9298
// Operator is the list of operator objects that needs to be tested.
9399
Operators []Operator `yaml:"operators,omitempty" json:"operators,omitempty"`
100+
//
94101
// Node list
95102
Nodes map[string]Node `yaml:"Nodes" json:"Nodes"`
96103
}

test-network-function/certification/suite.go

+53-31
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package certification
1818

1919
import (
2020
"fmt"
21+
"strings"
2122
"time"
2223

2324
"github.com/onsi/ginkgo/v2"
@@ -26,18 +27,33 @@ import (
2627
configpkg "github.com/test-network-function/test-network-function/pkg/config"
2728
"github.com/test-network-function/test-network-function/pkg/config/configsections"
2829
"github.com/test-network-function/test-network-function/pkg/tnf"
30+
"github.com/test-network-function/test-network-function/pkg/tnf/interactive"
2931
"github.com/test-network-function/test-network-function/pkg/tnf/testcases"
32+
"github.com/test-network-function/test-network-function/pkg/utils"
3033
"github.com/test-network-function/test-network-function/test-network-function/common"
3134
"github.com/test-network-function/test-network-function/test-network-function/identifiers"
3235
"github.com/test-network-function/test-network-function/test-network-function/results"
3336
)
3437

3538
const (
3639
// timeout for eventually call
37-
apiRequestTimeout = 30 * time.Second
40+
apiRequestTimeout = 40 * time.Second
41+
expectersVerboseModeEnabled = false
42+
CertifiedOperator = "certified-operators"
43+
outMinikubeVersion = "null"
3844
)
3945

40-
var certAPIClient api.CertAPIClient
46+
var (
47+
ocpVersionCommand = "oc version -o json | jq '.openshiftVersion'"
48+
49+
execCommandOutput = func(command string) string {
50+
return utils.ExecuteCommandAndValidate(command, apiRequestTimeout, interactive.GetContext(expectersVerboseModeEnabled), func() {
51+
log.Error("can't run command: ", command)
52+
})
53+
}
54+
55+
certAPIClient api.CertAPIClient
56+
)
4157

4258
var _ = ginkgo.Describe(common.AffiliatedCertTestKey, func() {
4359
conf, _ := ginkgo.GinkgoConfiguration()
@@ -51,7 +67,7 @@ var _ = ginkgo.Describe(common.AffiliatedCertTestKey, func() {
5167
ginkgo.AfterEach(env.CloseLocalShellContext)
5268

5369
testContainerCertificationStatus()
54-
testOperatorCertificationStatus()
70+
testAllOperatorCertified(env)
5571
}
5672
})
5773

@@ -63,9 +79,9 @@ func getContainerCertificationRequestFunction(id configsections.ContainerImageId
6379
}
6480

6581
// getOperatorCertificationRequestFunction returns function that will try to get the certification status (OCP) for an operator.
66-
func getOperatorCertificationRequestFunction(organization, operatorName string) func() (interface{}, error) {
82+
func getOperatorCertificationRequestFunction(organization, operatorName, ocpversion string) func() (interface{}, error) {
6783
return func() (interface{}, error) {
68-
return certAPIClient.IsOperatorCertified(organization, operatorName)
84+
return certAPIClient.IsOperatorCertified(organization, operatorName, ocpversion)
6985
}
7086
}
7187

@@ -141,43 +157,49 @@ func testContainerCertificationStatus() {
141157
})
142158
}
143159

144-
func testOperatorCertificationStatus() {
160+
func testAllOperatorCertified(env *configpkg.TestEnvironment) {
145161
testID := identifiers.XformToGinkgoItIdentifier(identifiers.TestOperatorIsCertifiedIdentifier)
146162
ginkgo.It(testID, ginkgo.Label(testID), func() {
147-
operatorsToQuery := configpkg.GetTestEnvironment().Config.CertifiedOperatorInfo
163+
operatorsToQuery := env.OperatorsUnderTest
148164

149165
if len(operatorsToQuery) == 0 {
150-
ginkgo.Skip("No operators to check configured in tnf_config.yml")
166+
ginkgo.Skip("No operators to check configured ")
151167
}
152168

153169
ginkgo.By(fmt.Sprintf("Verify operator as certified. Number of operators to check: %d", len(operatorsToQuery)))
154-
if len(operatorsToQuery) > 0 {
155-
certAPIClient = api.NewHTTPClient()
156-
failedOperators := []configsections.CertifiedOperatorRequestInfo{}
157-
allOperatorsToQueryEmpty := true
158-
for _, operator := range operatorsToQuery {
159-
if operator.Name == "" || operator.Organization == "" {
160-
tnf.ClaimFilePrintf("Operator name = \"%s\" or organization = \"%s\" is missing, skipping this operator to query", operator.Name, operator.Organization)
161-
continue
162-
}
163-
allOperatorsToQueryEmpty = false
164-
ginkgo.By(fmt.Sprintf("Should eventually be verified as certified (operator %s/%s)", operator.Organization, operator.Name))
165-
isCertified := waitForCertificationRequestToSuccess(getOperatorCertificationRequestFunction(operator.Organization, operator.Name), apiRequestTimeout).(bool)
170+
testFailed := false
171+
for _, op := range operatorsToQuery {
172+
ocpversion := GetOcpVersion()
173+
pack := op.Name
174+
org := op.Org
175+
if org == CertifiedOperator {
176+
isCertified := waitForCertificationRequestToSuccess(getOperatorCertificationRequestFunction(org, pack, ocpversion), apiRequestTimeout).(bool)
166177
if !isCertified {
167-
tnf.ClaimFilePrintf("Operator %s (organization %s) failed to be certified.", operator.Name, operator.Organization)
168-
failedOperators = append(failedOperators, operator)
178+
testFailed = true
179+
log.Info(fmt.Sprintf("Operator %s (organization %s) not certified for Openshift %s .", pack, org, ocpversion))
180+
tnf.ClaimFilePrintf("Operator %s (organization %s) failed to be certified for Openshift %s", pack, org, ocpversion)
169181
} else {
170-
log.Info(fmt.Sprintf("Operator %s (organization %s) certified OK.", operator.Name, operator.Organization))
182+
log.Info(fmt.Sprintf("Operator %s (organization %s) certified OK.", pack, org))
171183
}
184+
} else {
185+
testFailed = true
186+
tnf.ClaimFilePrintf("Operator %s is not certified (needs to be part of the operator-certified organization in the catalog)", op.Packag)
172187
}
173-
if allOperatorsToQueryEmpty {
174-
ginkgo.Skip("No operators to check because either operator name or organization is empty for all operators in tnf_config.yml")
175-
}
176-
177-
if n := len(failedOperators); n > 0 {
178-
log.Warnf("Operators that failed to be certified: %+v", failedOperators)
179-
ginkgo.Fail(fmt.Sprintf("%d operators failed to be certified.", n))
180-
}
188+
}
189+
if testFailed {
190+
ginkgo.Skip("At least one operator was not certified to run on this version of openshift. Check Claim.json file for details.")
181191
}
182192
})
183193
}
194+
195+
func GetOcpVersion() string {
196+
ocCmd := ocpVersionCommand
197+
ocVersion := execCommandOutput(ocCmd)
198+
if ocVersion != outMinikubeVersion {
199+
nums := strings.Split(strings.ReplaceAll(ocVersion, "\"", ""), ".")
200+
ocVersion = nums[0] + "." + nums[1]
201+
} else {
202+
ocVersion = ""
203+
}
204+
return ocVersion
205+
}

0 commit comments

Comments
 (0)