diff --git a/tests/monitoring_test.go b/tests/monitoring_test.go index 949137699..c3266053c 100644 --- a/tests/monitoring_test.go +++ b/tests/monitoring_test.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "fmt" + "gomodules.xyz/jsonpatch/v2" "net" "net/http" "time" @@ -24,7 +25,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/rand" - "k8s.io/utils/ptr" kubevirtv1 "kubevirt.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -247,6 +247,19 @@ 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) + + var always = kubevirtv1.RunStrategyAlways + vm.Spec.RunStrategy = &always + + 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 { @@ -261,13 +274,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 } @@ -278,10 +288,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") @@ -290,8 +297,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")