Commit f150874e authored by Vy Ta's avatar Vy Ta

Requested changes and refactor

parent 2869c670
...@@ -30,9 +30,8 @@ import ( ...@@ -30,9 +30,8 @@ import (
) )
const ( const (
LinuxOS = "linux" linuxOS = "linux"
WindowsOS = "windows" windowsOS = "windows"
Iterations = 5
) )
var ( var (
...@@ -49,66 +48,55 @@ var _ = SIGDescribe("Hybrid cluster network", func() { ...@@ -49,66 +48,55 @@ var _ = SIGDescribe("Hybrid cluster network", func() {
Context("for all supported CNIs", func() { Context("for all supported CNIs", func() {
It("should have stable networking for linux and windows pods", func() { It("should have stable networking for Linux and Windows pods", func() {
By("creating linux and windows pods") By("creating linux and windows pods")
linuxPod := CreateTestPod(f, linuxBusyBoxImage, LinuxOS) linuxPod := createTestPod(f, linuxBusyBoxImage, linuxOS)
windowsPod := CreateTestPod(f, windowsBusyBoximage, WindowsOS) windowsPod := createTestPod(f, windowsBusyBoximage, windowsOS)
By("checking connectivity to 8.8.8.8 53 (google.com) from linux") By("checking connectivity to 8.8.8.8 53 (google.com) from Linux")
CheckLinuxConnectivity(f, linuxPod.ObjectMeta.Name, "8.8.8.8", "53") assertConsistentConnectivity(f, linuxPod.ObjectMeta.Name, linuxOS, linuxCheck("8.8.8.8", 53))
By("checkin connectivity to www.google.com from windows") By("checking connectivity to www.google.com from Windows")
CheckWindowsConnectivity(f, windowsPod.ObjectMeta.Name, "www.google.com") assertConsistentConnectivity(f, windowsPod.ObjectMeta.Name, windowsOS, windowsCheck("www.google.com"))
By("checking connectivity from linux to windows") By("checking connectivity from Linux to Windows")
CheckLinuxConnectivity(f, linuxPod.ObjectMeta.Name, windowsPod.Status.PodIP, "80") assertConsistentConnectivity(f, linuxPod.ObjectMeta.Name, linuxOS, linuxCheck(windowsPod.Status.PodIP, 80))
By("checking connectivity from windows to linux") By("checking connectivity from Windows to Linux")
CheckWindowsConnectivity(f, windowsPod.ObjectMeta.Name, linuxPod.Status.PodIP) assertConsistentConnectivity(f, windowsPod.ObjectMeta.Name, windowsOS, windowsCheck(linuxPod.Status.PodIP))
}) })
}) })
}) })
func CheckContainerOutput(f *framework.Framework, podName string, os string, cmd []string) (string, string, error) { var (
By(fmt.Sprintf("checking connectivity of %s-container in %s", os, podName)) duration = "10s"
out, stderr, err := f.ExecCommandInContainerWithFullOutput(podName, os+"-container", cmd...) poll_interval = "1s"
msg := fmt.Sprintf("cmd: %v, stdout: %q, stderr: %q", cmd, out, stderr) timeout = 10 // seconds
Expect(err).NotTo(HaveOccurred(), msg) )
return out, msg, err
func assertConsistentConnectivity(f *framework.Framework, podName string, os string, cmd []string) {
Consistently(func() error {
By(fmt.Sprintf("checking connectivity of %s-container in %s", os, podName))
_, _, err := f.ExecCommandInContainerWithFullOutput(podName, os+"-container", cmd...)
return err
}, duration, poll_interval).ShouldNot(HaveOccurred())
} }
func CheckLinuxConnectivity(f *framework.Framework, podName string, address string, port string) { func linuxCheck(address string, port int) []string {
successes := 0 nc := fmt.Sprintf("nc -vz %s %v -w %v", address, port, timeout)
for i := 0; i < Iterations; i++ { cmd := []string{"/bin/sh", "-c", nc}
nc := fmt.Sprintf("nc -vz %s %s", address, port) return cmd
cmd := []string{"/bin/sh", "-c", nc}
_, _, err := CheckContainerOutput(f, podName, LinuxOS, cmd)
if err != nil {
break
}
successes++
}
Expect(successes).To(Equal(Iterations))
} }
func CheckWindowsConnectivity(f *framework.Framework, podName string, address string) { func windowsCheck(address string) []string {
successes := 0 curl := fmt.Sprintf("curl.exe %s --connect-timeout %v --fail", address, timeout)
for i := 0; i < Iterations; i++ { cmd := []string{"cmd", "/c", curl}
ps := fmt.Sprintf("$r=invoke-webrequest %s -usebasicparsing; echo $r.StatusCode", address) return cmd
cmd := []string{"powershell", "-command", ps}
out, msg, err := CheckContainerOutput(f, podName, WindowsOS, cmd)
if err != nil || out != "200" {
framework.Logf(msg)
break
}
successes++
}
Expect(successes).To(Equal(Iterations))
} }
func CreateTestPod(f *framework.Framework, image string, os string) *v1.Pod { func createTestPod(f *framework.Framework, image string, os string) *v1.Pod {
containerName := fmt.Sprintf("%s-container", os) containerName := fmt.Sprintf("%s-container", os)
podName := "pod-" + string(uuid.NewUUID()) podName := "pod-" + string(uuid.NewUUID())
pod := &v1.Pod{ pod := &v1.Pod{
...@@ -132,7 +120,7 @@ func CreateTestPod(f *framework.Framework, image string, os string) *v1.Pod { ...@@ -132,7 +120,7 @@ func CreateTestPod(f *framework.Framework, image string, os string) *v1.Pod {
}, },
}, },
} }
if os == LinuxOS { if os == linuxOS {
pod.Spec.Tolerations = []v1.Toleration{ pod.Spec.Tolerations = []v1.Toleration{
{ {
Key: "key", Key: "key",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment