Skip to content

Commit

Permalink
tests, kubernetes: avoid boolean arg
Browse files Browse the repository at this point in the history
A casual reader cannot guess what is "true" about reporter.Dump(duration, true).
The meaning of reporter.DumpAllNamespaces(duration) is far clearer.

Signed-off-by: Dan Kenigsberg <[email protected]>
  • Loading branch information
dankenigsberg committed Aug 5, 2021
1 parent 7539b84 commit 1f98338
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ func main() {
// 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, true)
reporter.DumpAllNamespaces(duration)
}
23 changes: 13 additions & 10 deletions tests/reporter/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,18 @@ func (r *KubernetesReporter) SpecDidComplete(specSummary *types.SpecSummary) {
if r.artifactsDir == "" {
return
}
r.Dump(specSummary.RunTime, false)
r.DumpTestNamespaces(specSummary.RunTime)
}

func (r *KubernetesReporter) Dump(duration time.Duration, isExternal bool) {
func (r *KubernetesReporter) DumpTestNamespaces(duration time.Duration) {
r.dumpNamespaces(duration, tests.TestNamespaces)
}

func (r *KubernetesReporter) DumpAllNamespaces(duration time.Duration) {
r.dumpNamespaces(duration, []string{v1.NamespaceAll})
}

func (r *KubernetesReporter) dumpNamespaces(duration time.Duration, vmiNamespaces []string) {
virtCli, err := kubecli.GetKubevirtClient()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get client: %v\n", err)
Expand Down Expand Up @@ -146,7 +154,7 @@ func (r *KubernetesReporter) Dump(duration time.Duration, isExternal bool) {
r.logNodeCommands(virtCli, virtHandlerPods)
r.logVirtLauncherCommands(virtCli, networkPodsDir)
r.logVirtLauncherPrivilegedCommands(virtCli, networkPodsDir, virtHandlerPods)
r.logVMICommands(virtCli, isExternal)
r.logVMICommands(virtCli, vmiNamespaces)
}

// Cleanup cleans up the current content of the artifactsDir
Expand Down Expand Up @@ -364,19 +372,14 @@ func (r *KubernetesReporter) logAuditLogs(virtCli kubecli.KubevirtClient, logsdi
}
}

func (r *KubernetesReporter) logVMICommands(virtCli kubecli.KubevirtClient, isExternal bool) {
func (r *KubernetesReporter) logVMICommands(virtCli kubecli.KubevirtClient, vmiNamespaces []string) {

logsdir := filepath.Join(r.artifactsDir, "network", "vmis")
if err := os.MkdirAll(logsdir, 0777); err != nil {
fmt.Fprintf(os.Stderr, "failed to create directory: %v\n", err)
return
}

vmiNamespaces := tests.TestNamespaces
if isExternal {
vmiNamespaces = []string{v1.NamespaceAll}
}

for _, ns := range vmiNamespaces {
vmis, err := virtCli.VirtualMachineInstance(ns).List(&metav1.ListOptions{})
if err != nil {
Expand Down Expand Up @@ -1034,7 +1037,7 @@ func (r *KubernetesReporter) dumpK8sEntityToFile(virtCli kubecli.KubevirtClient,
func (r *KubernetesReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
if setupSummary.State.IsFailure() {
r.failureCount++
r.Dump(setupSummary.RunTime, false)
r.DumpTestNamespaces(setupSummary.RunTime)
}
}

Expand Down

0 comments on commit 1f98338

Please sign in to comment.