mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-20 15:04:17 +00:00
+13
-22
@@ -72,7 +72,8 @@ type TestCase struct {
|
||||
UseVolumeSnapshots bool
|
||||
VeleroCfg VeleroConfig
|
||||
RestorePhaseExpect velerov1api.RestorePhase
|
||||
Timeout time.Duration
|
||||
Ctx context.Context
|
||||
CtxCancel context.CancelFunc
|
||||
UUIDgen string
|
||||
}
|
||||
|
||||
@@ -80,11 +81,6 @@ func TestFunc(test VeleroBackupRestoreTest) func() {
|
||||
return func() {
|
||||
Expect(test.Init()).To(Succeed(), "Failed to instantiate test cases")
|
||||
veleroCfg := test.GetTestCase().VeleroCfg
|
||||
// If TestCase.Timeout is not set, then make 10 minutes as default value for backup
|
||||
// or restore CLI
|
||||
if test.GetTestCase().Timeout == 0 {
|
||||
test.GetTestCase().Timeout = 10 * time.Minute
|
||||
}
|
||||
BeforeEach(func() {
|
||||
flag.Parse()
|
||||
veleroCfg := test.GetTestCase().VeleroCfg
|
||||
@@ -117,11 +113,9 @@ func TestFuncWithMultiIt(tests []VeleroBackupRestoreTest) func() {
|
||||
var veleroCfg VeleroConfig
|
||||
for k := range tests {
|
||||
Expect(tests[k].Init()).To(Succeed(), fmt.Sprintf("Failed to instantiate test %s case", tests[k].GetTestMsg().Desc))
|
||||
if tests[k].GetTestCase().Timeout == 0 {
|
||||
tests[k].GetTestCase().Timeout = 10 * time.Minute
|
||||
}
|
||||
veleroCfg = tests[k].GetTestCase().VeleroCfg
|
||||
useVolumeSnapshots = tests[k].GetTestCase().UseVolumeSnapshots
|
||||
defer tests[k].GetTestCase().CtxCancel()
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
@@ -156,6 +150,7 @@ func TestFuncWithMultiIt(tests []VeleroBackupRestoreTest) func() {
|
||||
}
|
||||
|
||||
func (t *TestCase) Init() error {
|
||||
t.Ctx, t.CtxCancel = context.WithTimeout(context.Background(), 1*time.Hour)
|
||||
t.UUIDgen = t.GenerateUUID()
|
||||
return nil
|
||||
}
|
||||
@@ -170,10 +165,8 @@ func (t *TestCase) CreateResources() error {
|
||||
}
|
||||
|
||||
func (t *TestCase) Backup() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), t.Timeout)
|
||||
defer ctxCancel()
|
||||
veleroCfg := t.GetTestCase().VeleroCfg
|
||||
if err := VeleroBackupExec(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.BackupName, t.BackupArgs); err != nil {
|
||||
if err := VeleroBackupExec(t.Ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.BackupName, t.BackupArgs); err != nil {
|
||||
RunDebug(context.Background(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.BackupName, "")
|
||||
return errors.Wrapf(err, "Failed to backup resources")
|
||||
}
|
||||
@@ -181,17 +174,17 @@ func (t *TestCase) Backup() error {
|
||||
}
|
||||
|
||||
func (t *TestCase) Destroy() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
By(fmt.Sprintf("Start to destroy namespace %s......", t.CaseBaseName), func() {
|
||||
Expect(CleanupNamespacesWithPoll(ctx, t.Client, t.CaseBaseName)).To(Succeed(), "Could cleanup retrieve namespaces")
|
||||
Expect(CleanupNamespacesWithPoll(t.Ctx, t.Client, t.CaseBaseName)).To(Succeed(), "Could cleanup retrieve namespaces")
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TestCase) Restore() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), t.Timeout)
|
||||
defer ctxCancel()
|
||||
if len(t.RestoreArgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
veleroCfg := t.GetTestCase().VeleroCfg
|
||||
// the snapshots of AWS may be still in pending status when do the restore, wait for a while
|
||||
// to avoid this https://github.com/vmware-tanzu/velero/issues/1799
|
||||
@@ -205,7 +198,7 @@ func (t *TestCase) Restore() error {
|
||||
if t.RestorePhaseExpect == "" {
|
||||
t.RestorePhaseExpect = velerov1api.RestorePhaseCompleted
|
||||
}
|
||||
Expect(VeleroRestoreExec(ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.RestoreName, t.RestoreArgs, t.RestorePhaseExpect)).To(Succeed(), func() string {
|
||||
Expect(VeleroRestoreExec(t.Ctx, veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, t.RestoreName, t.RestoreArgs, t.RestorePhaseExpect)).To(Succeed(), func() string {
|
||||
RunDebug(context.Background(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, "", t.RestoreName)
|
||||
return "Fail to restore workload"
|
||||
})
|
||||
@@ -218,15 +211,13 @@ func (t *TestCase) Verify() error {
|
||||
}
|
||||
|
||||
func (t *TestCase) Clean() error {
|
||||
ctx, ctxCancel := context.WithTimeout(context.Background(), 60*time.Minute)
|
||||
defer ctxCancel()
|
||||
veleroCfg := t.GetTestCase().VeleroCfg
|
||||
if !veleroCfg.Debug {
|
||||
By(fmt.Sprintf("Clean namespace with prefix %s after test", t.CaseBaseName), func() {
|
||||
CleanupNamespaces(ctx, t.Client, t.CaseBaseName)
|
||||
CleanupNamespaces(t.Ctx, t.Client, t.CaseBaseName)
|
||||
})
|
||||
By("Clean backups after test", func() {
|
||||
DeleteBackups(ctx, t.Client)
|
||||
DeleteBackups(t.Ctx, t.Client)
|
||||
})
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user