Skip to content

Commit

Permalink
Add pause/unpause schedule e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: danfengl <danfengl@vmware.com>
  • Loading branch information
danfengliu committed Nov 21, 2022
1 parent 1ea1d4d commit 7ce0aca
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
5 changes: 2 additions & 3 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ import (
. "github.com/vmware-tanzu/velero/test/e2e/basic"
. "github.com/vmware-tanzu/velero/test/e2e/basic/resources-check"
. "github.com/vmware-tanzu/velero/test/e2e/bsl-mgmt"
. "github.com/vmware-tanzu/velero/test/e2e/migration"
. "github.com/vmware-tanzu/velero/test/e2e/orderedresources"
. "github.com/vmware-tanzu/velero/test/e2e/privilegesmgmt"
. "github.com/vmware-tanzu/velero/test/e2e/pv-backup"
. "github.com/vmware-tanzu/velero/test/e2e/resource-filtering"

. "github.com/vmware-tanzu/velero/test/e2e/scale"
. "github.com/vmware-tanzu/velero/test/e2e/schedule"
. "github.com/vmware-tanzu/velero/test/e2e/upgrade"

. "github.com/vmware-tanzu/velero/test/e2e/migration"
. "github.com/vmware-tanzu/velero/test/e2e/util/k8s"
)

Expand Down
32 changes: 29 additions & 3 deletions test/e2e/backups/schedule.go → test/e2e/schedule/schedule.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backups
package schedule

import (
"context"
Expand Down Expand Up @@ -29,7 +29,7 @@ var ScheduleBackupTest func() = TestFunc(&ScheduleBackup{TestCase: TestCase{NSBa

func (n *ScheduleBackup) Init() error {
n.Client = TestClientInstance
n.Period = 3
n.Period = 3 // Unit is minute
n.verifyTimes = 5 // More verify times more confidence
n.TestMsg = &TestMSG{
Desc: "Set up a scheduled backup defined by a Cron expression",
Expand All @@ -48,7 +48,7 @@ func (n *ScheduleBackup) StartRun() error {
"--include-namespaces", strings.Join(*n.NSIncluded, ","),
"--schedule=*/" + fmt.Sprintf("%v", n.Period) + " * * * *",
}

Expect(n.Period < 30).To(Equal(true))
return nil
}
func (n *ScheduleBackup) CreateResources() error {
Expand Down Expand Up @@ -152,6 +152,32 @@ func (n *ScheduleBackup) Destroy() error {
"--wait",
}

backupsInfo, err := GetScheduledBackupsCreationTime(context.Background(), VeleroCfg.VeleroCLI, "default", n.ScheduleName)
Expect(err).To(Succeed())
backupCount := len(backupsInfo)
//VeleroSchedulePause
By(fmt.Sprintf("Pause schedule %s ......\n", n.ScheduleName), func() {
Expect(VeleroSchedulePause(n.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, n.ScheduleName, n.ScheduleArgs)).To(Succeed(), func() string {
RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, "", "")
return "Fail to restore workload"
})
})

time.Sleep(time.Duration(n.Period*3) * time.Minute)
backupsInfo, err = GetScheduledBackupsCreationTime(context.Background(), VeleroCfg.VeleroCLI, "default", n.ScheduleName)
Expect(err).To(Succeed())

backupCountPostPause := len(backupsInfo)

Expect(backupCountPostPause == backupCount).To(Equal(true))

By(fmt.Sprintf("Pause schedule %s ......\n", n.ScheduleName), func() {
Expect(VeleroSchedulePause(n.Ctx, VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, n.ScheduleName, n.ScheduleArgs)).To(Succeed(), func() string {
RunDebug(context.Background(), VeleroCfg.VeleroCLI, VeleroCfg.VeleroNamespace, "", "")
return "Fail to restore workload"
})
})

return nil
}

Expand Down
38 changes: 38 additions & 0 deletions test/e2e/util/velero/velero_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,24 @@ func checkSchedulePhase(ctx context.Context, veleroCLI, veleroNamespace, schedul
})
}

func checkSchedulePause(ctx context.Context, veleroCLI, veleroNamespace, scheduleName string, pause bool) error {
checkCMD := exec.CommandContext(ctx, veleroCLI, "--namespace", veleroNamespace, "schedule", "get", scheduleName, "-ojson")
jsonBuf, err := CMDExecWithOutput(checkCMD)
if err != nil {
return err
}
schedule := velerov1api.Schedule{}
err = json.Unmarshal(*jsonBuf, &schedule)
if err != nil {
return err
}

if schedule.Spec.Paused != pause {
fmt.Printf("Unexpected schedule phase got %s, expecting %s, still waiting...", schedule.Status.Phase, velerov1api.SchedulePhaseEnabled)
return nil
}
return nil
}
func CheckScheduleWithResourceOrder(ctx context.Context, veleroCLI, veleroNamespace, scheduleName string, order map[string]string) error {
checkCMD := exec.CommandContext(ctx, veleroCLI, "--namespace", veleroNamespace, "schedule", "get", scheduleName, "-ojson")
jsonBuf, err := CMDExecWithOutput(checkCMD)
Expand Down Expand Up @@ -442,6 +460,26 @@ func VeleroScheduleCreate(ctx context.Context, veleroCLI string, veleroNamespace
return checkSchedulePhase(ctx, veleroCLI, veleroNamespace, scheduleName)
}

func VeleroSchedulePause(ctx context.Context, veleroCLI string, veleroNamespace string, scheduleName string, args []string) error {
args = append([]string{
"--namespace", veleroNamespace, "schedule", "pause", scheduleName,
}, args...)
if err := VeleroCmdExec(ctx, veleroCLI, args); err != nil {
return err
}
return checkSchedulePause(ctx, veleroCLI, veleroNamespace, scheduleName, true)
}

func VeleroScheduleUnpause(ctx context.Context, veleroCLI string, veleroNamespace string, scheduleName string, args []string) error {
args = append([]string{
"--namespace", veleroNamespace, "schedule", "unpause", scheduleName,
}, args...)
if err := VeleroCmdExec(ctx, veleroCLI, args); err != nil {
return err
}
return checkSchedulePause(ctx, veleroCLI, veleroNamespace, scheduleName, false)
}

func VeleroCmdExec(ctx context.Context, veleroCLI string, args []string) error {
cmd := exec.CommandContext(ctx, veleroCLI, args...)
cmd.Stdout = os.Stdout
Expand Down

0 comments on commit 7ce0aca

Please sign in to comment.