Skip to content

Commit

Permalink
[WIP] Multicluster E2E Test Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Enhao Cui committed Feb 8, 2022
1 parent e23cf3b commit f85ecdb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
12 changes: 12 additions & 0 deletions multicluster/test/e2e/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ func setupTest(tb testing.TB) (*TestData, error) {
return nil, err
}

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, 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)

success = true
return testData, nil
}
Expand All @@ -63,6 +73,8 @@ func teardownTest(tb testing.TB, data *TestData) {
if empty, _ := IsDirEmpty(data.logsDirForTestCase); empty {
_ = os.Remove(data.logsDirForTestCase)
}
deletePodWrapper(t, data, westCluster, multiClusterTestNamespace, nginxPodName)
deletePodWrapper(t, data, eastCluster, multiClusterTestNamespace, nginxPodName)
}

func createPodWrapper(tb testing.TB, data *TestData, cluster string, namespace string, name string, image string, ctr string, command []string,
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
59 changes: 26 additions & 33 deletions multicluster/test/e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,39 @@ 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 {
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 {
t.Fatalf("Error when creating nginx Pod in east cluster: %v", err)
}
defer deletePodWrapper(t, data, eastCluster, multiClusterTestNamespace, podName)

func (data *TestData) setupTestServices(t *testing.T) {
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) tearDownTestServices(t *testing.T) {
deleteServiceWrapper(t, testData, westCluster, multiClusterTestNamespace, westClusterTestService)
deleteServiceWrapper(t, testData, eastCluster, multiClusterTestNamespace, eastClusterTestService)
}

func (data *TestData) getAndProberFromCluster(t *testing.T, clusterName string){
svc, err := data.getService(clusterName, 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)
}

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.setupTestServices(t)

if err := data.deployServiceExport(westCluster); err != nil {
t.Fatalf("Error when deploy ServiceExport in west cluster: %v", err)
Expand All @@ -84,23 +91,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.getAndProberFromCluster(t, eastCluster)
data.getAndProberFromCluster(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 Expand Up @@ -133,6 +125,7 @@ func (data *TestData) testServiceExport(t *testing.T) {
} else if connectivity != antreae2e.Dropped {
t.Errorf("Failure -- wrong result from probing exported Service after applying toService AntreaNetworkPolicy. Expected: %v, Actual: %v", antreae2e.Dropped, connectivity)
}
data.tearDownTestServices(t)
}

func (data *TestData) deployServiceExport(clusterName string) error {
Expand Down

0 comments on commit f85ecdb

Please sign in to comment.