diff --git a/tests/integration/etcdsnapshot/etcd_int_test.go b/tests/integration/etcdsnapshot/etcd_int_test.go index fc6e8a74c55..79160a287b1 100644 --- a/tests/integration/etcdsnapshot/etcd_int_test.go +++ b/tests/integration/etcdsnapshot/etcd_int_test.go @@ -1,6 +1,7 @@ package tests import ( + "fmt" "os" "regexp" "testing" @@ -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{""} @@ -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")). @@ -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() { @@ -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() { @@ -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`) @@ -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()) }) }) })