Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[oadp-1.4] OADP-4213: Backport VM E2E tests to OADP-1.4. #1408

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ VELERO_INSTANCE_NAME ?= velero-test
E2E_TIMEOUT_MULTIPLIER ?= 1
ARTIFACT_DIR ?= /tmp
OC_CLI = $(shell which oc)
TEST_VIRT ?= false

ifdef CLI_DIR
OC_CLI = ${CLI_DIR}/oc
Expand Down Expand Up @@ -485,9 +486,14 @@ install-ginkgo: # Make sure ginkgo is in $GOPATH/bin
go install -v -mod=mod github.com/onsi/ginkgo/v2/ginkgo

OADP_BUCKET ?= $(shell cat $(OADP_BUCKET_FILE))
TEST_FILTER := ($(shell echo '! aws && ! gcp && ! azure && ! ibmcloud' | \
sed -r "s/[&]* [!] $(CLUSTER_TYPE)|[!] $(CLUSTER_TYPE) [&]*//")) || $(CLUSTER_TYPE)
TEST_FILTER = (($(shell echo '! aws && ! gcp && ! azure && ! ibmcloud' | \
sed -r "s/[&]* [!] $(CLUSTER_TYPE)|[!] $(CLUSTER_TYPE) [&]*//")) || $(CLUSTER_TYPE))
#TEST_FILTER := $(shell echo '! aws && ! gcp && ! azure' | sed -r "s/[&]* [!] $(CLUSTER_TYPE)|[!] $(CLUSTER_TYPE) [&]*//")
ifeq ($(TEST_VIRT),true)
TEST_FILTER += && (virt)
else
TEST_FILTER += && (! virt)
endif
SETTINGS_TMP=/tmp/test-settings

.PHONY: test-e2e-setup
Expand Down
1 change: 1 addition & 0 deletions docs/developer/testing/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ To get started, you need to provide the following **required** environment varia
| `BSL_REGION` | The region of backupLocations | `us-east-1` | false |
| `OADP_TEST_NAMESPACE` | The namespace where OADP operator is installed | `openshift-adp` | false |
| `OPENSHIFT_CI` | Disable colored output from tests suite run | `true` | false |
| `TEST_VIRT` | Exclusively run Virtual Machine backup/restore testing | `false` | false |

The expected format for `OADP_CRED_FILE` and `CI_CRED_FILE` files is:
```
Expand Down
321 changes: 193 additions & 128 deletions tests/e2e/backup_restore_suite_test.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
. "github.com/openshift/oadp-operator/tests/e2e/lib"
"github.com/openshift/oadp-operator/tests/e2e/utils"
veleroClientset "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
Expand Down Expand Up @@ -103,6 +104,7 @@ var kubernetesClientForSuiteRun *kubernetes.Clientset
var runTimeClientForSuiteRun client.Client
var veleroClientForSuiteRun veleroClientset.Interface
var csiClientForSuiteRun *snapshotv1client.Clientset
var dynamicClientForSuiteRun dynamic.Interface
var dpaCR *DpaCustomResource
var knownFlake bool
var accumulatedTestLogs []string
Expand Down Expand Up @@ -132,6 +134,9 @@ var _ = BeforeSuite(func() {
csiClientForSuiteRun, err = snapshotv1client.NewForConfig(kubeConf)
Expect(err).NotTo(HaveOccurred())

dynamicClientForSuiteRun, err = dynamic.NewForConfig(kubeConf)
Expect(err).NotTo(HaveOccurred())

dpaCR = &DpaCustomResource{
Namespace: namespace,
Provider: provider,
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/lib/dpa_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1"
"github.com/openshift/oadp-operator/pkg/common"
utils "github.com/openshift/oadp-operator/tests/e2e/utils"
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
operators "github.com/operator-framework/api/pkg/operators/v1alpha1"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
velero "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
Expand Down Expand Up @@ -272,6 +273,7 @@ func (v *DpaCustomResource) SetClient(client client.Client) error {
volumesnapshotv1.AddToScheme(client.Scheme())
buildv1.AddToScheme(client.Scheme())
operatorsv1alpha1.AddToScheme(client.Scheme())
operatorsv1.AddToScheme(client.Scheme())

v.Client = client
return nil
Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/lib/kube_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ import (
"k8s.io/client-go/kubernetes"
)

func CreateNamespace(clientset *kubernetes.Clientset, namespace string) error {
ns := corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
_, err := clientset.CoreV1().Namespaces().Create(context.Background(), &ns, metav1.CreateOptions{})
if apierrors.IsAlreadyExists(err) {
return nil
}
return err
}

func DeleteNamespace(clientset *kubernetes.Clientset, namespace string) error {
err := clientset.CoreV1().Namespaces().Delete(context.Background(), namespace, metav1.DeleteOptions{})
if apierrors.IsNotFound(err) {
return nil
}
return err
}

func DoesNamespaceExist(clientset *kubernetes.Clientset, namespace string) (bool, error) {
_, err := clientset.CoreV1().Namespaces().Get(context.Background(), namespace, metav1.GetOptions{})
if err != nil {
Expand Down
53 changes: 42 additions & 11 deletions tests/e2e/lib/subscription_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ type Subscription struct {
*operators.Subscription
}

func (d *DpaCustomResource) GetOperatorSubscription(c client.Client, stream string) (*Subscription, error) {
err := d.SetClient(c)
if err != nil {
return nil, err
}
type StreamSource string

const (
UPSTREAM StreamSource = "up"
DOWNSTREAM StreamSource = "down"
)

func getOperatorSubscription(c client.Client, namespace, label string) (*Subscription, error) {
sl := operators.SubscriptionList{}
if stream == "up" {
err = d.Client.List(context.Background(), &sl, client.InNamespace(d.Namespace), client.MatchingLabels(map[string]string{"operators.coreos.com/oadp-operator." + d.Namespace: ""}))
}
if stream == "down" {
err = d.Client.List(context.Background(), &sl, client.InNamespace(d.Namespace), client.MatchingLabels(map[string]string{"operators.coreos.com/redhat-oadp-operator." + d.Namespace: ""}))
}
err := c.List(context.Background(), &sl, client.InNamespace(namespace), client.MatchingLabels(map[string]string{label: ""}))
if err != nil {
return nil, err
}
Expand All @@ -39,6 +37,27 @@ func (d *DpaCustomResource) GetOperatorSubscription(c client.Client, stream stri
return &Subscription{&sl.Items[0]}, nil
}

func (d *DpaCustomResource) GetOperatorSubscription(c client.Client, stream StreamSource) (*Subscription, error) {
err := d.SetClient(c)
if err != nil {
return nil, err
}

label := ""
if stream == UPSTREAM {
label = "operators.coreos.com/oadp-operator." + d.Namespace
}
if stream == DOWNSTREAM {
label = "operators.coreos.com/redhat-oadp-operator." + d.Namespace
}
return getOperatorSubscription(c, d.Namespace, label)
}

func (v *VirtOperator) getOperatorSubscription() (*Subscription, error) {
label := "operators.coreos.com/kubevirt-hyperconverged.openshift-cnv"
return getOperatorSubscription(v.Client, v.Namespace, label)
}

func (s *Subscription) Refresh(c client.Client) error {
return c.Get(context.Background(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, s.Subscription)
}
Expand Down Expand Up @@ -97,3 +116,15 @@ func (s *Subscription) CreateOrUpdate(c client.Client) error {
}
return c.Update(context.Background(), s.Subscription)
}

func (s *Subscription) Delete(c client.Client) error {
var currentSubscription operators.Subscription
err := c.Get(context.Background(), types.NamespacedName{Namespace: s.Namespace, Name: s.Name}, &currentSubscription)
if apierrors.IsNotFound(err) {
return nil
}
if err != nil {
return err
}
return c.Delete(context.Background(), s.Subscription)
}
Loading