Skip to content

Commit

Permalink
test/e2e: multik8s: correct MB sync when primary -> standalone -> pri…
Browse files Browse the repository at this point in the history
…mary role change

Signed-off-by: Ryotaro Banno <[email protected]>
  • Loading branch information
ushitora-anqou committed Dec 25, 2024
1 parent 7eedfcd commit 2c47e47
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
78 changes: 78 additions & 0 deletions test/e2e/multik8s/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var _ = Describe("Mantle", func() {
Context("wait controller to be ready", waitControllerToBeReady)
Context("replication test", replicationTestSuite)
Context("change to standalone", changeToStandalone)
Context("change to primary", changeToPrimary)
})

func waitControllerToBeReady() {
Expand Down Expand Up @@ -551,5 +552,82 @@ func changeToStandalone() {
g.Expect(found).To(BeTrue())
}, "10s", "1s").Should(Succeed())
})

It("should change their roles back to primary/secondary", func() {
By("changing the primary K8s cluster to standalone")
err := changeClusterRole(primaryK8sCluster, rolePrimary)
Expect(err).NotTo(HaveOccurred())
By("changing the secondary K8s cluster to standalone")
err = changeClusterRole(secondaryK8sCluster, roleSecondary)
Expect(err).NotTo(HaveOccurred())
})
})
}

func changeToPrimary() {
Describe("change to primary", func() {
var (
namespace string
pvcName0, backupName00, backupName01, writtenDataHash00, writtenDataHash01 string
pvcName1, backupName10, writtenDataHash10 string
)

It("should replicate a MantleBackup resource", func(ctx context.Context) {
namespace = util.GetUniqueName("ns-")
pvcName0 = util.GetUniqueName("pvc-")
backupName00 = util.GetUniqueName("mb-")

setupEnvironment(namespace, pvcName0)
writtenDataHash00 = writeRandomDataToPV(ctx, namespace, pvcName0)
createMantleBackup(namespace, pvcName0, backupName00)
waitMantleBackupSynced(namespace, backupName00)
})

It("should change the role from primary to standalone", func() {
By("changing the primary K8s cluster to standalone")
err := changeClusterRole(primaryK8sCluster, roleStandalone)
Expect(err).NotTo(HaveOccurred())
})

It("should create a MantleBackup resource", func(ctx SpecContext) {
backupName01 = util.GetUniqueName("mb-")
writtenDataHash01 = writeRandomDataToPV(ctx, namespace, pvcName0)

createMantleBackup(namespace, pvcName0, backupName01)

pvcName1 = util.GetUniqueName("pvc-")
backupName10 = util.GetUniqueName("mb-")

Eventually(func() error {
return applyPVCTemplate(primaryK8sCluster, namespace, pvcName1)
}).Should(Succeed())
writtenDataHash10 = writeRandomDataToPV(ctx, namespace, pvcName1)
createMantleBackup(namespace, pvcName1, backupName10)
})

It("should change the role from standalone to primary", func() {
By("changing the primary K8s cluster to primary")
err := changeClusterRole(primaryK8sCluster, rolePrimary)
Expect(err).NotTo(HaveOccurred())
})

It("should synchronize MantleBackups correctly", func() {
waitMantleBackupSynced(namespace, backupName01)
waitMantleBackupSynced(namespace, backupName10)
})

It("should restore MantleBackups correctly", func(ctx SpecContext) {
restoreName00 := util.GetUniqueName("mr-")
ensureCorrectRestoration(primaryK8sCluster, ctx, namespace, backupName00, restoreName00, writtenDataHash00)
ensureCorrectRestoration(secondaryK8sCluster, ctx, namespace, backupName00, restoreName00, writtenDataHash00)

restoreName01 := util.GetUniqueName("mr-")
ensureCorrectRestoration(primaryK8sCluster, ctx, namespace, backupName01, restoreName01, writtenDataHash01)
ensureCorrectRestoration(secondaryK8sCluster, ctx, namespace, backupName01, restoreName01, writtenDataHash01)

restoreName10 := util.GetUniqueName("mr-")
ensureCorrectRestoration(primaryK8sCluster, ctx, namespace, backupName10, restoreName10, writtenDataHash10)
ensureCorrectRestoration(secondaryK8sCluster, ctx, namespace, backupName10, restoreName10, writtenDataHash10)
})
})
}
2 changes: 2 additions & 0 deletions test/e2e/multik8s/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
primaryK8sCluster = 1
secondaryK8sCluster = 2
roleStandalone = "standalone"
rolePrimary = "primary"
roleSecondary = "secondary"
)

var (
Expand Down

0 comments on commit 2c47e47

Please sign in to comment.