Skip to content

Commit

Permalink
Merge pull request #765 from fromanirh/event-reporting
Browse files Browse the repository at this point in the history
functests: utils: add and use event reporting
  • Loading branch information
openshift-merge-robot authored Oct 20, 2021
2 parents 295bb1c + 48da6b9 commit 5856115
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions functests/4_latency/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
testutils "github.com/openshift-kni/performance-addon-operators/functests/utils"
testclient "github.com/openshift-kni/performance-addon-operators/functests/utils/client"
"github.com/openshift-kni/performance-addon-operators/functests/utils/discovery"
"github.com/openshift-kni/performance-addon-operators/functests/utils/events"
"github.com/openshift-kni/performance-addon-operators/functests/utils/images"
testlog "github.com/openshift-kni/performance-addon-operators/functests/utils/log"
"github.com/openshift-kni/performance-addon-operators/functests/utils/nodes"
Expand Down Expand Up @@ -422,6 +423,16 @@ func getLatencyTestPod(profile *performancev2.PerformanceProfile, node *corev1.N
}
}

func logEventsForPod(testPod *corev1.Pod) {
events, err := events.GetEventsForObject(testclient.Client, testPod.Namespace, testPod.Name, string(testPod.UID))
if err != nil {
testlog.Error(err)
}
for _, event := range events.Items {
testlog.Warningf("-> %s %s %s", event.Action, event.Reason, event.Message)
}
}

func createLatencyTestPod(testPod *corev1.Pod, node *corev1.Node, logName string) {
err := testclient.Client.Create(context.TODO(), testPod)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -431,6 +442,10 @@ func createLatencyTestPod(testPod *corev1.Pod, node *corev1.Node, logName string

By("Waiting two minutes to download the latencyTest image")
err = pods.WaitForPhase(testPod, corev1.PodRunning, 2*time.Minute)
if err != nil {
testlog.Error(err)
logEventsForPod(testPod)
}
Expect(err).ToNot(HaveOccurred())

if runtime, _ := strconv.Atoi(latencyTestRuntime); runtime > 1 {
Expand All @@ -445,6 +460,10 @@ func createLatencyTestPod(testPod *corev1.Pod, node *corev1.Node, logName string
By("Waiting another two minutes to give enough time for the cluster to move the pod to Succeeded phase")
podTimeout := time.Duration(timeout + 120)
err = pods.WaitForPhase(testPod, corev1.PodSucceeded, podTimeout*time.Second)
if err != nil {
testlog.Error(err)
logEventsForPod(testPod)
}
Expect(err).ToNot(HaveOccurred(), getLogFile(node, logName))
}

Expand Down
3 changes: 3 additions & 0 deletions functests/4_latency/test_suite_latency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package __latency_test

import (
"context"
"os"
"testing"
"time"

Expand Down Expand Up @@ -40,6 +41,8 @@ var _ = AfterSuite(func() {
func TestLatency(t *testing.T) {
RegisterFailHandler(Fail)

testlog.Infof("KUBECONFIG=%q", os.Getenv("KUBECONFIG"))

rr := []Reporter{}
if ginkgo_reporters.Polarion.Run {
rr = append(rr, &ginkgo_reporters.Polarion)
Expand Down
19 changes: 19 additions & 0 deletions functests/utils/events/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package events

import (
"context"

corev1 "k8s.io/api/core/v1"

"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetEventsForObject(cli client.Client, namespace, name, uid string) (corev1.EventList, error) {
eventList := corev1.EventList{}
match := client.MatchingFields{
"involvedObject.name": name,
"involvedObject.uid": uid,
}
err := cli.List(context.TODO(), &eventList, &client.ListOptions{Namespace: namespace}, match)
return eventList, err
}

0 comments on commit 5856115

Please sign in to comment.