Skip to content

Commit 64dcc7d

Browse files
hmeirclaude
andcommitted
refactor: move validate_metrics_value to utilities/monitoring
Signed-off-by: Harel Meir <hmeir@redhat.com> Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent f64dfc7 commit 64dcc7d

15 files changed

Lines changed: 120 additions & 48 deletions

File tree

conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from utilities.bitwarden import get_cnv_tests_secret_by_name
3434
from utilities.constants import (
3535
AMD_64,
36+
MULTIARCH,
3637
QUARANTINED,
3738
SETUP_ERROR,
3839
TIMEOUT_5MIN,
@@ -558,6 +559,15 @@ def filter_sno_only_tests(items: list[Item], config: Config) -> list[Item]:
558559
return items
559560

560561

562+
def filter_multiarch_tests(items: list[Item], config: Config) -> list[Item]:
563+
if py_config.get("cluster_type") == MULTIARCH:
564+
return items
565+
discard_tests, items_to_return = remove_tests_from_list(items=items, filter_str="multiarch")
566+
if discard_tests:
567+
config.hook.pytest_deselected(items=discard_tests)
568+
return items_to_return
569+
570+
561571
def remove_tests_from_list(items: list[Item], filter_str: str) -> tuple[list[Item], list[Item]]:
562572
discard_tests: list[Item] = []
563573
items_to_return: list[Item] = []
@@ -635,6 +645,7 @@ def pytest_collection_modifyitems(session, config, items):
635645
config.hook.pytest_deselected(items=discard)
636646
items[:] = filter_deprecated_api_tests(items=items, config=config)
637647
items[:] = filter_sno_only_tests(items=items, config=config)
648+
items[:] = filter_multiarch_tests(items=items, config=config)
638649
items[:] = mark_nmstate_dependent_tests(items=items)
639650

640651

tests/install_upgrade_operators/hco_enablement_golden_image_updates/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
COMMON_TEMPLATES_KEY_NAME,
2020
FEATURE_GATES,
2121
HCO_OPERATOR,
22+
KUBERNETES_ARCH_LABEL,
2223
SSP_CR_COMMON_TEMPLATES_LIST_KEY_NAME,
2324
)
2425
from utilities.ssp import get_ssp_resource
@@ -121,6 +122,11 @@ def common_templates_scope_session(hyperconverged_status_scope_session):
121122
return hyperconverged_status_scope_session[SSP_CR_COMMON_TEMPLATES_LIST_KEY_NAME]
122123

123124

125+
@pytest.fixture(scope="session")
126+
def worker_architectures(schedulable_nodes):
127+
return {node.labels[KUBERNETES_ARCH_LABEL] for node in schedulable_nodes}
128+
129+
124130
@pytest.fixture(scope="class")
125131
def default_common_template_hco_status(hyperconverged_status_templates_scope_class):
126132
return get_templates_by_type_from_hco_status(

tests/install_upgrade_operators/hco_enablement_golden_image_updates/multiarch/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ def enabled_multiarch_feature_gate(hyperconverged_resource_scope_class):
5656
yield
5757

5858

59-
@pytest.fixture(scope="session")
60-
def worker_architectures(schedulable_nodes):
61-
return {node.labels[KUBERNETES_ARCH_LABEL] for node in schedulable_nodes}
62-
63-
6459
@pytest.fixture(scope="class")
6560
def control_plane_architecture(control_plane_nodes):
6661
return get_control_plane_architecture(control_plane_nodes=control_plane_nodes)

tests/install_upgrade_operators/hco_enablement_golden_image_updates/multiarch/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ def get_modified_data_import_cron_template(
4545
managed_data_source: str,
4646
annotations: dict[str, str] | None = None,
4747
) -> dict[str, Any]:
48+
"""Clone the first common template and customize it for testing.
49+
50+
Args:
51+
common_templates: HCO status templates; first entry is used as base.
52+
name: New template name.
53+
managed_data_source: DataSource name to associate with this cron.
54+
annotations: Optional annotations to merge into metadata.
55+
56+
Returns:
57+
dict[str, Any]: Modified template with status removed, name and datasource updated.
58+
"""
4859
template = deepcopy(common_templates[0])
4960
del template["status"]
5061
template["metadata"]["name"] = name
@@ -55,6 +66,7 @@ def get_modified_data_import_cron_template(
5566

5667

5768
def get_unsupported_arch_template(common_templates: list[dict[str, Any]]) -> dict[str, Any]:
69+
"""Return a template annotated with an unsupported architecture (arm42)."""
5870
return get_modified_data_import_cron_template(
5971
common_templates=common_templates,
6072
name=CUSTOM_UNSUPPORTED_ARCH_CRON_NAME,
@@ -64,6 +76,7 @@ def get_unsupported_arch_template(common_templates: list[dict[str, Any]]) -> dic
6476

6577

6678
def get_no_arch_annotation_template(common_templates: list[dict[str, Any]]) -> dict[str, Any]:
79+
"""Return a template with the architecture annotation removed."""
6780
template = get_modified_data_import_cron_template(
6881
common_templates=common_templates,
6982
name=CUSTOM_NO_ARCH_ANNOTATION_CRON_NAME,

tests/observability/metrics/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
network_packets_received,
3737
vnic_info_from_vm_or_vmi,
3838
)
39-
from tests.observability.utils import validate_metrics_value
4039
from tests.utils import create_vms, start_stress_on_vm
4140
from utilities import console
4241
from utilities.constants import (
@@ -72,7 +71,7 @@
7271
get_pod_by_name_prefix,
7372
unique_name,
7473
)
75-
from utilities.monitoring import get_metrics_value
74+
from utilities.monitoring import get_metrics_value, validate_metrics_value
7675
from utilities.network import assert_ping_successful, get_ip_from_vm_or_virt_handler_pod, ping
7776
from utilities.ssp import verify_ssp_pod_is_running
7877
from utilities.storage import (

tests/observability/metrics/test_aaq_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
timestamp_to_seconds,
55
validate_values_from_kube_application_aware_resourcequota_metric,
66
)
7-
from tests.observability.utils import validate_metrics_value
7+
from utilities.monitoring import validate_metrics_value
88

99
pytestmark = [
1010
pytest.mark.usefixtures(

tests/observability/metrics/test_general_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from libs.net.cluster import is_ipv6_single_stack_cluster
88
from tests.observability.metrics.constants import KUBEVIRT_VMI_NODE_CPU_AFFINITY
99
from tests.observability.metrics.utils import validate_vmi_node_cpu_affinity_with_prometheus
10-
from tests.observability.utils import validate_metrics_value
10+
from utilities.monitoring import validate_metrics_value
1111
from utilities.virt import VirtualMachineForTests, fedora_vm_body, running_vm
1212

1313
KUBEVIRT_VM_TAG = f"{Resource.ApiGroup.KUBEVIRT_IO}/vm"

tests/observability/metrics/test_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
assert_vm_metric_virt_handler_pod,
1010
compare_kubevirt_vmi_info_metric_with_vm_info,
1111
)
12-
from tests.observability.utils import validate_metrics_value
1312
from utilities.constants import (
1413
KUBEVIRT_HCO_HYPERCONVERGED_CR_EXISTS,
1514
)
15+
from utilities.monitoring import validate_metrics_value
1616

1717
pytestmark = [pytest.mark.post_upgrade, pytest.mark.sno]
1818

tests/observability/metrics/test_migration_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
timestamp_to_seconds,
1414
wait_for_non_empty_metrics_value,
1515
)
16-
from tests.observability.utils import validate_metrics_value
16+
from utilities.monitoring import validate_metrics_value
1717

1818
LOGGER = logging.getLogger(__name__)
1919

tests/observability/metrics/test_ssp_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
validate_metric_value_with_round_down,
88
validate_metric_value_within_range,
99
)
10-
from tests.observability.utils import validate_metrics_value
1110
from utilities.constants import (
1211
SSP_OPERATOR,
1312
VIRT_TEMPLATE_VALIDATOR,
1413
)
1514
from utilities.hco import ResourceEditorValidateHCOReconcile
15+
from utilities.monitoring import validate_metrics_value
1616
from utilities.virt import VirtualMachineForTests
1717

1818
KUBEVIRT_SSP_OPERATOR_UP = "kubevirt_ssp_operator_up"

0 commit comments

Comments
 (0)