Skip to content

Commit

Permalink
Merge pull request #136 from rmohr/events
Browse files Browse the repository at this point in the history
Make libvirt event checking test less flaky
  • Loading branch information
rmohr committed Mar 13, 2017
2 parents 09a6b0b + 9c67de3 commit 3c0f07b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tests/vmlifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ var _ = Describe("Vmlifecycle", func() {
Expect(pods.Items).To(HaveLen(1))

handlerName := pods.Items[0].GetObjectMeta().GetName()
seconds := int64(30)
logsQuery := coreCli.Pods(api.NamespaceDefault).GetLogs(handlerName, &kubev1.PodLogOptions{SinceSeconds: &seconds})

// Make sure we schedule the VM to master
vm.Spec.NodeSelector = map[string]string{"kubernetes.io/hostname": "master"}
Expand All @@ -87,6 +89,13 @@ var _ = Describe("Vmlifecycle", func() {
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMStart(obj)

// Check if the start event was logged
Eventually(func() string {
data, err := logsQuery.DoRaw()
Expect(err).ToNot(HaveOccurred())
return string(data)
}, 5, 0.1).Should(MatchRegexp("(name=%s)[^\n]+(kind=Domain)[^\n]+(Domain is in state Running)", vm.GetObjectMeta().GetName()))

// Delete the VM and wait for the confirmation of the delete
_, err = restClient.Delete().Resource("vms").Namespace(api.NamespaceDefault).Name(vm.GetObjectMeta().GetName()).Do().Get()
Expect(err).To(BeNil())
Expand All @@ -97,13 +106,12 @@ var _ = Describe("Vmlifecycle", func() {
return false
}).Watch()

// Check if start and stop events were logged by the domain event watch loop
seconds := int64(30)
data, err := coreCli.Pods(api.NamespaceDefault).GetLogs(handlerName, &kubev1.PodLogOptions{SinceSeconds: &seconds}).DoRaw()
Expect(err).ToNot(HaveOccurred())
logs := string(data)
Expect(logs).To(MatchRegexp("(name=%s)[^\n]+(kind=Domain)[^\n]+(Domain is in state Running)", vm.GetObjectMeta().GetName()))
Expect(logs).To(MatchRegexp("(name=%s)[^\n]+(kind=Domain)[^\n]+(Domain deleted)", vm.GetObjectMeta().GetName()))
// Check if the stop event was logged
Eventually(func() string {
data, err := logsQuery.DoRaw()
Expect(err).ToNot(HaveOccurred())
return string(data)
}, 5, 0.1).Should(MatchRegexp("(name=%s)[^\n]+(kind=Domain)[^\n]+(Domain deleted)", vm.GetObjectMeta().GetName()))

close(done)
}, 30)
Expand Down

0 comments on commit 3c0f07b

Please sign in to comment.