Add Guestbook App to k8s upgrade tests

This commit is contained in:
shashidharatd 2016-10-31 13:29:52 +05:30
parent 4bbd40441f
commit bade01694a
2 changed files with 99 additions and 33 deletions

View File

@ -50,6 +50,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
testServiceRemainsUp(f, sem)
testSecretsDuringUpgrade(f, sem)
testConfigMapsDuringUpgrade(f, sem)
testGuestbookApplicationDuringUpgrade(f, sem)
})
cm.Do()
})
@ -68,6 +69,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
testServiceUpBeforeAndAfter(f, sem)
testSecretsBeforeAndAfterUpgrade(f, sem)
testConfigMapsBeforeAndAfterUpgrade(f, sem)
testGuestbookApplicationBeforeAndAfterUpgrade(f, sem)
})
cm.Do()
})
@ -84,6 +86,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
testServiceRemainsUp(f, sem)
testSecretsDuringUpgrade(f, sem)
testConfigMapsDuringUpgrade(f, sem)
testGuestbookApplicationDuringUpgrade(f, sem)
})
cm.Do()
})
@ -104,6 +107,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
testServiceUpBeforeAndAfter(f, sem)
testSecretsBeforeAndAfterUpgrade(f, sem)
testConfigMapsBeforeAndAfterUpgrade(f, sem)
testGuestbookApplicationBeforeAndAfterUpgrade(f, sem)
})
cm.Do()
})
@ -122,6 +126,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
testServiceRemainsUp(f, sem)
testSecretsDuringUpgrade(f, sem)
testConfigMapsDuringUpgrade(f, sem)
testGuestbookApplicationDuringUpgrade(f, sem)
})
cm.Do()
})
@ -312,3 +317,43 @@ func testConfigMaps(f *framework.Framework, sem *chaosmonkey.Semaphore, testDuri
// Teardown
}
func testGuestbookApplicationBeforeAndAfterUpgrade(f *framework.Framework, sem *chaosmonkey.Semaphore) {
testGuestbookApplication(f, sem, false)
}
func testGuestbookApplicationDuringUpgrade(f *framework.Framework, sem *chaosmonkey.Semaphore) {
testGuestbookApplication(f, sem, true)
}
func testGuestbookApplication(f *framework.Framework, sem *chaosmonkey.Semaphore, testDuringDisruption bool) {
// Setup
By("setup guestbook app")
GuestbookApplicationSetup(f.ClientSet, f.Namespace.Name)
// Validate
By("validate guestbook app before upgrade")
GuestbookApplicationValidate(f.ClientSet, f.Namespace.Name)
sem.Ready()
if testDuringDisruption {
// Continuously validate
wait.Until(func() {
By("validate guestbook app during upgrade")
GuestbookApplicationValidate(f.ClientSet, f.Namespace.Name)
}, framework.Poll, sem.StopCh)
} else {
// Block until chaosmonkey is done
By("waiting for upgrade to finish without validating guestbook app")
<-sem.StopCh
}
// Validate after upgrade
By("validate guestbook app after upgrade")
GuestbookApplicationValidate(f.ClientSet, f.Namespace.Name)
// Teardown
By("teardown guestbook app")
GuestbookApplicationTeardown(f.ClientSet, f.Namespace.Name)
}

View File

@ -335,34 +335,8 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
})
framework.KubeDescribe("Guestbook application", func() {
forEachGBFile := func(run func(s string)) {
for _, gbAppFile := range []string{
"examples/guestbook/frontend-deployment.yaml",
"examples/guestbook/frontend-service.yaml",
"examples/guestbook/redis-master-deployment.yaml",
"examples/guestbook/redis-master-service.yaml",
"examples/guestbook/redis-slave-deployment.yaml",
"examples/guestbook/redis-slave-service.yaml",
} {
contents := framework.ReadOrDie(gbAppFile)
run(string(contents))
}
}
It("should create and stop a working application [Conformance]", func() {
framework.SkipUnlessServerVersionGTE(deploymentsVersion, c.Discovery())
defer forEachGBFile(func(contents string) {
cleanupKubectlInputs(contents, ns)
})
By("creating all guestbook components")
forEachGBFile(func(contents string) {
framework.Logf(contents)
framework.RunKubectlOrDieInput(contents, "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
})
By("validating guestbook app")
validateGuestbookApp(c, ns)
guestbookApplication(c, ns)
})
})
@ -1597,27 +1571,32 @@ func validateGuestbookApp(c clientset.Interface, ns string) {
err := testutils.WaitForPodsWithLabelRunning(c, ns, label)
Expect(err).NotTo(HaveOccurred())
framework.Logf("Waiting for frontend to serve content.")
if !waitForGuestbookResponse(c, "get", "", `{"data": ""}`, guestbookStartupTimeout, ns) {
// the response could be {"data": ""} or "data": "TestEntry"} depending on how many times validateGuestbookApp is called
if !waitForGuestbookResponse(c, "get", "", []string{`{"data": ""}`, `{"data": "TestEntry"}`}, guestbookStartupTimeout, ns) {
framework.Failf("Frontend service did not start serving content in %v seconds.", guestbookStartupTimeout.Seconds())
}
framework.Logf("Trying to add a new entry to the guestbook.")
if !waitForGuestbookResponse(c, "set", "TestEntry", `{"message": "Updated"}`, guestbookResponseTimeout, ns) {
if !waitForGuestbookResponse(c, "set", "TestEntry", []string{`{"message": "Updated"}`}, guestbookResponseTimeout, ns) {
framework.Failf("Cannot added new entry in %v seconds.", guestbookResponseTimeout.Seconds())
}
framework.Logf("Verifying that added entry can be retrieved.")
if !waitForGuestbookResponse(c, "get", "", `{"data": "TestEntry"}`, guestbookResponseTimeout, ns) {
if !waitForGuestbookResponse(c, "get", "", []string{`{"data": "TestEntry"}`}, guestbookResponseTimeout, ns) {
framework.Failf("Entry to guestbook wasn't correctly added in %v seconds.", guestbookResponseTimeout.Seconds())
}
}
// Returns whether received expected response from guestbook on time.
func waitForGuestbookResponse(c clientset.Interface, cmd, arg, expectedResponse string, timeout time.Duration, ns string) bool {
func waitForGuestbookResponse(c clientset.Interface, cmd, arg string, expectedResponse []string, timeout time.Duration, ns string) bool {
for start := time.Now(); time.Since(start) < timeout; time.Sleep(5 * time.Second) {
res, err := makeRequestToGuestbook(c, cmd, arg, ns)
if err == nil && res == expectedResponse {
return true
if err == nil {
for _, expResp := range expectedResponse {
if res == expResp {
return true
}
}
}
framework.Logf("Failed to get response from guestbook. err: %v, response: %s", err, res)
}
@ -1832,3 +1811,45 @@ func startLocalProxy() (srv *httptest.Server, logs *bytes.Buffer) {
p.Logger = log.New(logs, "", 0)
return httptest.NewServer(p), logs
}
func forEachGuestbookFile(run func(s string)) {
for _, gbAppFile := range []string{
"examples/guestbook/frontend-deployment.yaml",
"examples/guestbook/frontend-service.yaml",
"examples/guestbook/redis-master-deployment.yaml",
"examples/guestbook/redis-master-service.yaml",
"examples/guestbook/redis-slave-deployment.yaml",
"examples/guestbook/redis-slave-service.yaml",
} {
contents := framework.ReadOrDie(gbAppFile)
run(string(contents))
}
}
func GuestbookApplicationSetup(c clientset.Interface, ns string) {
framework.SkipUnlessServerVersionGTE(deploymentsVersion, c.Discovery())
By("creating all guestbook components")
forEachGuestbookFile(func(contents string) {
framework.Logf(contents)
framework.RunKubectlOrDieInput(contents, "create", "-f", "-", fmt.Sprintf("--namespace=%v", ns))
})
}
func GuestbookApplicationValidate(c clientset.Interface, ns string) {
By("validating guestbook app")
validateGuestbookApp(c, ns)
}
func GuestbookApplicationTeardown(c clientset.Interface, ns string) {
By("teardown guestbook app")
forEachGuestbookFile(func(contents string) {
cleanupKubectlInputs(contents, ns)
})
}
func guestbookApplication(c clientset.Interface, ns string) {
GuestbookApplicationSetup(c, ns)
GuestbookApplicationValidate(c, ns)
GuestbookApplicationTeardown(c, ns)
}