Skip to content

Commit

Permalink
Merge pull request kubernetes#4750 from fabioy/e2e-defer.fix
Browse files Browse the repository at this point in the history
Move 'defer' call before creation on various e2e tests.
  • Loading branch information
roberthbailey committed Feb 26, 2015
2 parents e41d0bd + 0b72391 commit 6efa68a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
16 changes: 7 additions & 9 deletions test/e2e/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,16 @@ var _ = Describe("Events", func() {
}

By("submitting the pod to kubernetes")
_, err := podClient.Create(pod)
if err != nil {
Fail(fmt.Sprintf("Failed to create pod: %v", err))
}
defer func() {
By("deleting the pod")
defer GinkgoRecover()
podClient.Delete(pod.Name)
}()
if _, err := podClient.Create(pod); err != nil {
Failf("Failed to create pod: %v", err)
}

By("waiting for the pod to start running")
err = waitForPodRunning(c, pod.Name, 300*time.Second)
err := waitForPodRunning(c, pod.Name, 300*time.Second)
Expect(err).NotTo(HaveOccurred())

By("verifying the pod is in kubernetes")
Expand All @@ -92,7 +90,7 @@ var _ = Describe("Events", func() {
By("retrieving the pod")
podWithUid, err := podClient.Get(pod.Name)
if err != nil {
Fail(fmt.Sprintf("Failed to get pod: %v", err))
Failf("Failed to get pod: %v", err)
}
fmt.Printf("%+v\n", podWithUid)

Expand All @@ -108,7 +106,7 @@ var _ = Describe("Events", func() {
}.AsSelector(),
)
if err != nil {
Fail(fmt.Sprintf("Error while listing events:", err))
Failf("Error while listing events: %v", err)
}
Expect(len(events.Items)).ToNot(BeZero(), "scheduler events from running pod")
fmt.Println("Saw scheduler event for our pod.")
Expand All @@ -125,7 +123,7 @@ var _ = Describe("Events", func() {
}.AsSelector(),
)
if err != nil {
Fail(fmt.Sprintf("Error while listing events:", err))
Failf("Error while listing events: %v", err)
}
Expect(len(events.Items)).ToNot(BeZero(), "kubelet events from running pod")
fmt.Println("Saw kubelet event for our pod.")
Expand Down
26 changes: 10 additions & 16 deletions test/e2e/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,17 @@ var _ = Describe("Secrets", func() {
},
}

secret, err := c.Secrets(ns).Create(secret)
By(fmt.Sprintf("Creating secret with name %s", secret.Name))
if err != nil {
Fail(fmt.Sprintf("unable to create test secret %s: %v", secret.Name, err))
}

// Clean up secret
defer func() {
By("Cleaning up the secret")
if err = c.Secrets(ns).Delete(secret.Name); err != nil {
Fail(fmt.Sprintf("unable to delete secret %v: %v", secret.Name, err))
if err := c.Secrets(ns).Delete(secret.Name); err != nil {
Failf("unable to delete secret %v: %v", secret.Name, err)
}
}()
var err error
if secret, err = c.Secrets(ns).Create(secret); err != nil {
Failf("unable to create test secret %s: %v", secret.Name, err)
}

By(fmt.Sprintf("Creating a pod to consume secret %v", secret.Name))
// Make a client pod that verifies that it has the service environment variables.
Expand Down Expand Up @@ -112,21 +110,17 @@ var _ = Describe("Secrets", func() {
},
}

_, err = c.Pods(ns).Create(clientPod)
if err != nil {
Fail(fmt.Sprintf("Failed to create pod: %v", err))
defer c.Pods(ns).Delete(clientPod.Name)
if _, err := c.Pods(ns).Create(clientPod); err != nil {
Failf("Failed to create pod: %v", err)
}
defer func() {
c.Pods(ns).Delete(clientPod.Name)
}()

// Wait for client pod to complete.
expectNoError(waitForPodRunning(c, clientPod.Name, 60*time.Second))

// Grab its logs. Get host first.
clientPodStatus, err := c.Pods(ns).Get(clientPod.Name)
if err != nil {
Fail(fmt.Sprintf("Failed to get clientPod to know host: %v", err))
Failf("Failed to get clientPod to know host: %v", err)
}
By(fmt.Sprintf("Trying to get logs from host %s pod %s container %s: %v",
clientPodStatus.Status.Host, clientPodStatus.Name, clientPodStatus.Spec.Containers[0].Name, err))
Expand Down
27 changes: 14 additions & 13 deletions test/e2e/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,23 @@ var _ = Describe("Services", func() {
}

By("submitting the pod to kuberenetes")
_, err := podClient.Create(pod)
if err != nil {
Fail(fmt.Sprintf("Failed to create %s pod: %v", pod.Name, err))
}
defer func() {
By("deleting the pod")
defer GinkgoRecover()
podClient.Delete(pod.Name)
}()
if _, err := podClient.Create(pod); err != nil {
Failf("Failed to create %s pod: %v", pod.Name, err)
}

By("waiting for the pod to start running")
err = waitForPodRunning(c, pod.Name, 300*time.Second)
err := waitForPodRunning(c, pod.Name, 300*time.Second)
Expect(err).NotTo(HaveOccurred())

By("retrieving the pod")
pod, err = podClient.Get(pod.Name)
if err != nil {
Fail(fmt.Sprintf("Failed to get pod %s: %v", pod.Name, err))
Failf("Failed to get pod %s: %v", pod.Name, err)
}

// Try to find results for each expected name.
Expand Down Expand Up @@ -166,7 +165,7 @@ var _ = Describe("Services", func() {
Do().
Into(&svc)
if err != nil {
Fail(fmt.Sprintf("unexpected error listing services using ro service: %v", err))
Failf("unexpected error listing services using ro service: %v", err)
}
var foundRW, foundRO bool
for i := range svc.Items {
Expand Down Expand Up @@ -210,16 +209,18 @@ var _ = Describe("Services", func() {

validateEndpointsOrFail(c, ns, serviceName, expectedPort, []string{})

name1 := "test1"
addEndpointPodOrFail(c, ns, name1, labels)
names := []string{name1}
var names []string
defer func() {
for _, name := range names {
err := c.Pods(ns).Delete(name)
Expect(err).NotTo(HaveOccurred())
}
}()

name1 := "test1"
addEndpointPodOrFail(c, ns, name1, labels)
names = append(names, name1)

validateEndpointsOrFail(c, ns, serviceName, expectedPort, names)

name2 := "test2"
Expand Down Expand Up @@ -251,18 +252,18 @@ func validateIPsOrFail(c *client.Client, ns string, expectedPort int, expectedEn
ips := util.StringSet{}
for _, ep := range endpoints.Endpoints {
if ep.Port != expectedPort {
Fail(fmt.Sprintf("invalid port, expected %d, got %d", expectedPort, ep.Port))
Failf("invalid port, expected %d, got %d", expectedPort, ep.Port)
}
ips.Insert(ep.IP)
}

for _, name := range expectedEndpoints {
pod, err := c.Pods(ns).Get(name)
if err != nil {
Fail(fmt.Sprintf("failed to get pod %s, that's pretty weird. validation failed: %s", name, err))
Failf("failed to get pod %s, that's pretty weird. validation failed: %s", name, err)
}
if !ips.Has(pod.Status.PodIP) {
Fail(fmt.Sprintf("ip validation failed, expected: %v, saw: %v", ips, pod.Status.PodIP))
Failf("ip validation failed, expected: %v, saw: %v", ips, pod.Status.PodIP)
}
}
}
Expand Down

0 comments on commit 6efa68a

Please sign in to comment.