Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 3 additions & 1 deletion tests/e2e/backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var _ = Describe("AWS backup restore tests", func() {

parksAppReady := VerificationFunction(func(ocClient client.Client, namespace string) error {
Eventually(IsDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
// err := VerifyBackUpRestoreData(artifact_dir, namespace, "restify", "parks-app") // TODO: VERIFY PARKS APP DATA
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks... looking at the parks app.. the last commit was in 2016. I'm a little suspicious of this app. https://github.com/ryanj/restify-mongodb-parks

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 added the issue in the description although we could verify the data if we add a wait function.

return nil
})
mysqlReady := VerificationFunction(func(ocClient client.Client, namespace string) error {
Expand All @@ -60,7 +61,8 @@ var _ = Describe("AWS backup restore tests", func() {
if !exists {
return errors.New("did not find MYSQL scc")
}
return nil
err = VerifyBackUpRestoreData(artifact_dir, namespace, "todolist-route", "todolist")
return err
})

DescribeTable("backup and restore applications",
Expand Down
57 changes: 57 additions & 0 deletions tests/e2e/lib/apps.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package lib

import (
"bytes"
"context"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"

"github.com/onsi/ginkgo/v2"
ocpappsv1 "github.com/openshift/api/apps/v1"
routev1 "github.com/openshift/api/route/v1"
security "github.com/openshift/api/security/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -18,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

func InstallApplication(ocClient client.Client, file string) error {
Expand Down Expand Up @@ -197,3 +203,54 @@ func RunMustGather(oc_cli string, artifact_dir string) error {
_, err := cmd.Output()
return err
}

func VerifyBackUpRestoreData(artifact_dir string, namespace string, routeName string, app string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func VerifyBackUpRestoreData(artifact_dir string, namespace string, routeName string, app string) error {
func VerifyBackupRestoreData(artifact_dir string, namespace string, routeName string, app string) error {

log.Printf("Verifying backup/restore data of %s", app)
appRoute := &routev1.Route{}
clientv1, err := client.New(config.GetConfigOrDie(), client.Options{})
if err != nil {
return err
}
backupFile := artifact_dir + "/backup-data.txt"
routev1.AddToScheme(clientv1.Scheme())
err = clientv1.Get(context.Background(), client.ObjectKey{
Namespace: namespace,
Name: routeName,
}, appRoute)
if err != nil {
return err
}
appApi := "http://" + appRoute.Spec.Host
switch app {
case "todolist":
appApi += "/todo-completed"
case "parks-app":
appApi += "/parks"
}
resp, err := http.Get(appApi)
if err != nil {
return err
}
defer resp.Body.Close()

respData, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
if _, err := os.Stat(backupFile); err == nil {
backupData, err := os.ReadFile(backupFile)
if err != nil {
return err
}
os.Remove(backupFile)
if bytes.Compare(backupData, respData) != 0 {
return errors.New("Backup and Restore Data are not the same")
}
} else if errors.Is(err, os.ErrNotExist) {
err := os.WriteFile(backupFile, respData, 0644)
if err != nil {
return err
}
}
return nil
}