Skip to content

Commit

Permalink
Hardcode the number of fails parameter to 1 for the reporter, since i…
Browse files Browse the repository at this point in the history
…t's not tracking the number of failures.

Remove the specsummary from the methods that are not using it, split the cleanup / dump functions so they can invoked explicitly from the dump command.

Signed-off-by: Federico Paolinelli <[email protected]>
  • Loading branch information
fedepaol committed Sep 30, 2019
1 parent 87f3aa8 commit 1198a40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
12 changes: 4 additions & 8 deletions cmd/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
"time"

"github.com/onsi/ginkgo/types"
"github.com/spf13/pflag"

"kubevirt.io/client-go/kubecli"
Expand All @@ -16,13 +15,10 @@ func main() {
var duration time.Duration
pflag.CommandLine.AddGoFlagSet(kubecli.FlagSet())
pflag.DurationVarP(&duration, "since", "s", 10*time.Minute, "collection window, defaults to 10 minutes")
maxFails := pflag.Int("maxfails", 10, "max failed tests to report, defaults to 10")
pflag.Parse()

reporter := reporter.NewKubernetesReporter(os.Getenv("ARTIFACTS"), *maxFails)
reporter.BeforeSuiteDidRun(nil)
reporter.SpecDidComplete(&types.SpecSummary{
State: types.SpecStateFailed,
RunTime: duration,
})
// Hardcoding maxFails to 1 since the purpouse here is just to dump the state once
reporter := reporter.NewKubernetesReporter(os.Getenv("ARTIFACTS"), 1)
reporter.Cleanup()
reporter.Dump(duration)
}
46 changes: 28 additions & 18 deletions tests/reporter/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ func (r *KubernetesReporter) SpecSuiteWillBegin(config config.GinkgoConfigType,
}

func (r *KubernetesReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
// clean up artifacts from previous run
if r.artifactsDir != "" {
os.RemoveAll(r.artifactsDir)
}
r.Cleanup()
}

func (r *KubernetesReporter) SpecWillRun(specSummary *types.SpecSummary) {
Expand All @@ -65,7 +62,12 @@ func (r *KubernetesReporter) SpecDidComplete(specSummary *types.SpecSummary) {
if r.artifactsDir == "" {
return
}
r.Dump(specSummary.RunTime)
}

// Dump dumps the current state of the cluster. The relevant logs are collected starting
// from the since parameter.
func (r *KubernetesReporter) Dump(since time.Duration) {
virtCli, err := kubecli.GetKubevirtClient()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get client: %v\n", err)
Expand All @@ -77,15 +79,23 @@ func (r *KubernetesReporter) SpecDidComplete(specSummary *types.SpecSummary) {
return
}

r.logEvents(virtCli, specSummary)
r.logNodes(virtCli, specSummary)
r.logPods(virtCli, specSummary)
r.logVMIs(virtCli, specSummary)
r.logDomainXMLs(virtCli, specSummary)
r.logLogs(virtCli, specSummary)
r.logEvents(virtCli, since)
r.logNodes(virtCli)
r.logPods(virtCli)
r.logVMIs(virtCli)
r.logDomainXMLs(virtCli)
r.logLogs(virtCli, since)
}

// Cleanup cleans up the current content of the artifactsDir
func (r *KubernetesReporter) Cleanup() {
// clean up artifacts from previous run
if r.artifactsDir != "" {
os.RemoveAll(r.artifactsDir)
}
}

func (r *KubernetesReporter) logDomainXMLs(virtCli kubecli.KubevirtClient, specSummary *types.SpecSummary) {
func (r *KubernetesReporter) logDomainXMLs(virtCli kubecli.KubevirtClient) {

f, err := os.OpenFile(filepath.Join(r.artifactsDir, fmt.Sprintf("%d_domains.log", r.failureCount)),
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
Expand All @@ -112,7 +122,7 @@ func (r *KubernetesReporter) logDomainXMLs(virtCli kubecli.KubevirtClient, specS
}
}

func (r *KubernetesReporter) logVMIs(virtCli kubecli.KubevirtClient, specSummary *types.SpecSummary) {
func (r *KubernetesReporter) logVMIs(virtCli kubecli.KubevirtClient) {

f, err := os.OpenFile(filepath.Join(r.artifactsDir, fmt.Sprintf("%d_vmis.log", r.failureCount)),
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
Expand All @@ -136,7 +146,7 @@ func (r *KubernetesReporter) logVMIs(virtCli kubecli.KubevirtClient, specSummary
fmt.Fprintln(f, string(j))
}

func (r *KubernetesReporter) logPods(virtCli kubecli.KubevirtClient, specSummary *types.SpecSummary) {
func (r *KubernetesReporter) logPods(virtCli kubecli.KubevirtClient) {

f, err := os.OpenFile(filepath.Join(r.artifactsDir, fmt.Sprintf("%d_pods.log", r.failureCount)),
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
Expand All @@ -160,7 +170,7 @@ func (r *KubernetesReporter) logPods(virtCli kubecli.KubevirtClient, specSummary
fmt.Fprintln(f, string(j))
}

func (r *KubernetesReporter) logNodes(virtCli kubecli.KubevirtClient, specSummary *types.SpecSummary) {
func (r *KubernetesReporter) logNodes(virtCli kubecli.KubevirtClient) {

f, err := os.OpenFile(filepath.Join(r.artifactsDir, fmt.Sprintf("%d_nodes.log", r.failureCount)),
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
Expand All @@ -184,7 +194,7 @@ func (r *KubernetesReporter) logNodes(virtCli kubecli.KubevirtClient, specSummar
fmt.Fprintln(f, string(j))
}

func (r *KubernetesReporter) logLogs(virtCli kubecli.KubevirtClient, specSummary *types.SpecSummary) {
func (r *KubernetesReporter) logLogs(virtCli kubecli.KubevirtClient, since time.Duration) {

logsdir := filepath.Join(r.artifactsDir, "pods")

Expand All @@ -193,7 +203,7 @@ func (r *KubernetesReporter) logLogs(virtCli kubecli.KubevirtClient, specSummary
return
}

startTime := time.Now().Add(-specSummary.RunTime).Add(-5 * time.Second)
startTime := time.Now().Add(-since).Add(-5 * time.Second)

pods, err := virtCli.CoreV1().Pods(v1.NamespaceAll).List(v12.ListOptions{})
if err != nil {
Expand Down Expand Up @@ -231,7 +241,7 @@ func (r *KubernetesReporter) logLogs(virtCli kubecli.KubevirtClient, specSummary
}
}

func (r *KubernetesReporter) logEvents(virtCli kubecli.KubevirtClient, specSummary *types.SpecSummary) {
func (r *KubernetesReporter) logEvents(virtCli kubecli.KubevirtClient, since time.Duration) {

f, err := os.OpenFile(filepath.Join(r.artifactsDir, fmt.Sprintf("%d_events.log", r.failureCount)),
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
Expand All @@ -241,7 +251,7 @@ func (r *KubernetesReporter) logEvents(virtCli kubecli.KubevirtClient, specSumma
}
defer f.Close()

startTime := time.Now().Add(-specSummary.RunTime).Add(-5 * time.Second)
startTime := time.Now().Add(-since).Add(-5 * time.Second)

events, err := virtCli.CoreV1().Events(v1.NamespaceAll).List(v12.ListOptions{})
if err != nil {
Expand Down

0 comments on commit 1198a40

Please sign in to comment.