From fe838fca64de6eb9a49d416e8291990be7b8b5fb Mon Sep 17 00:00:00 2001 From: Zach Loafman Date: Mon, 9 Feb 2015 07:48:07 -0800 Subject: [PATCH] Convert waitForPodSuccess to error form, glog->By * Also add variable timeout as well * And nail in coffin for glog in this file! --- test/e2e/pods.go | 6 ++---- test/e2e/util.go | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/test/e2e/pods.go b/test/e2e/pods.go index 01ac3018435..0bfa78c691c 100644 --- a/test/e2e/pods.go +++ b/test/e2e/pods.go @@ -275,10 +275,8 @@ var _ = Describe("Pods", func() { }() // Wait for client pod to complete. - success := waitForPodSuccess(c, clientPod.Name, clientPod.Spec.Containers[0].Name) - if !success { - Fail(fmt.Sprintf("Failed to run client pod to detect service env vars.")) - } + err = waitForPodSuccess(c, clientPod.Name, clientPod.Spec.Containers[0].Name, 60*time.Second) + Expect(err).NotTo(HaveOccurred()) // Grab its logs. Get host first. clientPodStatus, err := c.Pods(api.NamespaceDefault).Get(clientPod.Name) diff --git a/test/e2e/util.go b/test/e2e/util.go index c8490c4af5e..0dbe7864466 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -26,7 +26,6 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/clientauth" - "github.com/golang/glog" . "github.com/onsi/ginkgo" ) @@ -79,36 +78,36 @@ func waitForPodNotPending(c *client.Client, ns, podName string, tryFor time.Dura } // waitForPodSuccess returns true if the pod reached state success, or false if it reached failure or ran too long. -func waitForPodSuccess(c *client.Client, podName string, contName string) bool { - for i := 0; i < 10; i++ { +func waitForPodSuccess(c *client.Client, podName string, contName string, tryFor time.Duration) error { + trySecs := int(tryFor.Seconds()) + for i := 0; i <= trySecs; i += 5 { if i > 0 { time.Sleep(5 * time.Second) } pod, err := c.Pods(api.NamespaceDefault).Get(podName) if err != nil { - glog.Warningf("Get pod failed: %v", err) + By(fmt.Sprintf("Get pod failed, ignoring for 5s: %v", err)) continue } // Cannot use pod.Status.Phase == api.PodSucceeded/api.PodFailed due to #2632 ci, ok := pod.Status.Info[contName] if !ok { - glog.Infof("No Status.Info for container %s in pod %s yet", contName, podName) + By(fmt.Sprintf("No Status.Info for container %s in pod %s yet", contName, podName)) } else { if ci.State.Termination != nil { if ci.State.Termination.ExitCode == 0 { - glog.Infof("Saw pod success") - return true + By("Saw pod success") + return nil } else { - glog.Infof("Saw pod failure: %+v", ci.State.Termination) + By(fmt.Sprintf("Saw pod failure: %+v", ci.State.Termination)) } - glog.Infof("Waiting for pod %q status to be success or failure", podName) + By(fmt.Sprintf("Waiting for pod %q status to be success or failure", podName)) } else { - glog.Infof("Nil State.Termination for container %s in pod %s so far", contName, podName) + By(fmt.Sprintf("Nil State.Termination for container %s in pod %s so far", contName, podName)) } } } - glog.Warningf("Gave up waiting for pod %q status to be success or failure", podName) - return false + return fmt.Errorf("Gave up waiting for pod %q status to be success or failure after %d seconds", podName, trySecs) } func loadClient() (*client.Client, error) {