Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functests: utils: add and use event reporting #765

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}