Skip to content

Commit

Permalink
Merge pull request kubevirt#1299 from cynepco3hahue/custom_fail_handler
Browse files Browse the repository at this point in the history
Add KubeVirt custom fail handler
  • Loading branch information
Artyom Lukianov authored Jul 15, 2018
2 parents ea6e19e + a0ed3f5 commit 130b88a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package tests_test

import (
. "github.com/onsi/ginkgo"

. "github.com/onsi/gomega"

"testing"
Expand All @@ -31,7 +32,7 @@ import (
)

func TestTests(t *testing.T) {
RegisterFailHandler(Fail)
RegisterFailHandler(tests.KubevirtFailHandler)
reporters := make([]Reporter, 0)
if ginkgo_reporters.Polarion.Run {
reporters = append(reporters, &ginkgo_reporters.Polarion)
Expand Down
35 changes: 35 additions & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,3 +1567,38 @@ func GetNodeLibvirtCapabilities(nodeName string) string {

return output
}

// KubevirtFailHandler call ginkgo.Fail with printing the additional information
func KubevirtFailHandler(message string, callerSkip ...int) {
virtClient, err := kubecli.GetKubevirtClient()
PanicOnError(err)

for _, ns := range []string{metav1.NamespaceSystem, NamespaceTestDefault} {
// Get KubeVirt specific pods information
pods, err := virtClient.CoreV1().Pods(ns).List(metav1.ListOptions{LabelSelector: "kubevirt.io"})
PanicOnError(err)

for _, pod := range pods.Items {
fmt.Printf("\nPod name: %s\t Pod phase: %s\n\n", pod.Name, pod.Status.Phase)
var tailLines int64 = 15
var containerName = ""
if strings.HasPrefix(pod.Name, "virt-launcher") {
containerName = "compute"
}
logsRaw, err := virtClient.CoreV1().Pods(ns).GetLogs(
pod.Name, &k8sv1.PodLogOptions{
TailLines: &tailLines,
Container: containerName,
},
).DoRaw()
if err == nil {
fmt.Printf(string(logsRaw))
}
}
}

if len(callerSkip) > 0 {
callerSkip[0]++
}
Fail(message, callerSkip...)
}

0 comments on commit 130b88a

Please sign in to comment.