-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoBackup e2e Test: - [x] PVC - [x] success case - [x] failure case - [x] Deployment - [x] success case - [x] failure case - [x] StatefulSet - [x] success case - [x] failure case - [x] DaemonSet - [x] success case - [x] failure case
- Loading branch information
Showing
40 changed files
with
2,523 additions
and
1,155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
package auto_backup | ||
|
||
import ( | ||
"fmt" | ||
|
||
"stash.appscode.dev/stash/apis" | ||
"stash.appscode.dev/stash/apis/stash/v1alpha1" | ||
"stash.appscode.dev/stash/apis/stash/v1beta1" | ||
"stash.appscode.dev/stash/pkg/eventer" | ||
"stash.appscode.dev/stash/test/e2e/framework" | ||
"stash.appscode.dev/stash/test/e2e/matcher" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
store "kmodules.xyz/objectstore-api/api/v1" | ||
) | ||
|
||
var _ = Describe("Auto-Backup", func() { | ||
|
||
var f *framework.Invocation | ||
|
||
BeforeEach(func() { | ||
f = framework.NewInvocation() | ||
}) | ||
|
||
AfterEach(func() { | ||
err := f.CleanupTestResources() | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
annotations := func(backupBlueprintName string) map[string]string { | ||
return map[string]string{ | ||
v1beta1.KeyBackupBlueprint: backupBlueprintName, | ||
v1beta1.KeyTargetPaths: framework.TestSourceDataTargetPath, | ||
v1beta1.KeyVolumeMounts: framework.TestSourceDataVolumeMount, | ||
} | ||
} | ||
|
||
Context("DaemonSet", func() { | ||
|
||
Context("Success Case", func() { | ||
|
||
It("should backup successfully", func() { | ||
// Create BackupBlueprint | ||
bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Deploy a DaemonSet | ||
dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Generate Sample Data | ||
_, err = f.GenerateSampleData(dmn.ObjectMeta, apis.KindDaemonSet) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Add and Ensure annotations to Target | ||
err = f.AddAutoBackupAnnotations(annotations(bb.Name), dmn) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// ensure Repository and BackupConfiguration | ||
backupConfig, err := f.VerifyAutoBackupConfigured(dmn.ObjectMeta, apis.KindDaemonSet) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Take an Instant Backup the Sample Data | ||
backupSession, err := f.TakeInstantBackup(backupConfig.ObjectMeta) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Verifying that BackupSession has succeeded") | ||
completedBS, err := f.StashClient.StashV1beta1().BackupSessions(backupSession.Namespace).Get(backupSession.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionSucceeded)) | ||
}) | ||
}) | ||
|
||
Context("Failure Case", func() { | ||
|
||
Context("Missing AutoBackup resource credential in BackupBlueprint", func() { | ||
It("should fail BackupSession for missing backend repository credential", func() { | ||
// Create Secret for BackupBlueprint | ||
secret, err := f.CreateBackendSecretForMinio() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Generate BackupBlueprint definition | ||
bb := f.BackupBlueprint(secret.Name) | ||
bb.Spec.Backend.S3 = &store.S3Spec{} | ||
By(fmt.Sprintf("Creating BackupBlueprint: %s", bb.Name)) | ||
_, err = f.CreateBackupBlueprint(bb) | ||
Expect(err).NotTo(HaveOccurred()) | ||
f.AppendToCleanupList(bb) | ||
|
||
// Deploy a DaemonSet | ||
dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Generate Sample Data | ||
_, err = f.GenerateSampleData(dmn.ObjectMeta, apis.KindDaemonSet) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Add and Ensure annotations to Target | ||
err = f.AddAutoBackupAnnotations(annotations(bb.Name), dmn) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// ensure Repository and BackupConfiguration | ||
backupConfig, err := f.VerifyAutoBackupConfigured(dmn.ObjectMeta, apis.KindDaemonSet) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Take an Instant Backup the Sample Data | ||
backupSession, err := f.TakeInstantBackup(backupConfig.ObjectMeta) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Verifying that BackupSession has failed") | ||
completedBS, err := f.StashClient.StashV1beta1().BackupSessions(backupSession.Namespace).Get(backupSession.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionFailed)) | ||
}) | ||
It("should fail BackupSession for missing RetentionPolicy", func() { | ||
// Create Storage Secret for Minio | ||
secret, err := f.CreateBackendSecretForMinio() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Generate BackupBlueprint definition | ||
bb := f.BackupBlueprint(secret.Name) | ||
bb.Spec.RetentionPolicy = v1alpha1.RetentionPolicy{} | ||
By(fmt.Sprintf("Creating BackupBlueprint: %s", bb.Name)) | ||
_, err = f.CreateBackupBlueprint(bb) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Deploy a DaemonSet | ||
dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Generate Sample Data | ||
_, err = f.GenerateSampleData(dmn.ObjectMeta, apis.KindDaemonSet) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Add and Ensure annotations to Target | ||
err = f.AddAutoBackupAnnotations(annotations(bb.Name), dmn) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// ensure Repository and BackupConfiguration | ||
backupConfig, err := f.VerifyAutoBackupConfigured(dmn.ObjectMeta, apis.KindDaemonSet) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Take an Instant Backup the Sample Data | ||
backupSession, err := f.TakeInstantBackup(backupConfig.ObjectMeta) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Verifying that BackupSession has failed") | ||
completedBS, err := f.StashClient.StashV1beta1().BackupSessions(backupSession.Namespace).Get(backupSession.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionFailed)) | ||
}) | ||
}) | ||
|
||
Context("Add inappropriate annotation to Target", func() { | ||
It("should fail to create AutoBackup resources", func() { | ||
// Create BackupBlueprint | ||
_, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Deploy a DaemonSet | ||
dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Generate Sample Data | ||
_, err = f.GenerateSampleData(dmn.ObjectMeta, apis.KindDaemonSet) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Add and Ensure annotations to Target | ||
err = f.AddAutoBackupAnnotations(annotations(framework.WrongBackupBlueprintName), dmn) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// AutoBackup Resource creation failed | ||
f.EventuallyEvent(dmn.ObjectMeta, apis.KindDaemonSet).Should(matcher.HaveEvent(eventer.EventReasonAutoBackupResourcesCreationFailed)) | ||
|
||
}) | ||
It("should fail BackupSession for adding inappropriate TargetPath/MountPath", func() { | ||
// Create BackupBlueprint | ||
bb, err := f.CreateBackupBlueprintForWorkload(fmt.Sprintf("backupblueprint-%s", f.App())) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Deploy a DaemonSet | ||
dmn, err := f.DeployDaemonSet(fmt.Sprintf("dmn-%s", f.App())) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Generate Sample Data | ||
_, err = f.GenerateSampleData(dmn.ObjectMeta, apis.KindDaemonSet) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Add and Ensure annotations to Target | ||
anno := annotations(bb.Name) | ||
anno[v1beta1.KeyTargetPaths] = framework.WrongTargetPath | ||
err = f.AddAutoBackupAnnotations(anno, dmn) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// ensure Repository and BackupConfiguration | ||
backupConfig, err := f.VerifyAutoBackupConfigured(dmn.ObjectMeta, apis.KindDaemonSet) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Take an Instant Backup the Sample Data | ||
backupSession, err := f.TakeInstantBackup(backupConfig.ObjectMeta) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Verifying that BackupSession has failed") | ||
completedBS, err := f.StashClient.StashV1beta1().BackupSessions(backupSession.Namespace).Get(backupSession.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(completedBS.Status.Phase).Should(Equal(v1beta1.BackupSessionFailed)) | ||
}) | ||
|
||
}) | ||
}) | ||
}) | ||
|
||
}) |
Oops, something went wrong.