Skip to content

Commit

Permalink
fixup! fix: Refactor E2E tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <msouzaol@redhat.com>
  • Loading branch information
mateusoliveira43 committed Jul 24, 2024
1 parent 8612565 commit c9db884
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 71 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ require (
github.com/vmware-tanzu/velero v1.14.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
k8s.io/klog/v2 v2.110.1
sigs.k8s.io/yaml v1.4.0
)

require (
Expand Down Expand Up @@ -175,6 +174,7 @@ require (
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/vmware-tanzu/velero => github.com/openshift/velero v0.10.2-0.20240523154040-23f5b576327e
Expand Down
8 changes: 0 additions & 8 deletions tests/e2e/backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func todoListReady(preBackupState bool, twoVol bool, database string) Verificati
log.Printf("checking for the NAMESPACE: %s", namespace)
gomega.Eventually(lib.IsDeploymentReady(ocClient, namespace, database), time.Minute*10, time.Second*10).Should(gomega.BeTrue())
gomega.Eventually(lib.IsDCReady(ocClient, namespace, "todolist"), time.Minute*10, time.Second*10).Should(gomega.BeTrue())
// TODO remove or change line?
// gomega.Eventually(lib.AreAppBuildsReady(dpaCR.Client, namespace), time.Minute*3, time.Second*5).Should(gomega.BeTrue())
gomega.Eventually(lib.AreApplicationPodsRunning(kubernetesClientForSuiteRun, namespace), time.Minute*9, time.Second*5).Should(gomega.BeTrue())
// This test confirms that SCC restore logic in our plugin is working
err := lib.DoesSCCExist(ocClient, database+"-persistent-scc")
Expand Down Expand Up @@ -130,9 +128,6 @@ func runApplicationBackupAndRestore(brCase ApplicationBackupRestoreCase, expecte
log.Printf("Running pre-backup custom function for case %s", brCase.Name)
err := brCase.PreBackupVerify(dpaCR.Client, brCase.Namespace)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
} else {
log.Printf("Running pre-backup check for case %s", brCase.Name)
gomega.Eventually(lib.AreApplicationPodsRunning(kubernetesClientForSuiteRun, brCase.Namespace), time.Minute*9, time.Second*5).Should(gomega.BeTrue())
}

// do the backup for real
Expand All @@ -156,9 +151,6 @@ func runApplicationBackupAndRestore(brCase ApplicationBackupRestoreCase, expecte
log.Printf("Running post-restore custom function for case %s", brCase.Name)
err = brCase.PostRestoreVerify(dpaCR.Client, brCase.Namespace)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
} else {
log.Printf("Running post-restore check for case %s", brCase.Name)
gomega.Eventually(lib.AreApplicationPodsRunning(kubernetesClientForSuiteRun, brCase.Namespace), time.Minute*9, time.Second*5).Should(gomega.BeTrue())
}
}

Expand Down
56 changes: 1 addition & 55 deletions tests/e2e/lib/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
ocpappsv1 "github.com/openshift/api/apps/v1"
buildv1 "github.com/openshift/api/build/v1"
security "github.com/openshift/api/security/v1"
templatev1 "github.com/openshift/api/template/v1"
"github.com/vmware-tanzu/velero/pkg/label"
Expand All @@ -26,7 +25,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -273,13 +271,6 @@ func IsDCReady(ocClient client.Client, namespace, dcName string) wait.ConditionF
}
return false, errors.New("DC is not in a ready state")
}
for _, trigger := range dc.Spec.Triggers {
if trigger.Type == ocpappsv1.DeploymentTriggerOnImageChange {
if trigger.ImageChangeParams.Automatic {
return areAppBuildsReady(ocClient, namespace)
}
}
}
return true, nil
}
}
Expand All @@ -306,52 +297,6 @@ func IsDeploymentReady(ocClient client.Client, namespace, dName string) wait.Con
}
}

func areAppBuildsReady(ocClient client.Client, namespace string) (bool, error) {
buildList := &buildv1.BuildList{}
parsedLabel, err := labels.Parse(e2eAppLabel)
if err != nil {
return false, err
}
err = ocClient.List(context.Background(), buildList, &client.ListOptions{Namespace: namespace, LabelSelector: parsedLabel})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
if buildList.Items != nil {
for _, build := range buildList.Items {
if build.Status.Phase == buildv1.BuildPhaseNew ||
build.Status.Phase == buildv1.BuildPhasePending ||
build.Status.Phase == buildv1.BuildPhaseRunning {
log.Println("Build is not ready: " + build.Name)
return false, nil
}
if build.Status.Phase == buildv1.BuildPhaseFailed || build.Status.Phase == buildv1.BuildPhaseError {
ginkgo.GinkgoWriter.Println("Build failed/error: " + build.Name)
ginkgo.GinkgoWriter.Println(fmt.Sprintf("status: %v", build.Status))
return false, errors.New("found build failed or error")
}
if build.Status.Phase == buildv1.BuildPhaseComplete {
log.Println("Build is complete: " + build.Name + " patching build pod label to exclude from backup")
podName := build.GetAnnotations()["openshift.io/build.pod-name"]
pod := corev1.Pod{}
err := ocClient.Get(context.Background(), client.ObjectKey{
Namespace: namespace,
Name: podName,
}, &pod)
if err != nil {
return false, err
}
pod.Labels["velero.io/exclude-from-backup"] = "true"
err = ocClient.Update(context.Background(), &pod)
if err != nil {
log.Println("Error patching build pod label to exclude from backup: " + err.Error())
return false, err
}
}
}
}
return true, nil
}

func AreApplicationPodsRunning(c *kubernetes.Clientset, namespace string) wait.ConditionFunc {
return func() (bool, error) {
podList, err := GetAllPodsWithLabel(c, namespace, e2eAppLabel)
Expand All @@ -372,6 +317,7 @@ func AreApplicationPodsRunning(c *kubernetes.Clientset, namespace string) wait.C
}

for _, condition := range pod.Status.Conditions {
log.Printf("Pod %v condition:\n%#v", pod.Name, condition)
if condition.Type == corev1.ContainersReady && condition.Status != corev1.ConditionTrue {
log.Printf("Pod %v not yet succeeded: condition is: %v", pod.Name, condition.Status)
return false, fmt.Errorf("Pod not yet succeeded")
Expand Down
7 changes: 0 additions & 7 deletions tests/e2e/virt_backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func getLatestCirrosImageURL() (string, error) {

func vmPoweredOff(vmnamespace, vmname string) VerificationFunction {
return VerificationFunction(func(ocClient client.Client, namespace string) error {
gomega.Eventually(lib.AreApplicationPodsRunning(kubernetesClientForSuiteRun, namespace), time.Minute*9, time.Second*5).Should(gomega.BeTrue())
isOff := func() bool {
status, err := lib.GetVmStatus(dynamicClientForSuiteRun, vmnamespace, vmname)
if err != nil {
Expand Down Expand Up @@ -125,9 +124,6 @@ func runVmBackupAndRestore(brCase VmBackupRestoreCase, expectedErr error, update
log.Printf("Running pre-backup custom function for case %s", brCase.Name)
err := brCase.PreBackupVerify(dpaCR.Client, brCase.Namespace)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
} else {
log.Printf("Running pre-backup check for case %s", brCase.Name)
gomega.Eventually(lib.AreApplicationPodsRunning(kubernetesClientForSuiteRun, brCase.Namespace), time.Minute*9, time.Second*5).Should(gomega.BeTrue())
}

// Back up VM
Expand All @@ -148,9 +144,6 @@ func runVmBackupAndRestore(brCase VmBackupRestoreCase, expectedErr error, update
log.Printf("Running post-restore custom function for VM case %s", brCase.Name)
err = brCase.PostRestoreVerify(dpaCR.Client, brCase.Namespace)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
} else {
log.Printf("Running post-restore check for case %s", brCase.Name)
gomega.Eventually(lib.AreApplicationPodsRunning(kubernetesClientForSuiteRun, brCase.Namespace), time.Minute*9, time.Second*5).Should(gomega.BeTrue())
}
}

Expand Down

0 comments on commit c9db884

Please sign in to comment.