Skip to content

Commit

Permalink
Pod Traffic Across AZ Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
orsenthil committed Nov 22, 2023
1 parent 628ac23 commit 38a1fc7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/integration/cni/pod_traffic_across_az_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var _ = Describe("[STATIC_AZ] test pod networking", func() {
// tester pod to receiver pod
testConnectionCommandFunc func(serverPod coreV1.Pod, port int) []string

// The functions re-inforces that the positive test is working as
// expected by creating a negative test command that should fail
testFailedConnectionCommandFunc func(serverPod coreV1.Pod, port int) []string

// Expected stdout from the exec command on testing connection
// from tester to server
testerExpectedStdOut string
Expand Down Expand Up @@ -148,6 +152,12 @@ var _ = Describe("[STATIC_AZ] test pod networking", func() {
return []string{"ping", "-c", strconv.Itoa(packetCount), receiverPod.Status.PodIP}
}

// Create a negative test case with the wrong port number. This is to reinforce the
// positive test case work by verifying negative cases do throw error
testFailedConnectionCommandFunc = func(receiverPod coreV1.Pod, port int) []string {
return []string{"nc", "-u", "-v", "-w2", receiverPod.Status.PodIP, strconv.Itoa(port + 1)}
}

})

It("should allow ICMP traffic", func() {
Expand Down Expand Up @@ -182,6 +192,9 @@ var _ = Describe("[STATIC_AZ] test pod networking", func() {
It("connection should be established", func() {
fmt.Println("Test UDP Traffic for Daemonset.")
CheckConnectivityBetweenPods(azToPod, serverPort, testerExpectedStdOut, testerExpectedStdErr, testConnectionCommandFunc)

By("verifying connection fails for unreachable port")
VerifyConnectivityForNegativeCase(azToPod, serverPort, testFailedConnectionCommandFunc)
})
})

Expand Down Expand Up @@ -209,6 +222,7 @@ var _ = Describe("[STATIC_AZ] test pod networking", func() {

It("should allow connection across nodes and across interface types", func() {
CheckConnectivityBetweenPods(azToPod, serverPort, testerExpectedStdOut, testerExpectedStdErr, testConnectionCommandFunc)
VerifyConnectivityForNegativeCase(azToPod, serverPort, testFailedConnectionCommandFunc)
})
})

Expand All @@ -228,3 +242,31 @@ func CheckConnectivityBetweenPods(azToPod map[string]coreV1.Pod, port int, teste
}
}
}

func VerifyConnectivityForNegativeCase(azToPod map[string]coreV1.Pod, port int,
getTestCommandFunc func(receiverPod coreV1.Pod, port int) []string) {

for az1 := range azToPod {
for az2 := range azToPod {
if az1 != az2 {
fmt.Printf("Testing Connectivity from Pod IP1 %s (%s) to Pod IP2 %s (%s) \n",
azToPod[az1].Status.PodIP, az1, azToPod[az2].Status.PodIP, az2)

senderPod := azToPod[az1]
receiverPod := azToPod[az2]
testerCommand := getTestCommandFunc(receiverPod, port)

fmt.Fprintf(GinkgoWriter, "verifying connectivity fails from pod %s on node %s with IP %s to pod"+
" %s on node %s with IP %s\n", senderPod.Name, senderPod.Spec.NodeName, senderPod.Status.PodIP,
receiverPod.Name, receiverPod.Spec.NodeName, receiverPod.Status.PodIP)

_, _, err := f.K8sResourceManagers.PodManager().
PodExec(senderPod.Namespace, senderPod.Name, testerCommand)
Expect(err).To(HaveOccurred())
// single test is fine!
break
}
}
}

}

0 comments on commit 38a1fc7

Please sign in to comment.