Skip to content

Commit f11834b

Browse files
committed
Test kubevirt_vmi_number_of_outdated
Test kubevirt_vmi_number_of_outdated metric.
1 parent 8ea4f4a commit f11834b

5 files changed

Lines changed: 74 additions & 2 deletions

File tree

tests/observability/conftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
VIRT_OPERATOR,
1515
)
1616
from utilities.hco import ResourceEditorValidateHCOReconcile, get_installed_hco_csv
17-
from utilities.infra import get_deployment_by_name, scale_deployment_replicas
18-
from utilities.virt import get_all_virt_pods_with_running_status
17+
from utilities.infra import get_deployment_by_name, get_node_selector_dict, scale_deployment_replicas
18+
from utilities.virt import VirtualMachineForTests, fedora_vm_body, get_all_virt_pods_with_running_status, running_vm
1919

2020
LOGGER = logging.getLogger(__name__)
2121
ANNOTATIONS_FOR_VIRT_OPERATOR_ENDPOINT = {
@@ -112,3 +112,16 @@ def initial_virt_operator_replicas_reverted(prometheus, initial_virt_operator_re
112112
validate_initial_virt_operator_replicas_reverted(
113113
prometheus=prometheus, initial_virt_operator_replicas=initial_virt_operator_replicas
114114
)
115+
116+
117+
@pytest.fixture()
118+
def vm_with_node_selector_for_upgrade(namespace, worker_node1):
119+
name = "vm-with-node-selector"
120+
with VirtualMachineForTests(
121+
name=name,
122+
namespace=namespace.name,
123+
body=fedora_vm_body(name=name),
124+
node_selector=get_node_selector_dict(node_selector=worker_node1.name),
125+
) as vm:
126+
running_vm(vm=vm)
127+
yield vm

tests/observability/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
SSP_HIGH_RATE_REJECTED_VMS = "SSPHighRateRejectedVms"
33
BAD_HTTPGET_PATH = "/metrics-fake"
44
SSP_COMMON_TEMPLATES_MODIFICATION_REVERTED = "SSPCommonTemplatesModificationReverted"
5+
KUBEVIRT_VMI_NUMBER_OF_OUTDATED = "kubevirt_vmi_number_of_outdated"
56
VIRT_ALERTS_LIST = [
67
"VirtOperatorDown",
78
"NoReadyVirtOperator",

tests/observability/upgrade/__init__.py

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
3+
from tests.observability.constants import KUBEVIRT_VMI_NUMBER_OF_OUTDATED
4+
from tests.observability.utils import validate_metrics_value, wait_for_greater_than_zero_metric_value
5+
from tests.upgrade_params import IUO_UPGRADE_TEST_DEPENDENCY_NODE_ID
6+
from utilities.constants import DEPENDENCY_SCOPE_SESSION
7+
8+
9+
@pytest.mark.upgrade
10+
class TestUpgradeObservability:
11+
TEST_METRIC_KUBEVIRT_VMI_NUMBER_OF_OUTDATED_BEFORE_UPGRADE = (
12+
"test_metric_kubevirt_vmi_number_of_outdated_before_upgrade"
13+
)
14+
"""Pre-upgrade tests"""
15+
16+
@pytest.mark.order(before=IUO_UPGRADE_TEST_DEPENDENCY_NODE_ID)
17+
@pytest.mark.dependency(name=TEST_METRIC_KUBEVIRT_VMI_NUMBER_OF_OUTDATED_BEFORE_UPGRADE)
18+
@pytest.mark.polarion("CNV-11749")
19+
def test_metric_kubevirt_vmi_number_of_outdated_before_upgrade(self, prometheus, vm_with_node_selector_for_upgrade):
20+
validate_metrics_value(
21+
prometheus=prometheus,
22+
metric_name=KUBEVIRT_VMI_NUMBER_OF_OUTDATED,
23+
expected_value="0",
24+
)
25+
26+
"""Post-upgrade tests"""
27+
28+
@pytest.mark.polarion("CNV-11758")
29+
@pytest.mark.order(after=IUO_UPGRADE_TEST_DEPENDENCY_NODE_ID)
30+
@pytest.mark.dependency(
31+
depends=[IUO_UPGRADE_TEST_DEPENDENCY_NODE_ID, TEST_METRIC_KUBEVIRT_VMI_NUMBER_OF_OUTDATED_BEFORE_UPGRADE],
32+
scope=DEPENDENCY_SCOPE_SESSION,
33+
)
34+
def test_metric_kubevirt_vmi_number_of_outdated_after_upgrade(self, prometheus):
35+
wait_for_greater_than_zero_metric_value(
36+
prometheus=prometheus,
37+
metric_name=KUBEVIRT_VMI_NUMBER_OF_OUTDATED,
38+
)

tests/observability/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
from tests.observability.constants import SSP_COMMON_TEMPLATES_MODIFICATION_REVERTED
1010
from utilities.constants import (
1111
TIMEOUT_4MIN,
12+
TIMEOUT_5MIN,
1213
TIMEOUT_15SEC,
14+
TIMEOUT_30SEC,
1315
)
1416
from utilities.monitoring import get_metrics_value
1517

@@ -62,3 +64,21 @@ def get_olm_namespace() -> Namespace:
6264
if olm_ns.exists:
6365
return olm_ns
6466
raise ResourceNotFoundError(f"Namespace: {olm_ns.name} not found.")
67+
68+
69+
def wait_for_greater_than_zero_metric_value(prometheus: Prometheus, metric_name: str) -> None:
70+
samples = TimeoutSampler(
71+
wait_timeout=TIMEOUT_5MIN,
72+
sleep=TIMEOUT_30SEC,
73+
func=get_metrics_value,
74+
prometheus=prometheus,
75+
metrics_name=metric_name,
76+
)
77+
sample = None
78+
try:
79+
for sample in samples:
80+
if sample and int(sample) > 0:
81+
return
82+
except TimeoutExpiredError:
83+
LOGGER.info(f"Metric value of: {metric_name} is: {sample}, expected value: non zero")
84+
raise

0 commit comments

Comments
 (0)