mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 05:46:37 +00:00
1. Fix context issues produced by previous PR, increase timeout or add case scpoed global timeout param to make backup/restore command timeout configurable. 2. Add global param for storage class name using by test cases; 3. Fix param DefaultVolumesToFsBackup usage issue: set DefaultVolumesToFsBackup to false in backup CLI in case it was set to true in install CLI. 4. Make namespace names of each namespace mapping test unique from being interfered by each other. Signed-off-by: danfengl <danfengl@vmware.com>
118 lines
4.6 KiB
Go
118 lines
4.6 KiB
Go
package basic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
|
|
. "github.com/vmware-tanzu/velero/test/e2e"
|
|
. "github.com/vmware-tanzu/velero/test/e2e/test"
|
|
. "github.com/vmware-tanzu/velero/test/e2e/util/k8s"
|
|
. "github.com/vmware-tanzu/velero/test/e2e/util/kibishii"
|
|
)
|
|
|
|
type NamespaceMapping struct {
|
|
TestCase
|
|
MappedNamespaceList []string
|
|
kibishiiData *KibishiiData
|
|
}
|
|
|
|
const NamespaceBaseName string = "ns-mp-"
|
|
|
|
var OneNamespaceMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: NamespaceBaseName, NSIncluded: &[]string{NamespaceBaseName + "1"}, UseVolumeSnapshots: false}})
|
|
var MultiNamespacesMappingResticTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: NamespaceBaseName, NSIncluded: &[]string{NamespaceBaseName + "2", NamespaceBaseName + "3"}, UseVolumeSnapshots: false}})
|
|
var OneNamespaceMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: NamespaceBaseName, NSIncluded: &[]string{NamespaceBaseName + "4"}, UseVolumeSnapshots: true}})
|
|
var MultiNamespacesMappingSnapshotTest func() = TestFunc(&NamespaceMapping{TestCase: TestCase{NSBaseName: NamespaceBaseName, NSIncluded: &[]string{NamespaceBaseName + "5", NamespaceBaseName + "6"}, UseVolumeSnapshots: true}})
|
|
|
|
func (n *NamespaceMapping) Init() error {
|
|
n.VeleroCfg = VeleroCfg
|
|
n.Client = *n.VeleroCfg.ClientToInstallVelero
|
|
n.VeleroCfg.UseVolumeSnapshots = n.UseVolumeSnapshots
|
|
n.VeleroCfg.UseNodeAgent = !n.UseVolumeSnapshots
|
|
n.kibishiiData = &KibishiiData{Levels: 2, DirsPerLevel: 10, FilesPerLevel: 10, FileLength: 1024, BlockSize: 1024, PassNum: 0, ExpectedNodes: 2}
|
|
backupType := "restic"
|
|
if n.UseVolumeSnapshots {
|
|
backupType = "snapshot"
|
|
}
|
|
n.TestMsg = &TestMSG{
|
|
Desc: fmt.Sprintf("Restore namespace %s with namespace mapping by %s test", *n.NSIncluded, backupType),
|
|
FailedMSG: "Failed to restore with namespace mapping",
|
|
Text: fmt.Sprintf("should restore namespace %s with namespace mapping by %s", *n.NSIncluded, backupType),
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (n *NamespaceMapping) StartRun() error {
|
|
var mappedNS string
|
|
var mappedNSList []string
|
|
|
|
for index, ns := range *n.NSIncluded {
|
|
mappedNS = mappedNS + ns + ":" + ns + UUIDgen.String()
|
|
mappedNSList = append(mappedNSList, ns+UUIDgen.String())
|
|
if index+1 != len(*n.NSIncluded) {
|
|
mappedNS = mappedNS + ","
|
|
}
|
|
n.BackupName = n.BackupName + ns
|
|
n.RestoreName = n.RestoreName + ns
|
|
}
|
|
n.BackupName = n.BackupName + UUIDgen.String()
|
|
n.RestoreName = n.RestoreName + UUIDgen.String()
|
|
|
|
n.MappedNamespaceList = mappedNSList
|
|
fmt.Println(mappedNSList)
|
|
n.BackupArgs = []string{
|
|
"create", "--namespace", VeleroCfg.VeleroNamespace, "backup", n.BackupName,
|
|
"--include-namespaces", strings.Join(*n.NSIncluded, ","), "--wait",
|
|
}
|
|
if n.UseVolumeSnapshots {
|
|
n.BackupArgs = append(n.BackupArgs, "--snapshot-volumes")
|
|
} else {
|
|
n.BackupArgs = append(n.BackupArgs, "--snapshot-volumes=false")
|
|
n.BackupArgs = append(n.BackupArgs, "--default-volumes-to-fs-backup")
|
|
}
|
|
n.RestoreArgs = []string{
|
|
"create", "--namespace", VeleroCfg.VeleroNamespace, "restore", n.RestoreName,
|
|
"--from-backup", n.BackupName, "--namespace-mappings", mappedNS,
|
|
"--wait",
|
|
}
|
|
return nil
|
|
}
|
|
func (n *NamespaceMapping) CreateResources() error {
|
|
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
|
defer ctxCancel()
|
|
for index, ns := range *n.NSIncluded {
|
|
n.kibishiiData.Levels = len(*n.NSIncluded) + index
|
|
By(fmt.Sprintf("Creating namespaces ...%s\n", ns), func() {
|
|
Expect(CreateNamespace(ctx, n.Client, ns)).To(Succeed(), fmt.Sprintf("Failed to create namespace %s", ns))
|
|
})
|
|
By("Deploy sample workload of Kibishii", func() {
|
|
Expect(KibishiiPrepareBeforeBackup(ctx, n.Client, VeleroCfg.CloudProvider,
|
|
ns, VeleroCfg.RegistryCredentialFile, VeleroCfg.Features,
|
|
VeleroCfg.KibishiiDirectory, false, n.kibishiiData)).To(Succeed())
|
|
})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (n *NamespaceMapping) Verify() error {
|
|
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
|
defer ctxCancel()
|
|
for index, ns := range n.MappedNamespaceList {
|
|
n.kibishiiData.Levels = len(*n.NSIncluded) + index
|
|
By(fmt.Sprintf("Verify workload %s after restore ", ns), func() {
|
|
Expect(KibishiiVerifyAfterRestore(n.Client, ns,
|
|
ctx, n.kibishiiData)).To(Succeed(), "Fail to verify workload after restore")
|
|
})
|
|
}
|
|
for _, ns := range *n.NSIncluded {
|
|
By(fmt.Sprintf("Verify namespace %s for backup is no longer exist after restore with namespace mapping", ns), func() {
|
|
Expect(NamespaceShouldNotExist(ctx, n.Client, ns)).To(Succeed())
|
|
})
|
|
}
|
|
return nil
|
|
}
|