Skip to content

Commit

Permalink
Refactored changes to accomdate package structuring
Browse files Browse the repository at this point in the history
  • Loading branch information
nitishSr committed Feb 2, 2022
1 parent 6f8995b commit 17c8dc2
Show file tree
Hide file tree
Showing 18 changed files with 433 additions and 242 deletions.
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.16

require (
github.com/aws/aws-sdk-go v1.28.2
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v0.4.0
github.com/google/uuid v1.1.2
github.com/onsi/ginkgo v1.16.5
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package e2e
package e2e_test

import (
"errors"
Expand All @@ -10,19 +10,22 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "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 @@ -39,19 +42,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 @@ -71,17 +74,17 @@ 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 {
if clusterProfile == "aws" {
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())
} else {
Skip("CSI testing is not provided for this cluster provider.")
Expand All @@ -90,7 +93,7 @@ var _ = Describe("AWS backup restore tests", func() {

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 @@ -102,10 +105,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 @@ -114,41 +117,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 @@ -157,15 +160,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 @@ -174,35 +177,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

0 comments on commit 17c8dc2

Please sign in to comment.