Skip to content

Commit

Permalink
Merge pull request #1122 from machadovilaca/CNV-47434
Browse files Browse the repository at this point in the history
Fix flaky test fire VMStorageClassWarning when rxbounce is disabled
  • Loading branch information
kubevirt-bot authored Nov 11, 2024
2 parents 5adbc74 + 79e2887 commit 9c0734a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
32 changes: 19 additions & 13 deletions tests/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"gomodules.xyz/jsonpatch/v2"

routev1 "github.com/openshift/api/route/v1"
templatev1 "github.com/openshift/api/template/v1"
promApi "github.com/prometheus/client_golang/api"
Expand Down Expand Up @@ -247,6 +249,16 @@ var _ = Describe("Prometheus Alerts", func() {
var createResources = func(createDataVolume bool, rxbounceEnabled bool) string {
vmName := fmt.Sprintf("testvmi-%v", rand.String(10))

vmi := NewMinimalVMIWithNS(strategy.GetNamespace(), vmName)
vm = NewVirtualMachine(vmi)
vm.Spec.RunStrategy = ptr.To(kubevirtv1.RunStrategyAlways)
vm.Spec.Template.ObjectMeta.Annotations = map[string]string{
"vm.kubevirt.io/os": "windows-10",
}

eventuallyCreateVm(vm)
waitForSeriesToBeDetected(fmt.Sprintf("kubevirt_vmi_info{name='%s', os='windows-10'} == 1", vmi.Name))

var volumes []kubevirtv1.Volume

if createDataVolume {
Expand All @@ -261,13 +273,10 @@ var _ = Describe("Prometheus Alerts", func() {
})
}

vmi := NewMinimalVMIWithNS(strategy.GetNamespace(), vmName)
vmi.Spec = kubevirtv1.VirtualMachineInstanceSpec{
Volumes: volumes,
}
vm = NewVirtualMachine(vmi)
vm.Spec.Running = ptr.To(false)
eventuallyCreateVm(vm)
operation := jsonpatch.NewOperation("add", "/spec/template/spec/volumes", volumes)
patch := encodePatch([]jsonpatch.Operation{operation})
err := apiClient.Patch(ctx, vm, patch)
Expect(err).NotTo(HaveOccurred())

return vmName
}
Expand All @@ -278,10 +287,7 @@ var _ = Describe("Prometheus Alerts", func() {
alertShouldNotBeActive("VMStorageClassWarning")
})

// This test is flaky and fails too often.
//
// TODO: GitHub issue: https://github.com/kubevirt/ssp-operator/issues/889
PIt("[test_id:10549] Should fire VMStorageClassWarning when rxbounce is disabled", func() {
It("[test_id:10549] Should fire VMStorageClassWarning when rxbounce is disabled", func() {
vmName := createResources(true, false)
waitForSeriesToBeDetected(fmt.Sprintf("kubevirt_ssp_vm_rbd_block_volume_without_rxbounce{name='%s'} == 1", vmName))
waitForAlertToActivate("VMStorageClassWarning")
Expand All @@ -290,8 +296,8 @@ var _ = Describe("Prometheus Alerts", func() {
Expect(err).ToNot(HaveOccurred())

Eventually(func(g Gomega) error {
return apiClient.Get(ctx, types.NamespacedName{Name: vmName, Namespace: strategy.GetNamespace()}, vm)
}, 10*time.Second, time.Second).Should(MatchError(k8serrors.IsNotFound, "IsNotFound"))
return apiClient.Get(ctx, types.NamespacedName{Name: vm.Name, Namespace: vm.Namespace}, vm)
}, 1*time.Minute, 5*time.Second).Should(MatchError(k8serrors.IsNotFound, "IsNotFound"))

waitForSeriesToBeDetected(fmt.Sprintf("kubevirt_ssp_vm_rbd_block_volume_without_rxbounce{name='%s'} == 0", vmName))
alertShouldNotBeActive("VMStorageClassWarning")
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/utils/ptr"
kubevirtv1 "kubevirt.io/api/core/v1"
"kubevirt.io/controller-lifecycle-operator-sdk/api"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -362,7 +363,6 @@ func NewMinimalVMIWithNS(namespace, name string) *kubevirtv1.VirtualMachineInsta
}

func NewVirtualMachine(vmi *kubevirtv1.VirtualMachineInstance) *kubevirtv1.VirtualMachine {
running := false
name := vmi.Name
namespace := vmi.Namespace
vm := &kubevirtv1.VirtualMachine{
Expand All @@ -371,7 +371,7 @@ func NewVirtualMachine(vmi *kubevirtv1.VirtualMachineInstance) *kubevirtv1.Virtu
Namespace: namespace,
},
Spec: kubevirtv1.VirtualMachineSpec{
Running: &running,
RunStrategy: ptr.To(kubevirtv1.RunStrategyHalted),
Template: &kubevirtv1.VirtualMachineInstanceTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"kubevirt.io/vm": name},
Expand Down

0 comments on commit 9c0734a

Please sign in to comment.