Merge pull request #5439 from piosz/guestbook_test

Ported guestbook.sh e2e test to ginkgo
This commit is contained in:
Robert Bailey 2015-03-16 12:49:59 -07:00
commit 0fe77d49af

View File

@ -36,18 +36,14 @@ const (
kittenImage = "kubernetes/update-demo:kitten" kittenImage = "kubernetes/update-demo:kitten"
updateDemoSelector = "name=update-demo" updateDemoSelector = "name=update-demo"
updateDemoContainer = "update-demo" updateDemoContainer = "update-demo"
frontendSelector = "name=frontend"
redisMasterSelector = "name=redis-master"
redisSlaveSelector = "name=redis-slave"
kubectlProxyPort = 8011 kubectlProxyPort = 8011
guestbookResponseTimeout = 10 * time.Minute
) )
var _ = Describe("kubectl", func() { var _ = Describe("kubectl", func() {
// Constants.
var (
updateDemoRoot = filepath.Join(testContext.repoRoot, "examples/update-demo/v1beta1")
nautilusPath = filepath.Join(updateDemoRoot, "nautilus-rc.yaml")
kittenPath = filepath.Join(updateDemoRoot, "kitten-rc.yaml")
)
var c *client.Client var c *client.Client
BeforeEach(func() { BeforeEach(func() {
@ -56,8 +52,15 @@ var _ = Describe("kubectl", func() {
expectNoError(err) expectNoError(err)
}) })
Describe("update-demo", func() {
var (
updateDemoRoot = filepath.Join(testContext.repoRoot, "examples/update-demo/v1beta1")
nautilusPath = filepath.Join(updateDemoRoot, "nautilus-rc.yaml")
kittenPath = filepath.Join(updateDemoRoot, "kitten-rc.yaml")
)
It("should create and stop a replication controller", func() { It("should create and stop a replication controller", func() {
defer cleanup(nautilusPath) defer cleanup(nautilusPath, updateDemoSelector)
By("creating a replication controller") By("creating a replication controller")
runKubectl("create", "-f", nautilusPath) runKubectl("create", "-f", nautilusPath)
@ -65,7 +68,7 @@ var _ = Describe("kubectl", func() {
}) })
It("should scale a replication controller", func() { It("should scale a replication controller", func() {
defer cleanup(nautilusPath) defer cleanup(nautilusPath, updateDemoSelector)
By("creating a replication controller") By("creating a replication controller")
runKubectl("create", "-f", nautilusPath) runKubectl("create", "-f", nautilusPath)
@ -80,7 +83,7 @@ var _ = Describe("kubectl", func() {
It("should do a rolling update of a replication controller", func() { It("should do a rolling update of a replication controller", func() {
// Cleanup all resources in case we fail somewhere in the middle // Cleanup all resources in case we fail somewhere in the middle
defer cleanup(updateDemoRoot) defer cleanup(updateDemoRoot, updateDemoSelector)
By("creating the initial replication controller") By("creating the initial replication controller")
runKubectl("create", "-f", nautilusPath) runKubectl("create", "-f", nautilusPath)
@ -89,17 +92,85 @@ var _ = Describe("kubectl", func() {
runKubectl("rollingupdate", "update-demo-nautilus", "--update-period=1s", "-f", kittenPath) runKubectl("rollingupdate", "update-demo-nautilus", "--update-period=1s", "-f", kittenPath)
validateController(c, kittenImage, 2) validateController(c, kittenImage, 2)
}) })
})
Describe("guestbook", func() {
var guestbookPath = filepath.Join(testContext.repoRoot, "examples/guestbook")
It("should create and stop a working application", func() {
defer cleanup(guestbookPath, frontendSelector, redisMasterSelector, redisSlaveSelector)
By("creating all guestbook components")
runKubectl("create", "-f", guestbookPath)
By("validating guestbook app")
validateGuestbookApp(c)
})
})
}) })
func cleanup(filePath string) { func validateGuestbookApp(c *client.Client) {
// Wait for frontend to serve content.
serving := false
for start := time.Now(); time.Since(start) < guestbookResponseTimeout; time.Sleep(5 * time.Second) {
entry, err := makeRequestToGuestbook(c, "get", "")
if err == nil && entry == `{"data": ""}` {
serving = true
break
}
}
if !serving {
Failf("Frontend service did not start serving content in %v seconds", guestbookResponseTimeout.Seconds())
}
// Try to add a new entry to the guestbook.
added := false
for start := time.Now(); time.Since(start) < guestbookResponseTimeout; time.Sleep(5 * time.Second) {
result, err := makeRequestToGuestbook(c, "set", "TestEntry")
if err == nil && result == `{"message": "Updated"}` {
added = true
break
}
}
if !added {
Failf("Cannot added new entry in %v seconds", guestbookResponseTimeout.Seconds())
}
// Verify that entry is correctly added to the guestbook.
entry, err := makeRequestToGuestbook(c, "get", "")
if err != nil {
Failf("Request to the guestbook failed with: %v", err)
}
if entry != `{"data": "TestEntry"}` {
Failf("Wrong entry received: %v", entry)
}
}
func makeRequestToGuestbook(c *client.Client, cmd, value string) (string, error) {
result, err := c.Get().
Prefix("proxy").
Resource("services").
Name("frontend").
Suffix("/index.php").
Param("cmd", cmd).
Param("key", "messages").
Param("value", value).
Do().
Raw()
return string(result), err
}
func cleanup(filePath string, selectors ...string) {
By("using stop to clean up resources") By("using stop to clean up resources")
runKubectl("stop", "-f", filePath) runKubectl("stop", "-f", filePath)
resources := runKubectl("get", "pods,rc", "-l", updateDemoSelector, "--no-headers") for _, selector := range selectors {
resources := runKubectl("get", "pods,rc,se", "-l", selector, "--no-headers")
if resources != "" { if resources != "" {
Failf("Resources left running after stop:\n%s", resources) Failf("Resources left running after stop:\n%s", resources)
} }
}
} }
func validateController(c *client.Client, image string, replicas int) { func validateController(c *client.Client, image string, replicas int) {
@ -158,7 +229,7 @@ func validateController(c *client.Client, image string, replicas int) {
return return
} }
} }
Failf("Timed out after %d seconds waiting for %s pods to reach valid state", podStartTimeout.Seconds(), updateDemoSelector) Failf("Timed out after %v seconds waiting for %s pods to reach valid state", podStartTimeout.Seconds(), updateDemoSelector)
} }
type updateDemoData struct { type updateDemoData struct {