Skip to content

Commit 80af1c8

Browse files
committed
scripts: add first e2e test by OTE
This is the first e2e test case which using openshift-tests-extension (OTE) framework, wich OTE framework, DEV and QE can work together. This PR implements a very simple test case which may still need improvements. But with this PR we can evaluate the posibility of moving other tests to OTE. The reference to OTE framework: https://docs.google.com/document/d/1cFZj9QdzW8hbHc3H0Nce-2xrJMtpDJrwAse9H7hLiWk/edit?tab=t.0#heading=h.8cf3f4eii1q8
1 parent 570c642 commit 80af1c8

File tree

4 files changed

+101
-10
lines changed

4 files changed

+101
-10
lines changed
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
[
22
{
3-
"name": "[Jira:Cluster Version Operator] cluster-version-operator-tests should support passing tests",
3+
"name": "[Jira:\"Cluster Version Operator\"] cluster-version-operator-tests should support passing tests the sanity test should pass",
44
"labels": {},
55
"resources": {
66
"isolation": {}
77
},
88
"source": "openshift:payload:cluster-version-operator",
99
"lifecycle": "blocking",
1010
"environmentSelector": {}
11+
},
12+
{
13+
"name": "[Jira:\"Cluster Version Operator\"] The cluster version operator should not install resources annotated with release.openshift.io/delete=true",
14+
"labels": {
15+
"42543": {},
16+
"Conformance": {},
17+
"High": {},
18+
"cvo": {}
19+
},
20+
"resources": {
21+
"isolation": {}
22+
},
23+
"source": "openshift:payload:cluster-version-operator",
24+
"lifecycle": "blocking",
25+
"environmentSelector": {}
1126
}
1227
]

cmd/cluster-version-operator-tests/README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@ It integrates [openshift-tests-extension](https://github.com/openshift-eng/opens
44
cluster-version-operator which allows openshift components to contribute tests to openshift-tests' suites with
55
extension binaries.
66

7+
## Build the executable binary
8+
In root folder, run below command to build executable binary:
9+
```console
10+
$ make build
11+
```
712

813
## Run the tests locally
914

10-
## Using the framework
15+
### Using the binary
16+
- run a test-suite
17+
```console
18+
$ _output/<OS>/<ARCH>/cluster-version-operator-tests run-suite <test suite name>
19+
```
20+
where test suites can be listed by `_output/<OS>/<ARCH>/cluster-version-operator-tests info`.
21+
22+
- run a single test case
1123
```console
12-
$ hack/build-go.sh
13-
$ _output/<OS>/<ARCH>/cluster-version-operator-tests run-suite cluster-version-operator
24+
$ _output/<OS>/<ARCH>/cluster-version-operator-tests run-test <test case name>
1425
```
26+
where test names can be listed by `_output/<OS>/<ARCH>/cluster-version-operator-tests list`.
1527

16-
## Using ginko-cli
28+
### Using ginko-cli
1729

1830
After [installing-ginkgo](https://onsi.github.io/ginkgo/#installing-ginkgo):
1931

test/cvo/cvo.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
package cvo
22

33
import (
4-
. "github.com/onsi/ginkgo/v2"
5-
. "github.com/onsi/gomega"
4+
"context"
5+
6+
g "github.com/onsi/ginkgo/v2"
7+
o "github.com/onsi/gomega"
8+
kerrors "k8s.io/apimachinery/pkg/api/errors"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
"k8s.io/client-go/kubernetes"
11+
12+
"github.com/openshift/cluster-version-operator/test/utilities"
613
)
714

8-
var _ = Describe("[Jira:Cluster Version Operator] cluster-version-operator-tests", func() {
9-
It("should support passing tests", func() {
10-
Expect(true).To(BeTrue())
15+
var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator-tests should support passing tests`, func() {
16+
g.It("the sanity test should pass", func() {
17+
o.Expect(true).To(o.BeTrue())
18+
})
19+
})
20+
21+
var _ = g.Describe(`[Jira:"Cluster Version Operator"] The cluster version operator`, g.Ordered, g.Label("cvo"), func() {
22+
defer g.GinkgoRecover()
23+
var err error
24+
var client *kubernetes.Clientset
25+
26+
g.BeforeAll(func() {
27+
client = utilities.MustGetKubeClient()
28+
})
29+
30+
g.It(`should not install resources annotated with release.openshift.io/delete=true`, g.Label("Conformance", "High", "42543"), func() {
31+
g.By("checking if Service openshift-cloud-credential-operator/controller-manager-service does not exist")
32+
_, err = client.CoreV1().Services("openshift-cloud-credential-operator").Get(context.TODO(), "controller-manager-service", metav1.GetOptions{})
33+
o.Expect(kerrors.IsNotFound(err)).To(o.BeTrue(), "The NotFound error should occur")
34+
35+
g.By("checking if ClusterRoleBindings default-account-openshift-machine-config-operator does not exist")
36+
_, err = client.RbacV1().ClusterRoleBindings().Get(context.TODO(), "default-account-openshift-machine-config-operator", metav1.GetOptions{})
37+
o.Expect(kerrors.IsNotFound(err)).To(o.BeTrue(), "The NotFound error should occur")
1138
})
1239
})

test/utilities/connection.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package utilities
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"os"
7+
8+
"k8s.io/client-go/kubernetes"
9+
"k8s.io/client-go/tools/clientcmd"
10+
)
11+
12+
// getKubeClient creates a Kubernetes clientset.
13+
func getKubeClient() (*kubernetes.Clientset, error) {
14+
configPath, present := os.LookupEnv("KUBECONFIG")
15+
if !present {
16+
return nil, errors.New("the environment variable KUBECONFIG must be set")
17+
}
18+
config, err := clientcmd.BuildConfigFromFlags("", configPath)
19+
if err != nil {
20+
return nil, fmt.Errorf("unable to load build config: %w", err)
21+
}
22+
// Create the Clientset
23+
clientset, err := kubernetes.NewForConfig(config)
24+
if err != nil {
25+
return nil, fmt.Errorf("unable to create a Kubernetes clientset: %w", err)
26+
}
27+
return clientset, nil
28+
}
29+
30+
// MustGetKubeClient creates a Kubernetes clientset, or panics on failures.
31+
func MustGetKubeClient() *kubernetes.Clientset {
32+
clientset, err := getKubeClient()
33+
if err != nil {
34+
panic("unable to create a Kubernetes clientset: " + err.Error())
35+
}
36+
return clientset
37+
}

0 commit comments

Comments
 (0)