Skip to content

Commit

Permalink
wip: add multik8s Ginkgo test replacing shell script with
Browse files Browse the repository at this point in the history
  • Loading branch information
ushitora-anqou committed Aug 27, 2024
1 parent 337687f commit b4b06ec
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 59 deletions.
16 changes: 10 additions & 6 deletions test/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ test-multiple-k8s-clusters:
$(MAKE) launch-cluster MINIKUBE_PROFILE=$(MINIKUBE_PROFILE_PRIMARY)
$(MAKE) launch-cluster MINIKUBE_PROFILE=$(MINIKUBE_PROFILE_SECONDARY)
$(MINIKUBE) profile $(MINIKUBE_PROFILE_PRIMARY)
env \
MINIKUBE=$(MINIKUBE) \
MINIKUBE_HOME=$(MINIKUBE_HOME) \
MINIKUBE_PROFILE_PRIMARY=$(MINIKUBE_PROFILE_PRIMARY) \
MINIKUBE_PROFILE_SECONDARY=$(MINIKUBE_PROFILE_SECONDARY) \
./test-multiple-k8s-clusters.sh
$(MAKE) do-test-multik8s

.PHONY: clean
clean:
Expand Down Expand Up @@ -166,3 +161,12 @@ do_test: $(GINKGO)
E2ETEST=1 \
KUBECTL=$(KUBECTL) \
$(GINKGO) --fail-fast -v $(GINKGO_FLAGS) singlek8s

.PHONY: do-test-multik8s
do-test-multik8s: $(GINKGO)
env \
PATH=${PATH} \
E2ETEST=1 \
KUBECTL0="$(MINIKUBE) -p $(MINIKUBE_PROFILE_PRIMARY) kubectl -- " \
KUBECTL1="$(MINIKUBE) -p $(MINIKUBE_PROFILE_SECONDARY) kubectl -- " \
$(GINKGO) --fail-fast -v $(GINKGO_FLAGS) multik8s
101 changes: 101 additions & 0 deletions test/e2e/multik8s/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package multik8s

import (
"bytes"
_ "embed"
"fmt"
"os"
"os/exec"
"strings"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestMtest(t *testing.T) {
if os.Getenv("E2ETEST") == "" {
t.Skip("Run under e2e/")
}

RegisterFailHandler(Fail)

SetDefaultEventuallyPollingInterval(time.Second)
SetDefaultEventuallyTimeout(3 * time.Minute)

RunSpecs(t, "rbd backup system test with multiple k8s clusters")
}

var _ = Describe("Mantle", func() {
Context("wait controller to be ready", waitControllerToBeReady)
Context("replication", replicationTestSuite)
})

var (
kubectlPrefix0 = os.Getenv("KUBECTL0")
kubectlPrefix1 = os.Getenv("KUBECTL1")
)

func execAtLocal(cmd string, input []byte, args ...string) ([]byte, []byte, error) {
var stdout, stderr bytes.Buffer
command := exec.Command(cmd, args...)
command.Stdout = &stdout
command.Stderr = &stderr

if len(input) != 0 {
command.Stdin = bytes.NewReader(input)
}

err := command.Run()
return stdout.Bytes(), stderr.Bytes(), err
}

// input can be nil
func kubectl(clusterNo int, input []byte, args ...string) ([]byte, []byte, error) {
kubectlPrefix := ""
switch clusterNo {
case 0:
kubectlPrefix = kubectlPrefix0
case 1:
kubectlPrefix = kubectlPrefix1
default:
panic(fmt.Sprintf("invalid clusterNo: %d", clusterNo))
}
if len(kubectlPrefix) == 0 {
panic("Either KUBECTL0 or KUBECTL1 environment variable is not set")
}
fields := strings.Fields(kubectlPrefix)
fields = append(fields, args...)
return execAtLocal(fields[0], input, fields[1:]...)
}

func checkDeploymentReady(clusterNo int, namespace, name string) error {
_, stderr, err := kubectl(
clusterNo, nil,
"-n", namespace, "wait", "--for=condition=Available", "deploy", name, "--timeout=1m",
)
if err != nil {
return fmt.Errorf("kubectl wait deploy failed. stderr: %s, err: %w", string(stderr), err)
}
return nil
}

func waitControllerToBeReady() {
It("wait for mantle-controller to be ready", func() {
Eventually(func() error {
return checkDeploymentReady(0, "rook-ceph", "mantle-controller")
}).Should(Succeed())

Eventually(func() error {
return checkDeploymentReady(0, "rook-ceph", "mantle-controller")
}).Should(Succeed())
})
}

func replicationTestSuite() {
Describe("make sure SyncToRemote becomes true after a MantleBackup is created", func() {
// FIXME
return

Check failure on line 99 in test/e2e/multik8s/suite_test.go

View workflow job for this annotation

GitHub Actions / build

S1023: redundant `return` statement (gosimple)
})
}
53 changes: 0 additions & 53 deletions test/e2e/test-multiple-k8s-clusters.sh

This file was deleted.

0 comments on commit b4b06ec

Please sign in to comment.