From 4a236f61452be39183bbdcd4f12f4a1accd9755e Mon Sep 17 00:00:00 2001 From: m1093782566 Date: Fri, 2 Jun 2017 10:51:55 +0800 Subject: [PATCH] use status code instead of response body for checking kube-proxy URLs --- test/e2e/framework/networking_utils.go | 15 ++++++++++++++- test/e2e/network/networking.go | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/e2e/framework/networking_utils.go b/test/e2e/framework/networking_utils.go index 06da52e58f9..9d5226e4cdb 100644 --- a/test/e2e/framework/networking_utils.go +++ b/test/e2e/framework/networking_utils.go @@ -279,9 +279,22 @@ func (config *NetworkingTestConfig) DialFromNode(protocol, targetIP string, targ func (config *NetworkingTestConfig) GetSelfURL(port int32, path string, expected string) { cmd := fmt.Sprintf("curl -i -q -s --connect-timeout 1 http://localhost:%d%s", port, path) By(fmt.Sprintf("Getting kube-proxy self URL %s", path)) + config.executeCurlCmd(cmd, expected) +} +// GetSelfStatusCode executes a curl against the given path via kubectl exec into a +// test container running with host networking, and fails if the returned status +// code doesn't match the expected string. +func (config *NetworkingTestConfig) GetSelfURLStatusCode(port int32, path string, expected string) { + // check status code + cmd := fmt.Sprintf("curl -o /dev/null -i -q -s -w %%{http_code} --connect-timeout 1 http://localhost:%d%s", port, path) + By(fmt.Sprintf("Checking status code against http://localhost:%d%s", port, path)) + config.executeCurlCmd(cmd, expected) +} + +func (config *NetworkingTestConfig) executeCurlCmd(cmd string, expected string) { // These are arbitrary timeouts. The curl command should pass on first try, - // unless kubeproxy is starved/bootstrapping/restarting etc. + // unless remote server is starved/bootstrapping/restarting etc. const retryInterval = 1 * time.Second const retryTimeout = 30 * time.Second podName := config.HostTestContainerPod.Name diff --git a/test/e2e/network/networking.go b/test/e2e/network/networking.go index 68cf59a6020..f5a1566e2fb 100644 --- a/test/e2e/network/networking.go +++ b/test/e2e/network/networking.go @@ -87,7 +87,8 @@ var _ = SIGDescribe("Networking", func() { config.GetSelfURL(ports.ProxyHealthzPort, "/healthz", "200 OK") // Verify /healthz returns the proper content. config.GetSelfURL(ports.ProxyHealthzPort, "/healthz", "lastUpdated") - config.GetSelfURL(ports.ProxyStatusPort, "/proxyMode", "iptables") // the default + // Verify /proxyMode returns http status code 200. + config.GetSelfURLStatusCode(ports.ProxyStatusPort, "/proxyMode", "200") }) // TODO: Remove [Slow] when this has had enough bake time to prove presubmit worthiness.