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

New structural changes to test repo #531

Merged
merged 7 commits into from
Feb 7, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bin/
tests/e2e/e2e.test
cover.out
.DS_Store
tests/e2e/templates/*.yaml
79 changes: 41 additions & 38 deletions tests/e2e/backup_restore_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package e2e
package e2e_test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: Is the name change intentional or accidental ? The PR description does not mention about e2e_test package #531 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shubham-pampattiwar yes that is intentional change. Just wanted to be more specific here, to reflect that its a test package (taken as reference from Ginkgo docs)


import (
"errors"
Expand All @@ -9,19 +9,22 @@ import (
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/openshift/oadp-operator/tests/e2e/lib"
utils "github.com/openshift/oadp-operator/tests/e2e/utils"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type VerificationFunction func(client.Client, string) error

var _ = Describe("AWS backup restore tests", func() {

var _ = BeforeEach(func() {
testSuiteInstanceName := "ts-" + instanceName
dpaCR.Name = testSuiteInstanceName

credData, err := readFile(cloud)
credData, err := utils.ReadFile(cloud)
Expect(err).NotTo(HaveOccurred())
err = createCredentialsSecret(credData, namespace, getSecretRef(credSecretRef))
err = CreateCredentialsSecret(credData, namespace, GetSecretRef(credSecretRef))
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -38,19 +41,19 @@ var _ = Describe("AWS backup restore tests", func() {
BackupRestoreType BackupRestoreType
PreBackupVerify VerificationFunction
PostRestoreVerify VerificationFunction
MaxK8SVersion *k8sVersion
MinK8SVersion *k8sVersion
MaxK8SVersion *K8sVersion
MinK8SVersion *K8sVersion
}

parksAppReady := VerificationFunction(func(ocClient client.Client, namespace string) error {
Eventually(isDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
Eventually(IsDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
return nil
})
mssqlReady := VerificationFunction(func(ocClient client.Client, namespace string) error {
// This test confirms that SCC restore logic in our plugin is working
Eventually(isDCReady(ocClient, "mssql-persistent", "mssql-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
Eventually(isDeploymentReady(ocClient, "mssql-persistent", "mssql-app-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
exists, err := doesSCCExist(ocClient, "mssql-persistent-scc")
Eventually(IsDCReady(ocClient, "mssql-persistent", "mssql-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
Eventually(IsDeploymentReady(ocClient, "mssql-persistent", "mssql-app-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
exists, err := DoesSCCExist(ocClient, "mssql-persistent-scc")
if err != nil {
return err
}
Expand All @@ -70,22 +73,22 @@ var _ = Describe("AWS backup restore tests", func() {
Expect(err).NotTo(HaveOccurred())

log.Printf("Waiting for velero pod to be running")
Eventually(areVeleroPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
Eventually(AreVeleroPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())

if brCase.BackupRestoreType == restic {
if brCase.BackupRestoreType == RESTIC {
log.Printf("Waiting for restic pods to be running")
Eventually(areResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
Eventually(AreResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
}

if brCase.BackupRestoreType == csi {
if brCase.BackupRestoreType == CSI {
log.Printf("Creating VolumeSnapshot for CSI backuprestore of %s", brCase.Name)
err = installApplication(dpaCR.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml")
err = InstallApplication(dpaCR.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml")
Expect(err).ToNot(HaveOccurred())
}

if dpaCR.CustomResource.Spec.BackupImages == nil || *dpaCR.CustomResource.Spec.BackupImages {
log.Printf("Waiting for registry pods to be running")
Eventually(areRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
}
if notVersionTarget, reason := NotServerVersionTarget(brCase.MinK8SVersion, brCase.MaxK8SVersion); notVersionTarget {
Skip(reason)
Expand All @@ -97,10 +100,10 @@ var _ = Describe("AWS backup restore tests", func() {

// install app
log.Printf("Installing application for case %s", brCase.Name)
err = installApplication(dpaCR.Client, brCase.ApplicationTemplate)
err = InstallApplication(dpaCR.Client, brCase.ApplicationTemplate)
Expect(err).ToNot(HaveOccurred())
// wait for pods to be running
Eventually(areApplicationPodsRunning(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*9, time.Second*5).Should(BeTrue())
Eventually(AreApplicationPodsRunning(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*9, time.Second*5).Should(BeTrue())

// Run optional custom verification
log.Printf("Running pre-backup function for case %s", brCase.Name)
Expand All @@ -109,41 +112,41 @@ var _ = Describe("AWS backup restore tests", func() {

// create backup
log.Printf("Creating backup %s for case %s", backupName, brCase.Name)
err = createBackupForNamespaces(dpaCR.Client, namespace, backupName, []string{brCase.ApplicationNamespace})
err = CreateBackupForNamespaces(dpaCR.Client, namespace, backupName, []string{brCase.ApplicationNamespace})
Expect(err).ToNot(HaveOccurred())

// wait for backup to not be running
Eventually(isBackupDone(dpaCR.Client, namespace, backupName), timeoutMultiplier*time.Minute*4, time.Second*10).Should(BeTrue())
Expect(getVeleroContainerFailureLogs(dpaCR.Namespace)).To(Equal([]string{}))
Eventually(IsBackupDone(dpaCR.Client, namespace, backupName), timeoutMultiplier*time.Minute*4, time.Second*10).Should(BeTrue())
Expect(GetVeleroContainerFailureLogs(dpaCR.Namespace)).To(Equal([]string{}))

// check if backup succeeded
succeeded, err := isBackupCompletedSuccessfully(dpaCR.Client, namespace, backupName)
succeeded, err := IsBackupCompletedSuccessfully(dpaCR.Client, namespace, backupName)
Expect(err).ToNot(HaveOccurred())
Expect(succeeded).To(Equal(true))
log.Printf("Backup for case %s succeeded", brCase.Name)

// uninstall app
log.Printf("Uninstalling app for case %s", brCase.Name)
err = uninstallApplication(dpaCR.Client, brCase.ApplicationTemplate)
err = UninstallApplication(dpaCR.Client, brCase.ApplicationTemplate)
Expect(err).ToNot(HaveOccurred())

// Wait for namespace to be deleted
Eventually(isNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue())
Eventually(IsNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue())

// run restore
log.Printf("Creating restore %s for case %s", restoreName, brCase.Name)
err = createRestoreFromBackup(dpaCR.Client, namespace, backupName, restoreName)
err = CreateRestoreFromBackup(dpaCR.Client, namespace, backupName, restoreName)
Expect(err).ToNot(HaveOccurred())
Eventually(isRestoreDone(dpaCR.Client, namespace, restoreName), timeoutMultiplier*time.Minute*4, time.Second*10).Should(BeTrue())
Expect(getVeleroContainerFailureLogs(dpaCR.Namespace)).To(Equal([]string{}))
Eventually(IsRestoreDone(dpaCR.Client, namespace, restoreName), timeoutMultiplier*time.Minute*4, time.Second*10).Should(BeTrue())
Expect(GetVeleroContainerFailureLogs(dpaCR.Namespace)).To(Equal([]string{}))

// Check if restore succeeded
succeeded, err = isRestoreCompletedSuccessfully(dpaCR.Client, namespace, restoreName)
succeeded, err = IsRestoreCompletedSuccessfully(dpaCR.Client, namespace, restoreName)
Expect(err).ToNot(HaveOccurred())
Expect(succeeded).To(Equal(true))

// verify app is running
Eventually(areApplicationPodsRunning(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*9, time.Second*5).Should(BeTrue())
Eventually(AreApplicationPodsRunning(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*9, time.Second*5).Should(BeTrue())

// Run optional custom verification
log.Printf("Running post-restore function for case %s", brCase.Name)
Expand All @@ -152,15 +155,15 @@ var _ = Describe("AWS backup restore tests", func() {

// Test is successful, clean up everything
log.Printf("Uninstalling application for case %s", brCase.Name)
err = uninstallApplication(dpaCR.Client, brCase.ApplicationTemplate)
err = UninstallApplication(dpaCR.Client, brCase.ApplicationTemplate)
Expect(err).ToNot(HaveOccurred())

// Wait for namespace to be deleted
Eventually(isNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue())
Eventually(IsNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue())

if brCase.BackupRestoreType == csi {
if brCase.BackupRestoreType == CSI {
log.Printf("Deleting VolumeSnapshot for CSI backuprestore of %s", brCase.Name)
err = uninstallApplication(dpaCR.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml")
err = UninstallApplication(dpaCR.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml")
Expect(err).ToNot(HaveOccurred())
}

Expand All @@ -169,35 +172,35 @@ var _ = Describe("AWS backup restore tests", func() {
ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-csi-template.yaml",
ApplicationNamespace: "mssql-persistent",
Name: "mssql-e2e",
BackupRestoreType: csi,
BackupRestoreType: CSI,
PreBackupVerify: mssqlReady,
PostRestoreVerify: mssqlReady,
}, nil),
Entry("Parks application <4.8.0", BackupRestoreCase{
ApplicationTemplate: "./sample-applications/parks-app/manifest.yaml",
ApplicationNamespace: "parks-app",
Name: "parks-e2e",
BackupRestoreType: restic,
BackupRestoreType: RESTIC,
PreBackupVerify: parksAppReady,
PostRestoreVerify: parksAppReady,
MaxK8SVersion: &k8sVersionOcp47,
MaxK8SVersion: &K8sVersionOcp47,
}, nil),
Entry("MSSQL application", BackupRestoreCase{
ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-template.yaml",
ApplicationNamespace: "mssql-persistent",
Name: "mssql-e2e",
BackupRestoreType: restic,
BackupRestoreType: RESTIC,
PreBackupVerify: mssqlReady,
PostRestoreVerify: mssqlReady,
}, nil),
Entry("Parks application >=4.8.0", BackupRestoreCase{
ApplicationTemplate: "./sample-applications/parks-app/manifest4.8.yaml",
ApplicationNamespace: "parks-app",
Name: "parks-e2e",
BackupRestoreType: restic,
BackupRestoreType: RESTIC,
PreBackupVerify: parksAppReady,
PostRestoreVerify: parksAppReady,
MinK8SVersion: &k8sVersionOcp48,
MinK8SVersion: &K8sVersionOcp48,
}, nil),
)
})
Loading