Skip to content

Commit

Permalink
Add expected error for frequently failing test.
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Arnold <[email protected]>
  • Loading branch information
mrnold committed Aug 16, 2024
1 parent c868c36 commit 2a81385
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion tests/e2e/virt_backup_restore_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e_test

import (
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -58,6 +59,7 @@ type VmBackupRestoreCase struct {
Template string
InitDelay time.Duration
PowerState string
RestoreErr error
}

func runVmBackupAndRestore(brCase VmBackupRestoreCase, expectedErr error, updateLastBRcase func(brCase VmBackupRestoreCase), updateLastInstallTime func(), v *lib.VirtOperator) {
Expand Down Expand Up @@ -116,7 +118,7 @@ func runVmBackupAndRestore(brCase VmBackupRestoreCase, expectedErr error, update
Eventually(lib.IsNamespaceDeleted(kubernetesClientForSuiteRun, brCase.Namespace), time.Minute*5, time.Second*5).Should(BeTrue())

// Do restore
runRestore(brCase.BackupRestoreCase, backupName, restoreName, nsRequiresResticDCWorkaround)
runVmRestore(brCase, backupName, restoreName, nsRequiresResticDCWorkaround)

// Run optional custom verification
if brCase.PostRestoreVerify != nil {
Expand Down Expand Up @@ -241,6 +243,7 @@ var _ = Describe("VM backup and restore tests", Ordered, func() {
BackupTimeout: 20 * time.Minute,
PreBackupVerify: vmPoweredOff("cirros-test", "cirros-test"),
},
RestoreErr: errors.New("error to expose snapshot: error to wait target PVC consumed"),
}, nil),

Entry("immediate binding no-application CSI datamover backup and restore, CirrOS VM", Label("virt"), VmBackupRestoreCase{
Expand Down Expand Up @@ -310,3 +313,44 @@ var _ = Describe("VM backup and restore tests", Ordered, func() {
}, nil),
)
})

// Temporary VM-specific copy of runRestore. This is here to avoid making big
// changes to runRestore when they are likely to be taken out in the near future.
func runVmRestore(brCase VmBackupRestoreCase, backupName, restoreName string, nsRequiresResticDCWorkaround bool) {
log.Printf("Creating restore %s for case %s", restoreName, brCase.Name)
err := lib.CreateRestoreFromBackup(dpaCR.Client, namespace, backupName, restoreName)
Expect(err).ToNot(HaveOccurred())
Eventually(lib.IsRestoreDone(dpaCR.Client, namespace, restoreName), time.Minute*60, time.Second*10).Should(BeTrue())
// TODO only log on fail?
describeRestore := lib.DescribeRestore(veleroClientForSuiteRun, dpaCR.Client, namespace, restoreName)
GinkgoWriter.Println(describeRestore)

restoreLogs := lib.RestoreLogs(kubernetesClientForSuiteRun, dpaCR.Client, namespace, restoreName)
restoreErrorLogs := lib.RestoreErrorLogs(kubernetesClientForSuiteRun, dpaCR.Client, namespace, restoreName)
accumulatedTestLogs = append(accumulatedTestLogs, describeRestore, restoreLogs)

if !brCase.SkipVerifyLogs {
Expect(restoreErrorLogs).Should(Equal([]string{}))
}

// Check if restore succeeded
succeeded, err := lib.IsRestoreCompletedSuccessfully(kubernetesClientForSuiteRun, dpaCR.Client, namespace, restoreName)
if brCase.RestoreErr != nil {
Expect(succeeded).To(Equal(false))
Expect(err.Error()).To(ContainSubstring(brCase.RestoreErr.Error()))
} else {
Expect(err).ToNot(HaveOccurred())
Expect(succeeded).To(Equal(true))
}

if nsRequiresResticDCWorkaround {
// We run the dc-post-restore.sh script for both restic and
// kopia backups and for any DCs with attached volumes,
// regardless of whether it was restic or kopia backup.
// The script is designed to work with labels set by the
// openshift-velero-plugin and can be run without pre-conditions.
log.Printf("Running dc-post-restore.sh script.")
err = lib.RunDcPostRestoreScript(restoreName)
Expect(err).ToNot(HaveOccurred())
}
}

0 comments on commit 2a81385

Please sign in to comment.