Skip to content

Commit

Permalink
Add E2E test cases for backup VolumeInfo feature.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <blackpigletbruce@gmail.com>
  • Loading branch information
Xun Jiang authored and blackpiglet committed Feb 7, 2024
1 parent a9e80d5 commit 354482c
Show file tree
Hide file tree
Showing 11 changed files with 496 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/velero-restore-helper/velero-restore-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func done() bool {
return false
}

fmt.Printf("Found %s", doneFile)
fmt.Printf("Found the done file %s\n", doneFile)
}

return true
Expand Down
116 changes: 116 additions & 0 deletions test/e2e/basic/backup-volume-info/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package basic

import (
"context"
"fmt"
"strconv"
"time"

. "github.com/onsi/gomega"
"github.com/pkg/errors"

. "github.com/vmware-tanzu/velero/test"
. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/util/k8s"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

type BackupVolumeInfo struct {
TestCase
SnapshotVolumes bool
DefaultVolumesToFSBackup bool
SnapshotMoveData bool
TimeoutDuration time.Duration
}

func (v *BackupVolumeInfo) Init() error {
v.TestCase.Init()
v.CaseBaseName = "volumeinfo-" + v.UUIDgen
v.BackupName = "backup-" + v.CaseBaseName
v.RestoreName = "restore-" + v.CaseBaseName
v.TimeoutDuration = 10 * time.Minute
v.NamespacesTotal = 1

v.VeleroCfg = VeleroCfg
v.Client = *v.VeleroCfg.ClientToInstallVelero
v.NSIncluded = &[]string{v.CaseBaseName}

v.TestMsg = &TestMSG{
Desc: "Backup with the label selector test",
Text: "Should backup resources with selected label resource",
FailedMSG: "Failed to backup resources with selected label",
}

v.BackupArgs = []string{
"backup", "create", v.BackupName,
"--namespace", v.VeleroCfg.VeleroNamespace,
"--include-namespaces", v.CaseBaseName,
"--snapshot-volumes" + "=" + strconv.FormatBool(v.SnapshotVolumes),
"--default-volumes-to-fs-backup" + "=" + strconv.FormatBool(v.DefaultVolumesToFSBackup),
"--snapshot-move-data" + "=" + strconv.FormatBool(v.SnapshotMoveData),
"--wait",
}

v.RestoreArgs = []string{
"create", "--namespace", v.VeleroCfg.VeleroNamespace, "restore", v.RestoreName,
"--from-backup", v.BackupName, "--wait",
}
return nil
}

func (v *BackupVolumeInfo) CreateResources() error {
v.Ctx, v.CtxCancel = context.WithTimeout(context.Background(), v.TimeoutDuration)
labels := map[string]string{
"volume-info": "true",
}
for nsNum := 0; nsNum < v.NamespacesTotal; nsNum++ {
fmt.Printf("Creating namespaces ...\n")
createNSName := v.CaseBaseName
if err := CreateNamespaceWithLabel(v.Ctx, v.Client, createNSName, labels); err != nil {
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
}

Expect(InstallTestStorageClasses(fmt.Sprintf("../testdata/storage-class/%s.yaml", v.VeleroCfg.CloudProvider))).To(Succeed(), "Failed to install storage class")

pvc, err := CreatePVC(v.Client, createNSName, "volume-info", StorageClassName, nil)
Expect(err).To(Succeed())
vols := CreateVolumes(pvc.Name, []string{"volume-info"})

//Create deployment
fmt.Printf("Creating deployment in namespaces ...%s\n", createNSName)
deployment := NewDeployment(v.CaseBaseName, createNSName, 1, labels, nil).WithVolume(vols).Result()
deployment, err = CreateDeployment(v.Client.ClientGo, createNSName, deployment)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to delete the namespace %q", createNSName))
}
err = WaitForReadyDeployment(v.Client.ClientGo, createNSName, deployment.Name)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to ensure job completion in namespace: %q", createNSName))
}
}
return nil
}

func (v *BackupVolumeInfo) Destroy() error {
err := CleanupNamespaces(v.Ctx, v.Client, v.CaseBaseName)
if err != nil {
return errors.Wrap(err, "Could cleanup retrieve namespaces")
}
return WaitAllSelectedNSDeleted(v.Ctx, v.Client, "ns-test=true")
}
55 changes: 55 additions & 0 deletions test/e2e/basic/backup-volume-info/csi_data_mover.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package basic

import (
"fmt"

. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/util/providers"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

var CSIDataMoverVolumeInfoTest func() = TestFunc(&CSIDataMoverVolumeInfo{
BackupVolumeInfo{
SnapshotMoveData: true,
},
})

type CSIDataMoverVolumeInfo struct {
BackupVolumeInfo
}

func (f *CSIDataMoverVolumeInfo) Verify() error {
volumeInfo, err := GetVolumeInfo(
f.VeleroCfg.CloudProvider,
f.VeleroCfg.CloudCredentialsFile,
f.VeleroCfg.BSLBucket,
f.VeleroCfg.BSLPrefix,
f.VeleroCfg.BSLConfig,
f.BackupName,
BackupObjectsPrefix+"/"+f.BackupName,
)

Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Fail to get VolumeInfo metadata in the Backup Repository."))
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].SnapshotDataMovementInfo).NotTo(BeNil())

return err
}
55 changes: 55 additions & 0 deletions test/e2e/basic/backup-volume-info/filesystem_upload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package basic

import (
"fmt"

. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/util/providers"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

var FilesystemUploadVolumeInfoTest func() = TestFunc(&FilesystemUploadVolumeInfo{
BackupVolumeInfo{
DefaultVolumesToFSBackup: true,
},
})

type FilesystemUploadVolumeInfo struct {
BackupVolumeInfo
}

func (f *FilesystemUploadVolumeInfo) Verify() error {
volumeInfo, err := GetVolumeInfo(
f.VeleroCfg.CloudProvider,
f.VeleroCfg.CloudCredentialsFile,
f.VeleroCfg.BSLBucket,
f.VeleroCfg.BSLPrefix,
f.VeleroCfg.BSLConfig,
f.BackupName,
BackupObjectsPrefix+"/"+f.BackupName,
)

Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Fail to get VolumeInfo metadata in the Backup Repository."))
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].PVBInfo).NotTo(BeNil())

return err
}
51 changes: 51 additions & 0 deletions test/e2e/basic/backup-volume-info/native_snapshot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package basic

import (
"fmt"

. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/util/providers"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

var NativeSnapshotVolumeInfoTest func() = TestFunc(&NativeSnapshotVolumeInfo{})

type NativeSnapshotVolumeInfo struct {
BackupVolumeInfo
}

func (f *NativeSnapshotVolumeInfo) Verify() error {
volumeInfo, err := GetVolumeInfo(
f.VeleroCfg.CloudProvider,
f.VeleroCfg.CloudCredentialsFile,
f.VeleroCfg.BSLBucket,
f.VeleroCfg.BSLPrefix,
f.VeleroCfg.BSLConfig,
f.BackupName,
BackupObjectsPrefix+"/"+f.BackupName,
)

Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Fail to get VolumeInfo metadata in the Backup Repository."))
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].NativeSnapshotInfo).NotTo(BeNil())

return err
}
55 changes: 55 additions & 0 deletions test/e2e/basic/backup-volume-info/skipped_volumes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package basic

import (
"fmt"

. "github.com/onsi/gomega"

. "github.com/vmware-tanzu/velero/test/e2e/test"
. "github.com/vmware-tanzu/velero/test/util/providers"
. "github.com/vmware-tanzu/velero/test/util/velero"
)

var SkippedVolumeInfoTest func() = TestFunc(&SkippedVolumeInfo{
BackupVolumeInfo{
SnapshotVolumes: false,
},
})

type SkippedVolumeInfo struct {
BackupVolumeInfo
}

func (s *SkippedVolumeInfo) Verify() error {
volumeInfo, err := GetVolumeInfo(
s.VeleroCfg.CloudProvider,
s.VeleroCfg.CloudCredentialsFile,
s.VeleroCfg.BSLBucket,
s.VeleroCfg.BSLPrefix,
s.VeleroCfg.BSLConfig,
s.BackupName,
BackupObjectsPrefix+"/"+s.BackupName,
)

Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Fail to get VolumeInfo metadata in the Backup Repository."))
Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true))
Expect(volumeInfo[0].Skipped == true).To(BeIdenticalTo(true))

return err
}
7 changes: 6 additions & 1 deletion test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
. "github.com/vmware-tanzu/velero/test/e2e/backups"
. "github.com/vmware-tanzu/velero/test/e2e/basic"
. "github.com/vmware-tanzu/velero/test/e2e/basic/api-group"
. "github.com/vmware-tanzu/velero/test/e2e/basic/backup-volume-info"
. "github.com/vmware-tanzu/velero/test/e2e/basic/resources-check"
. "github.com/vmware-tanzu/velero/test/e2e/bsl-mgmt"
. "github.com/vmware-tanzu/velero/test/e2e/migration"
Expand Down Expand Up @@ -136,14 +137,18 @@ var _ = Describe("[ResourceFiltering][IncludeResources][Restore] Velero test on
var _ = Describe("[ResourceFiltering][LabelSelector] Velero test on backup include resources matching the label selector", BackupWithLabelSelector)
var _ = Describe("[ResourceFiltering][ResourcePolicies] Velero test on skip backup of volume by resource policies", ResourcePoliciesTest)

// backup VolumeInfo test
var _ = Describe("[BackupVolumeInfo][SkippedVolume]", SkippedVolumeInfoTest)
var _ = Describe("[BackupVolumeInfo][FilesystemUpload]", FilesystemUploadVolumeInfoTest)

var _ = Describe("[ResourceModifier][Restore] Velero test on resource modifiers from the cluster restore", ResourceModifiersTest)

var _ = Describe("[Backups][Deletion][Restic] Velero tests of Restic backup deletion", BackupDeletionWithRestic)
var _ = Describe("[Backups][Deletion][Snapshot] Velero tests of snapshot backup deletion", BackupDeletionWithSnapshots)
var _ = Describe("[Backups][TTL][LongTime] Local backups and restic repos will be deleted once the corresponding backup storage location is deleted", TTLTest)
var _ = Describe("[Backups][BackupsSync] Backups in object storage are synced to a new Velero and deleted backups in object storage are synced to be deleted in Velero", BackupsSyncTest)

var _ = Describe("[Schedule][BR][Pause][LongTime] Backup will be created periodly by schedule defined by a Cron expression", ScheduleBackupTest)
var _ = Describe("[Schedule][BR][Pause][LongTime] Backup will be created periodically by schedule defined by a Cron expression", ScheduleBackupTest)
var _ = Describe("[Schedule][OrederedResources] Backup resources should follow the specific order in schedule", ScheduleOrderedResources)
var _ = Describe("[Schedule][BackupCreation] Schedule controller wouldn't create a new backup when it still has pending or InProgress backup", ScheduleBackupCreationTest)

Expand Down
Loading

0 comments on commit 354482c

Please sign in to comment.