tests: Don't try to log a paused VMI
The console is not available when a VMI is in paused state and any
attempt to connect blocks the exection for a ~2min timeout. Instead of
waiting just skip paused VMIs when dumping the logs.
@@ -363,39 +363,26 @@ func (r *KubernetesReporter) logAuditLogs(virtCli kubecli.KubevirtClient, logsdi
}
func (r *KubernetesReporter) logVMICommands(virtCli kubecli.KubevirtClient, vmiNamespaces []string) {
+ runningVMIs := getRunningVMIs(virtCli, vmiNamespaces)
- logsdir := filepath.Join(r.artifactsDir, "network", "vmis")
- if err := os.MkdirAll(logsdir, 0777); err != nil {
- fmt.Fprintf(os.Stderr, failedCreateDirectoryFmt, err)
+ if len(runningVMIs) < 1 {
return
}
- for _, ns := range vmiNamespaces {
- vmis, err := virtCli.VirtualMachineInstance(ns).List(&metav1.ListOptions{})
- if err != nil {
- fmt.Fprintf(os.Stderr, "failed to get vmis: %v\n", err)
- continue
- }
-
- for _, vmi := range vmis.Items {
- if vmi.Status.Phase != "Running" {
- fmt.Fprintf(os.Stderr, "skipping vmi %s, phase is not Running\n", vmi.ObjectMeta.Name)
- continue
+ logsDir := filepath.Join(r.artifactsDir, "network", "vmis")
+ if err := os.MkdirAll(logsDir, 0777); err != nil {
+ fmt.Fprintf(os.Stderr, failedCreateDirectoryFmt, err)
+ return
}
+ for _, vmi := range runningVMIs {
vmiType, err := getVmiType(vmi)
if err != nil {
- fmt.Fprintf(os.Stderr, "failed to get vmi type: %v\n", err)
- continue
- }
-
- if err := prepareVmiConsole(vmi, vmiType); err != nil {
- fmt.Fprintf(os.Stderr, "failed to login to vmi: %v\n", err)
+ fmt.Fprintf(os.Stderr, "skipping vmi %s/%s: failed to get vmi type: %v\n", vmi.Namespace, vmi.Name, err)
continue
}
- r.executeVMICommands(vmi, logsdir, vmiType)
- }
+ r.executeVMICommands(vmi, logsDir, vmiType)
}
}
@@ -812,6 +799,18 @@ func getRunningVMIs(virtCli kubecli.KubevirtClient, namespace []string) []v12.Vi
continue
}
+ isPaused := false
+ for _, cond := range vmi.Status.Conditions {
+ if cond.Type == v12.VirtualMachineInstancePaused && cond.Status == v1.ConditionTrue {
+ isPaused = true
+ break
+ }
+ }
+ if isPaused {
+ fmt.Fprintf(os.Stderr, "skipping paused vmi %s\n", vmi.ObjectMeta.Name)
+ continue
+ }
+
vmiType, err := getVmiType(vmi)
if err != nil {
fmt.Fprintf(os.Stderr, "skipping vmi %s/%s: failed to get vmi type: %v\n", vmi.Namespace, vmi.Name, err)
