Update hybrid_network.go

Add By clauses to windows networking test so that we always know where it failed and how
This commit is contained in:
jay vyas 2020-12-10 10:47:51 -08:00
parent 5a17c7ac74
commit 9aca5f8e41

View File

@ -50,19 +50,27 @@ var _ = SIGDescribe("Hybrid cluster network", func() {
ginkgo.Context("for all supported CNIs", func() {
ginkgo.It("should have stable networking for Linux and Windows pods", func() {
ginkgo.By("creating linux and windows pods")
linuxPod := createTestPod(f, linuxBusyBoxImage, linuxOS)
ginkgo.By("creating a linux pod and waiting for it to be running")
linuxPod = f.PodClient().CreateSync(linuxPod)
windowsPod := createTestPod(f, windowsBusyBoximage, windowsOS)
windowsPod.Spec.Containers[0].Args = []string{"test-webserver"}
ginkgo.By("creating a windows pod and waiting for it to be running")
windowsPod = f.PodClient().CreateSync(windowsPod)
ginkgo.By("verifying pod external connectivity to the internet")
ginkgo.By("checking connectivity to 8.8.8.8 53 (google.com) from Linux")
assertConsistentConnectivity(f, linuxPod.ObjectMeta.Name, linuxOS, linuxCheck("8.8.8.8", 53))
ginkgo.By("checking connectivity to www.google.com from Windows")
assertConsistentConnectivity(f, windowsPod.ObjectMeta.Name, windowsOS, windowsCheck("www.google.com"))
ginkgo.By("verifying pod internal connectivity to the cluster dataplane")
ginkgo.By("checking connectivity from Linux to Windows")
assertConsistentConnectivity(f, linuxPod.ObjectMeta.Name, linuxOS, linuxCheck(windowsPod.Status.PodIP, 80))
@ -75,27 +83,28 @@ var _ = SIGDescribe("Hybrid cluster network", func() {
})
var (
duration = "10s"
pollInterval = "1s"
timeout = 10 // seconds
duration = "10s"
pollInterval = "1s"
timeoutSeconds = 10
)
func assertConsistentConnectivity(f *framework.Framework, podName string, os string, cmd []string) {
gomega.Consistently(func() error {
ginkgo.By(fmt.Sprintf("checking connectivity of %s-container in %s", os, podName))
// TODO, we should be retrying this similar to what is done in DialFromNode, in the test/e2e/networking/networking.go tests
_, _, err := f.ExecCommandInContainerWithFullOutput(podName, os+"-container", cmd...)
return err
}, duration, pollInterval).ShouldNot(gomega.HaveOccurred())
}
func linuxCheck(address string, port int) []string {
nc := fmt.Sprintf("nc -vz %s %v -w %v", address, port, timeout)
nc := fmt.Sprintf("nc -vz %s %v -w %v", address, port, timeoutSeconds)
cmd := []string{"/bin/sh", "-c", nc}
return cmd
}
func windowsCheck(address string) []string {
curl := fmt.Sprintf("curl.exe %s --connect-timeout %v --fail", address, timeout)
curl := fmt.Sprintf("curl.exe %s --connect-timeout %v --fail", address, timeoutSeconds)
cmd := []string{"cmd", "/c", curl}
return cmd
}