Skip to content

Commit

Permalink
Add AutoBackup e2e test (#939)
Browse files Browse the repository at this point in the history
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
suaas21 authored and tamalsaha committed Oct 30, 2019
1 parent 6979ff8 commit dc34560
Show file tree
Hide file tree
Showing 40 changed files with 2,523 additions and 1,155 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.12

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/appscode/go v0.0.0-20191016085057-e186b6c94a3b
github.com/appscode/go v0.0.0-20191025021232-311ac347b3ef
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
github.com/cenkalti/backoff v2.1.1+incompatible
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27
Expand All @@ -26,7 +26,7 @@ require (
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
github.com/stretchr/testify v1.3.0
gomodules.xyz/cert v1.0.0
gomodules.xyz/cert v1.0.1
gomodules.xyz/envsubst v0.1.0
gomodules.xyz/stow v0.2.2
gopkg.in/ini.v1 v1.41.0
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb
github.com/appscode/docker-registry-client v0.0.0-20180426150142-1bb02bb202b0/go.mod h1:W9bsWfSbgJXUXzBZ+tSBV2g+zzT7ANPHQFsSXRHYKsA=
github.com/appscode/go v0.0.0-20190808133642-1d4ef1f1c1e0/go.mod h1:iy07dV61Z7QQdCKJCIvUoDL21u6AIceRhZzyleh2ymc=
github.com/appscode/go v0.0.0-20191006073906-e3d193d493fc/go.mod h1:hUW7Fq0KY2/ntGnYAzemyUpIhLL6bXrTljN6SRY/+Lc=
github.com/appscode/go v0.0.0-20191016085057-e186b6c94a3b h1:UskbETXW8u0DRCPU1pyBIgA55BFUnjuYjmt3qOBMdAY=
github.com/appscode/go v0.0.0-20191016085057-e186b6c94a3b/go.mod h1:hUW7Fq0KY2/ntGnYAzemyUpIhLL6bXrTljN6SRY/+Lc=
github.com/appscode/go v0.0.0-20191025021232-311ac347b3ef h1:nTbtvdVAVwFgKANCR4KU36Jo1V9Xs/Z2GMEAlpOVG1Y=
github.com/appscode/go v0.0.0-20191025021232-311ac347b3ef/go.mod h1:hUW7Fq0KY2/ntGnYAzemyUpIhLL6bXrTljN6SRY/+Lc=
github.com/appscode/osm v0.12.0 h1:7Rde+KnOp3EvHscXHS6rfdqiq6IO/2HZ2pKeE4f/sRo=
github.com/appscode/osm v0.12.0/go.mod h1:+ZXU2HilSSow2o0gsOolJfOTkhqQ2FcGROOum4wEh4w=
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 h1:7Ip0wMmLHLRJdrloDxZfhMm0xrLXZS8+COSu2bXmEQs=
Expand Down Expand Up @@ -410,8 +411,8 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gomodules.xyz/cert v1.0.0 h1:9vcN2V4g9Ol8LGqHd0FWSO0N8SjIbFLombfVk8Js22o=
gomodules.xyz/cert v1.0.0/go.mod h1:MG5H3SxZdkG8nng6QuQhXMTs+qt/qDLNXgUtbme82hQ=
gomodules.xyz/cert v1.0.1 h1:rowTfCHIKfcItwYurd1LYEmeMg9Svt4n5HWaoNS2HkE=
gomodules.xyz/cert v1.0.1/go.mod h1:DBLsvMRZSqek9FyAX/wVtUWkO6muPoWIvSlqGtrjGWg=
gomodules.xyz/envsubst v0.1.0 h1:xvS0A4NeRwa8y3qW/+jgc13nT3rW1nlcuePDJujHzBM=
gomodules.xyz/envsubst v0.1.0/go.mod h1:2o5f7bd13XIITbE2ZKieE05YkqB2KDoZkqKccGebduA=
gomodules.xyz/jsonpatch/v2 v2.0.0 h1:OyHbl+7IOECpPKfVK42oFr6N7+Y2dR+Jsb/IiDV3hOo=
Expand Down
215 changes: 215 additions & 0 deletions test/e2e/auto-backup/daemonset.go
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))
})

})
})
})

})
Loading

0 comments on commit dc34560

Please sign in to comment.