Skip to content

Commit

Permalink
Fix etcd test with new output values
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <derek.nola@suse.com>
  • Loading branch information
dereknola committed Feb 9, 2024
1 parent 5d749b0 commit 1182ac2
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions tests/integration/etcdsnapshot/etcd_int_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"fmt"
"os"
"regexp"
"testing"
Expand All @@ -9,6 +10,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
testutil "github.com/rancher/rke2/tests/integration"
"github.com/sirupsen/logrus"
)

var serverArgs = []string{""}
Expand All @@ -23,14 +25,20 @@ var _ = BeforeSuite(func() {
Expect(err).ToNot(HaveOccurred())
})

var _ = Describe("etcd snapshots", func() {
var _ = Describe("etcd snapshots", Ordered, func() {
When("a new etcd snapshot is created", func() {
It("starts up with no problems", func() {
Eventually(testutil.ServerReady(), "90s", "1s").Should(BeTrue())
Eventually(func() error {
err := testutil.ServerReady()
if err != nil {
logrus.Info(err)
}
return err
}, "240s", "15s").Should(Succeed())
})
It("saves an etcd snapshot", func() {
Expect(testutil.RKE2Cmd("etcd-snapshot", "save")).
To(ContainSubstring("Saving current etcd snapshot set to rke2-etcd-snapshots"))
To(ContainSubstring("Saving etcd snapshot to /var/lib/rancher/rke2/server/db/snapshots/on-demand"))
})
It("list snapshots", func() {
Expect(testutil.RKE2Cmd("etcd-snapshot", "ls")).
Expand All @@ -43,7 +51,7 @@ var _ = Describe("etcd snapshots", func() {
Expect(err).ToNot(HaveOccurred())
snapshotName := reg.FindString(lsResult)
Expect(testutil.RKE2Cmd("etcd-snapshot", "delete", snapshotName)).
To(ContainSubstring("Removing the given locally stored etcd snapshot"))
To(ContainSubstring(fmt.Sprintf("Snapshot %s deleted locally", snapshotName)))
})
})
When("saving a custom name", func() {
Expand All @@ -58,19 +66,19 @@ var _ = Describe("etcd snapshots", func() {
Expect(err).ToNot(HaveOccurred())
snapshotName := reg.FindString(lsResult)
Expect(testutil.RKE2Cmd("etcd-snapshot", "delete", snapshotName)).
To(ContainSubstring("Removing the given locally stored etcd snapshot"))
To(ContainSubstring(fmt.Sprintf("Snapshot %s deleted locally", snapshotName)))
})
})
When("using etcd snapshot prune", func() {
It("saves 3 different snapshots", func() {
Expect(testutil.RKE2Cmd("etcd-snapshot", "save", "--name", "PRUNE_TEST")).
To(ContainSubstring("Saving current etcd snapshot set to rke2-etcd-snapshots"))
To(ContainSubstring("Saving etcd snapshot to /var/lib/rancher/rke2/server/db/snapshots/PRUNE_TEST"))
time.Sleep(1 * time.Second)
Expect(testutil.RKE2Cmd("etcd-snapshot", "save", "--name", "PRUNE_TEST")).
To(ContainSubstring("Saving current etcd snapshot set to rke2-etcd-snapshots"))
To(ContainSubstring("Saving etcd snapshot to /var/lib/rancher/rke2/server/db/snapshots/PRUNE_TEST"))
time.Sleep(1 * time.Second)
Expect(testutil.RKE2Cmd("etcd-snapshot", "save", "--name", "PRUNE_TEST")).
To(ContainSubstring("Saving current etcd snapshot set to rke2-etcd-snapshots"))
To(ContainSubstring("Saving etcd snapshot to /var/lib/rancher/rke2/server/db/snapshots/PRUNE_TEST"))
time.Sleep(1 * time.Second)
})
It("lists all 3 snapshots", func() {
Expand All @@ -83,7 +91,7 @@ var _ = Describe("etcd snapshots", func() {
})
It("prunes snapshots down to 2", func() {
Expect(testutil.RKE2Cmd("etcd-snapshot", "prune", "--snapshot-retention", "2", "--name", "PRUNE_TEST")).
To(BeEmpty())
To(ContainSubstring("Applying snapshot retention=2"))
lsResult, err := testutil.RKE2Cmd("etcd-snapshot", "ls")
Expect(err).ToNot(HaveOccurred())
reg, err := regexp.Compile(`:///var/lib/rancher/rke2/server/db/snapshots/PRUNE_TEST`)
Expand All @@ -92,14 +100,16 @@ var _ = Describe("etcd snapshots", func() {
Expect(sepLines).To(HaveLen(2))
})
It("cleans up remaining snapshots", func() {
lsResult, err := testutil.RKE2Cmd("etcd-snapshot", "ls")
Expect(err).ToNot(HaveOccurred())
reg, err := regexp.Compile(`PRUNE_TEST[^\s]+`)
Expect(err).ToNot(HaveOccurred())
for _, snapshotName := range reg.FindAllString(lsResult, -1) {
Expect(testutil.RKE2Cmd("etcd-snapshot", "delete", snapshotName)).
To(ContainSubstring("Removing the given locally stored etcd snapshot"))
}
Eventually(func(g Gomega) {
lsResult, err := testutil.RKE2Cmd("etcd-snapshot", "ls")
g.Expect(err).ToNot(HaveOccurred())
reg, err := regexp.Compile(`PRUNE_TEST[^\s]+`)
g.Expect(err).ToNot(HaveOccurred())
for _, snapshotName := range reg.FindAllString(lsResult, -1) {
g.Expect(testutil.RKE2Cmd("etcd-snapshot", "delete", snapshotName)).
To(ContainSubstring(fmt.Sprintf("Snapshot %s deleted locally", snapshotName)))
}
}, "20s", "5s").Should(Succeed())
})
})
})
Expand Down

0 comments on commit 1182ac2

Please sign in to comment.