Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete the existing backuprepositories prior to a new test #1521

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/e2e/backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func runApplicationBackupAndRestore(brCase ApplicationBackupRestoreCase, expecte
// create DPA
backupName, restoreName := prepareBackupAndRestore(brCase.BackupRestoreCase, updateLastInstallTime)

// Ensure that an existing backup repository is deleted
weshayutin marked this conversation as resolved.
Show resolved Hide resolved
brerr := lib.DeleteBackupRepositories(runTimeClientForSuiteRun, namespace)
gomega.Expect(brerr).ToNot(gomega.HaveOccurred())

// install app
updateLastInstallTime()
log.Printf("Installing application for case %s", brCase.Name)
Expand Down
55 changes: 55 additions & 0 deletions tests/e2e/lib/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,58 @@ func BackupErrorLogs(c *kubernetes.Clientset, ocClient client.Client, namespace
bl := BackupLogs(c, ocClient, namespace, name)
return errorLogsExcludingIgnored(bl)
}

func GetBackupRepositoryList(c client.Client, namespace string) (*velero.BackupRepositoryList, error) {
// initialize an empty list of BackupRepositories
backupRepositoryList := &velero.BackupRepositoryList{
Items: []velero.BackupRepository{},
}
// get the list of BackupRepositories in the given namespace
err := c.List(context.Background(), backupRepositoryList, client.InNamespace(namespace))
if err != nil {
log.Printf("error getting BackupRepository list: %v", err)
return nil, err
}
return backupRepositoryList, nil
}

func DeleteBackupRepository(c client.Client, namespace string, name string) error {
backupRepository := &velero.BackupRepository{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
}
err := c.Delete(context.Background(), backupRepository)
if err != nil {
return err
}
return nil
}

// DeleteBackupRepositories deletes all BackupRepositories in the given namespace.
func DeleteBackupRepositories(c client.Client, namespace string) error {
log.Printf("Checking if backuprepository's exist in %s", namespace)
weshayutin marked this conversation as resolved.
Show resolved Hide resolved

backupRepos, err := GetBackupRepositoryList(c, namespace)
if err != nil {
return fmt.Errorf("failed to get BackupRepository list: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would check if error was not found error, and it is, return nil (there are no BackupRepositories in this namespace, nothing to delete), also keeping generic error handling as it is now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, fixing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will break tests, first run will always fail, because there is no prior backupRepo, and and error will be returned

need to check if the error is not found error here for cases where there is no prior backupRepo,no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same worry as you are expressing.

on line 150 I have
backupRepositoryList := &velero.BackupRepositoryList{
Items: []velero.BackupRepository{},

which should initialize the list w/ 0 items.
Unless I'm misunderstanding something, GetBackupRepositoryList should at minimum return an empty list or a populated list.

}
if len(backupRepos.Items) == 0 {
log.Printf("No BackupRepositories found in namespace %s", namespace)
return nil
}

// Get a list of the BackupRepositories and delete all of them.
for _, repo := range backupRepos.Items {
log.Printf("backuprepository name is %s", repo.Name)
err := DeleteBackupRepository(c, namespace, repo.Name)
if err != nil {
log.Printf("failed to delete BackupRepository %s: ", repo.Name)
return err
}
log.Printf("Successfully deleted BackupRepository: %s", repo.Name)
}

return nil
}
2 changes: 2 additions & 0 deletions tests/e2e/virt_backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ var _ = ginkgo.Describe("VM backup and restore tests", ginkgo.Ordered, func() {
gomega.Expect(err).To(gomega.BeNil())
err = v.CreateWaitForFirstConsumerStorageClass("test-sc-wffc")
gomega.Expect(err).To(gomega.BeNil())
err = lib.DeleteBackupRepositories(runTimeClientForSuiteRun, namespace)
gomega.Expect(err).To(gomega.BeNil())
weshayutin marked this conversation as resolved.
Show resolved Hide resolved
})

var _ = ginkgo.AfterAll(func() {
Expand Down