Skip to content

Commit

Permalink
Multicluster E2E Test Refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Enhao Cui <[email protected]>
  • Loading branch information
Enhao Cui committed Mar 1, 2022
1 parent e23cf3b commit 924d7e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 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
60 changes: 32 additions & 28 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) probeMCServiceFromCluster(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,30 +103,15 @@ 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.probeMCServiceFromCluster(t, westCluster)
data.probeMCServiceFromCluster(t, eastCluster)

if err := data.createPod(eastCluster, clientPodName, multiClusterTestNamespace, "client", agnhostImage,
[]string{"sleep", strconv.Itoa(3600)}, nil, nil, nil, false, nil); err != nil {
t.Fatalf("Error when creating client Pod in east cluster: %v", err)
}
defer deletePodWrapper(t, data, eastCluster, multiClusterTestNamespace, clientPodName)
_, err = data.podWaitFor(defaultTimeout, eastCluster, clientPodName, multiClusterTestNamespace, func(pod *corev1.Pod) (bool, error) {
_, err := data.podWaitFor(defaultTimeout, eastCluster, clientPodName, multiClusterTestNamespace, func(pod *corev1.Pod) (bool, error) {
return pod.Status.Phase == corev1.PodRunning, nil
})
if err != nil {
Expand Down

0 comments on commit 924d7e8

Please sign in to comment.