Skip to content

Commit

Permalink
test/e2e: check ReadyToUse before checking it remains
Browse files Browse the repository at this point in the history
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
  • Loading branch information
ushitora-anqou committed Jul 11, 2024
1 parent 4d07d80 commit 6776079
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
25 changes: 15 additions & 10 deletions test/e2e/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import (
"github.com/cybozu-go/mantle/test/util"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
)

const (
Expand Down Expand Up @@ -154,6 +151,18 @@ func (test *backupTest) testCase1() {

return checkSnapshotExist(cephCluster1Namespace, test.poolName, imageName, test.mantleBackupName3)
}).Should(Succeed())

By("Checking that the status.conditions of the MantleBackup resource becomes \"ReadyToUse\"")
Eventually(func() error {
ready, err := isMantleBackupReady(test.tenantNamespace, test.mantleBackupName3)
if err != nil {
return err
}
if !ready {
return fmt.Errorf("not ready")
}
return nil
}).Should(Succeed())
})

It("should not delete MantleBackup resource when delete backup target PVC", func() {
Expand All @@ -173,14 +182,10 @@ func (test *backupTest) testCase1() {
return fmt.Errorf("PVC %s still exists. stdout: %s", test.pvcName2, stdout)
}).Should(Succeed())

By("Checking that the status.conditions of the MantleBackup resource remain \"Bound\"")
stdout, _, err := kubectl("-n", test.tenantNamespace, "get", "mantlebackup", test.mantleBackupName3, "-o", "json")
Expect(err).NotTo(HaveOccurred())
var backup mantlev1.MantleBackup
err = yaml.Unmarshal(stdout, &backup)
By("Checking that the status.conditions of the MantleBackup resource remain \"ReadyToUse\"")
ready, err := isMantleBackupReady(test.tenantNamespace, test.mantleBackupName3)
Expect(err).NotTo(HaveOccurred())
Expect(meta.FindStatusCondition(backup.Status.Conditions, mantlev1.BackupConditionReadyToUse).Status).
To(Equal(metav1.ConditionTrue))
Expect(ready).To(Equal(true))
})

It("should delete MantleBackup resource", func() {
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
mantlev1 "github.com/cybozu-go/mantle/api/v1"
"github.com/cybozu-go/mantle/internal/controller"
testutil "github.com/cybozu-go/mantle/test/util"
"gopkg.in/yaml.v2"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -401,6 +402,20 @@ func getRBDInfo(clusterNS, pool, image string) (*rbdInfo, error) {
return &info, nil
}

func isMantleBackupReady(namespace, name string) (bool, error) {
stdout, _, err := kubectl("-n", namespace, "get", "mantlebackup", name, "-o", "json")
if err != nil {
return false, err
}
var backup mantlev1.MantleBackup
err = yaml.Unmarshal(stdout, &backup)
if err != nil {
return false, err
}
cond := meta.FindStatusCondition(backup.Status.Conditions, mantlev1.BackupConditionReadyToUse).Status
return cond == metav1.ConditionTrue, nil
}

func isMantleRestoreReady(namespace, name string) bool {
stdout, stderr, err := kubectl("get", "mantlerestore", "-n", namespace, name, "-o", "json")
if err != nil {
Expand Down

0 comments on commit 6776079

Please sign in to comment.