From 463202951d221b871cf53efc324fe12e6bb07a47 Mon Sep 17 00:00:00 2001 From: danfengl Date: Sat, 11 Jun 2022 08:40:19 +0000 Subject: [PATCH] Enhance checkpoint of bsl deletion Signed-off-by: danfengl --- test/e2e/backups/sync_backups.go | 2 +- test/e2e/bsl-mgmt/deletion.go | 5 ++-- test/e2e/util/velero/velero_utils.go | 34 ++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/test/e2e/backups/sync_backups.go b/test/e2e/backups/sync_backups.go index cc3fefb23..37162bac1 100644 --- a/test/e2e/backups/sync_backups.go +++ b/test/e2e/backups/sync_backups.go @@ -161,5 +161,5 @@ func BackupsSyncTest() { } func (b *SyncBackups) IsBackupsSynced() error { - return WaitForBackupCreated(b.ctx, VeleroCfg.VeleroCLI, b.backupName, 10*time.Minute) + return WaitForBackupToBeCreated(b.ctx, VeleroCfg.VeleroCLI, b.backupName, 10*time.Minute) } diff --git a/test/e2e/bsl-mgmt/deletion.go b/test/e2e/bsl-mgmt/deletion.go index fd75ba180..b60531346 100644 --- a/test/e2e/bsl-mgmt/deletion.go +++ b/test/e2e/bsl-mgmt/deletion.go @@ -252,12 +252,12 @@ func BslDeletionTest(useVolumeSnapshots bool) { } By(fmt.Sprintf("Backup 1 %s should be created.", backupName_1), func() { - Expect(WaitForBackupCreated(context.Background(), VeleroCfg.VeleroCLI, + Expect(WaitForBackupToBeCreated(context.Background(), VeleroCfg.VeleroCLI, backupName_1, 10*time.Minute)).To(Succeed()) }) By(fmt.Sprintf("Backup 2 %s should be created.", backupName_2), func() { - Expect(WaitForBackupCreated(context.Background(), VeleroCfg.VeleroCLI, + Expect(WaitForBackupToBeCreated(context.Background(), VeleroCfg.VeleroCLI, backupName_2, 10*time.Minute)).To(Succeed()) }) @@ -280,6 +280,7 @@ func BslDeletionTest(useVolumeSnapshots bool) { By(fmt.Sprintf("Delete one of backup locations - %s", backupLocation_1), func() { Expect(DeleteBslResource(context.Background(), VeleroCfg.VeleroCLI, backupLocation_1)).To(Succeed()) + Expect(WaitForBackupsToBeDeleted(context.Background(), VeleroCfg.VeleroCLI, backupsInBSL1, 10*time.Minute)).To(Succeed()) }) By("Get all backups from 2 BSLs after deleting one of them", func() { diff --git a/test/e2e/util/velero/velero_utils.go b/test/e2e/util/velero/velero_utils.go index 92171c765..aa4d8eec4 100644 --- a/test/e2e/util/velero/velero_utils.go +++ b/test/e2e/util/velero/velero_utils.go @@ -705,6 +705,7 @@ func getVeleroCliTarball(cliTarballUrl string) (*os.File, error) { return tmpfile, nil } + func DeleteBackupResource(ctx context.Context, veleroCLI string, backupName string) error { args := []string{"backup", "delete", backupName, "--confirm"} @@ -771,19 +772,48 @@ func WaitBackupDeleted(ctx context.Context, veleroCLI string, backupName string, }) } -func WaitForBackupCreated(ctx context.Context, veleroCLI string, backupName string, timeout time.Duration) error { +func WaitForExpectedStateOfBackup(ctx context.Context, veleroCLI string, backupName string, + timeout time.Duration, existing bool) error { return wait.PollImmediate(10*time.Second, timeout, func() (bool, error) { if exist, err := IsBackupExist(ctx, veleroCLI, backupName); err != nil { return false, err } else { - if exist { + msg := "does not exist" + if existing { + msg = "was found" + } + if exist == existing { + fmt.Println("Backup <" + backupName + "> " + msg) return true, nil } else { + fmt.Println("Backup <" + backupName + "> " + msg) return false, nil } } }) } + +func WaitForBackupToBeCreated(ctx context.Context, veleroCLI string, backupName string, timeout time.Duration) error { + return WaitForExpectedStateOfBackup(ctx, veleroCLI, backupName, timeout, true) +} + +func WaitForBackupToBeDeleted(ctx context.Context, veleroCLI string, backupName string, timeout time.Duration) error { + return WaitForExpectedStateOfBackup(ctx, veleroCLI, backupName, timeout, false) +} + +func WaitForBackupsToBeDeleted(ctx context.Context, veleroCLI string, backups []string, timeout time.Duration) error { + var err error + for _, backupName := range backups { + fmt.Println("Waiting for deletion of backup <" + backupName + ">") + err = WaitForExpectedStateOfBackup(ctx, veleroCLI, backupName, timeout, false) + if err != nil { + return err + } + } + fmt.Println("All backups were deleted.") + return nil +} + func GetBackupsFromBsl(ctx context.Context, veleroCLI, bslName string) ([]string, error) { args1 := []string{"get", "backups"} if strings.TrimSpace(bslName) != "" {