Skip to content

Commit

Permalink
[WIP] Multicluster E2E Test Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Enhao Cui <[email protected]>
  • Loading branch information
Enhao Cui committed Feb 22, 2022
1 parent e23cf3b commit 39f6219
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
1 change: 0 additions & 1 deletion multicluster/test/e2e/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func setupTest(tb testing.TB) (*TestData, error) {
if err := testData.createTestNamespace(); err != nil {
return nil, err
}

success = true
return testData, nil
}
Expand Down
1 change: 1 addition & 0 deletions multicluster/test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (

nginxImage = "nginx:latest"
agnhostImage = "agnhost:2.26"
nginxPodName = "test-nginx-pod"
)

var provider providers.ProviderInterface
Expand Down
58 changes: 31 additions & 27 deletions multicluster/test/e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,51 @@ func testServiceExport(t *testing.T, data *TestData) {
// we create a nginx in on cluster(east), and try to curl it in another cluster(west).
// If we got status code 200, it means that the resources is exported by the east cluster
// and imported by the west cluster.
// TODO(yang): reorg test function contents
func (data *TestData) testServiceExport(t *testing.T) {
podName := randName("test-nginx-")
clientPodName := "test-service-client"

if err := createPodWrapper(t, data, westCluster, multiClusterTestNamespace, podName, nginxImage, "nginx", nil, nil, nil, nil, false, nil); err != nil {
func (data *TestData) setupTestResources(t *testing.T) {

if err := createPodWrapper(t, data, westCluster, multiClusterTestNamespace, nginxPodName, nginxImage, "nginx", nil, nil, nil, nil, false, nil); err != nil {
t.Fatalf("Error when creating nginx Pod in west cluster: %v", err)
}
defer deletePodWrapper(t, data, westCluster, multiClusterTestNamespace, podName)

if err := createPodWrapper(t, data, eastCluster, multiClusterTestNamespace, podName, nginxImage, "nginx", nil, nil, nil, nil, false, nil); err != nil {
if err := createPodWrapper(t, data, eastCluster, multiClusterTestNamespace, nginxPodName, nginxImage, "nginx", nil, nil, nil, nil, false, nil); err != nil {
t.Fatalf("Error when creating nginx Pod in east cluster: %v", err)
}
defer deletePodWrapper(t, data, eastCluster, multiClusterTestNamespace, podName)

if _, err := data.createService(westCluster, westClusterTestService, multiClusterTestNamespace, 80, 80, corev1.ProtocolTCP, map[string]string{"app": "nginx"}, false,
false, corev1.ServiceTypeClusterIP, nil, nil); err != nil {
t.Fatalf("Error when creating Servie %s in west cluster: %v", westClusterTestService, err)
}
defer deleteServiceWrapper(t, testData, westCluster, multiClusterTestNamespace, westClusterTestService)

if _, err := data.createService(eastCluster, eastClusterTestService, multiClusterTestNamespace, 80, 80, corev1.ProtocolTCP, map[string]string{"app": "nginx"}, false,
false, corev1.ServiceTypeClusterIP, nil, nil); err != nil {
t.Fatalf("Error when creating Servie %s in east cluster: %v", eastClusterTestService, err)
}
defer deleteServiceWrapper(t, testData, eastCluster, multiClusterTestNamespace, eastClusterTestService)
}

func (data *TestData) tearDownTestResources(t *testing.T) {
deleteServiceWrapper(t, testData, westCluster, multiClusterTestNamespace, westClusterTestService)
deleteServiceWrapper(t, testData, eastCluster, multiClusterTestNamespace, eastClusterTestService)
deletePodWrapper(t, data, westCluster, multiClusterTestNamespace, nginxPodName)
deletePodWrapper(t, data, eastCluster, multiClusterTestNamespace, nginxPodName)
}

func (data *TestData) getAndProbeFromCluster(t *testing.T, clusterName string){
svc, err := data.getService(clusterName, multiClusterTestNamespace, fmt.Sprintf("antrea-mc-%s", clusterName))
if err != nil {
t.Fatalf("Error when getting the imported service %s: %v", fmt.Sprintf("antrea-mc-%s", clusterName), err)
}

ip := svc.Spec.ClusterIP
if err := data.probeFromCluster(clusterName, ip); err != nil {
t.Fatalf("Error when probe service from %s", clusterName)
}
}

func (data *TestData) testServiceExport(t *testing.T) {
clientPodName := "test-service-client"
data.setupTestResources(t)
defer data.tearDownTestResources(t)

if err := data.deployServiceExport(westCluster); err != nil {
t.Fatalf("Error when deploy ServiceExport in west cluster: %v", err)
Expand All @@ -84,23 +103,8 @@ func (data *TestData) testServiceExport(t *testing.T) {
defer data.deleteServiceExport(eastCluster)
time.Sleep(importServiceDelay)

svc, err := data.getService(eastCluster, multiClusterTestNamespace, fmt.Sprintf("antrea-mc-%s", westClusterTestService))
if err != nil {
t.Fatalf("Error when getting the imported service %s: %v", fmt.Sprintf("antrea-mc-%s", westClusterTestService), err)
}

eastIP := svc.Spec.ClusterIP
if err := data.probeFromCluster(eastCluster, eastIP); err != nil {
t.Fatalf("Error when probe service from %s", eastCluster)
}
svc, err = data.getService(westCluster, multiClusterTestNamespace, fmt.Sprintf("antrea-mc-%s", eastClusterTestService))
if err != nil {
t.Fatalf("Error when getting the imported service %s: %v", fmt.Sprintf("antrea-mc-%s", eastClusterTestService), err)
}
westIP := svc.Spec.ClusterIP
if err := data.probeFromCluster(westCluster, westIP); err != nil {
t.Fatalf("Error when probe service from %s", westCluster)
}
data.getAndProbeFromCluster(t, eastCluster)
data.getAndProbeFromCluster(t, westCluster)

if err := data.createPod(eastCluster, clientPodName, multiClusterTestNamespace, "client", agnhostImage,
[]string{"sleep", strconv.Itoa(3600)}, nil, nil, nil, false, nil); err != nil {
Expand Down

0 comments on commit 39f6219

Please sign in to comment.