Skip to content

Commit 8eb3a2b

Browse files
authored
CherryPicked: [cnv-4.20] Remove Artifactory dependency from CPU affinity test (RedHatQE#3247)
The test for kubevirt_vmi_node_cpu_affinity is flaky duo to connectivity issues with the artifactory, in this PR I modified the test to not rely on the artifactory to avoid this kind of failures to stabilize the observability lanes. https://issues.redhat.com/browse/CNV-75209 ##### Short description: ##### More details: ##### What this PR does / why we need it: ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: ##### jira-ticket: <!-- full-ticket-url needs to be provided. This would add a link to the pull request to the jira and close it when the pull request is merged If the task is not tracked by a Jira ticket, just write "NONE". -->
1 parent f2d528d commit 8eb3a2b

File tree

4 files changed

+26
-42
lines changed

4 files changed

+26
-42
lines changed

tests/conftest.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,22 +2350,6 @@ def rhel_vm_with_instance_type_and_preference(
23502350
yield vm
23512351

23522352

2353-
@pytest.fixture(scope="class")
2354-
def vm_from_template_scope_class(
2355-
request,
2356-
unprivileged_client,
2357-
namespace,
2358-
golden_image_data_source_scope_class,
2359-
):
2360-
with vm_instance_from_template(
2361-
request=request,
2362-
unprivileged_client=unprivileged_client,
2363-
namespace=namespace,
2364-
data_source=golden_image_data_source_scope_class,
2365-
) as vm:
2366-
yield vm
2367-
2368-
23692353
@pytest.fixture(scope="session")
23702354
def is_disconnected_cluster():
23712355
# To enable disconnected_cluster pass --tc=disconnected_cluster:True to pytest commandline.

tests/observability/metrics/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,16 @@ def aaq_resource_hard_limit_and_used(application_aware_resource_quota):
578578
for key, value in resource_used.items()
579579
}
580580
return formatted_hard_limit, formatted_used_value
581+
582+
583+
@pytest.fixture(scope="class")
584+
def expected_cpu_affinity_metric_value(vm_with_cpu_spec):
585+
"""Calculate expected kubevirt_vmi_node_cpu_affinity metric value."""
586+
# Calculate VM CPU count
587+
vm_cpu = vm_with_cpu_spec.vmi.instance.spec.domain.cpu
588+
cpu_count_from_vm = (vm_cpu.threads or 1) * (vm_cpu.cores or 1) * (vm_cpu.sockets or 1)
589+
# Get node CPU capacity
590+
cpu_count_from_vm_node = int(vm_with_cpu_spec.privileged_vmi.node.instance.status.capacity.cpu)
591+
592+
# return multiplication for multi-CPU VMs
593+
return str(cpu_count_from_vm_node * cpu_count_from_vm)

tests/observability/metrics/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@
3030
)
3131
BINDING_NAME = "binding_name"
3232
BINDING_TYPE = "binding_type"
33+
34+
KUBEVIRT_VMI_NODE_CPU_AFFINITY = "kubevirt_vmi_node_cpu_affinity{{kubernetes_vmi_label_kubevirt_io_domain='{vm_name}'}}"

tests/observability/metrics/test_general_metrics.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import pytest
44
from ocp_resources.resource import Resource
55
from ocp_resources.virtual_machine import VirtualMachine
6-
from pytest_testconfig import config as py_config
76

7+
from tests.observability.metrics.constants import KUBEVIRT_VMI_NODE_CPU_AFFINITY
88
from tests.observability.metrics.utils import (
99
validate_vmi_node_cpu_affinity_with_prometheus,
1010
)
1111
from tests.observability.utils import validate_metrics_value
12-
from tests.os_params import RHEL_LATEST, RHEL_LATEST_LABELS, RHEL_LATEST_OS
1312
from utilities.virt import VirtualMachineForTests, fedora_vm_body, running_vm
1413

1514
KUBEVIRT_VM_TAG = f"{Resource.ApiGroup.KUBEVIRT_IO}/vm"
@@ -41,37 +40,23 @@ def fedora_vm_without_name_in_label(
4140
client=unprivileged_client,
4241
run_strategy=VirtualMachine.RunStrategy.ALWAYS,
4342
) as vm:
44-
running_vm(vm=vm, check_ssh_connectivity=False)
43+
running_vm(vm=vm, wait_for_interfaces=False, check_ssh_connectivity=False)
4544
yield vm
4645

4746

4847
class TestVmiNodeCpuAffinityLinux:
49-
@pytest.mark.parametrize(
50-
"golden_image_data_volume_scope_class, vm_from_template_scope_class",
51-
[
52-
pytest.param(
53-
{
54-
"dv_name": RHEL_LATEST_OS,
55-
"image": RHEL_LATEST["image_path"],
56-
"storage_class": py_config["default_storage_class"],
57-
"dv_size": RHEL_LATEST["dv_size"],
58-
},
59-
{
60-
"vm_name": "rhel-latest",
61-
"template_labels": RHEL_LATEST_LABELS,
62-
"guest_agent": False,
63-
"ssh": False,
64-
},
65-
),
66-
],
67-
indirect=True,
68-
)
6948
@pytest.mark.polarion("CNV-7295")
7049
@pytest.mark.s390x
71-
def test_kubevirt_vmi_node_cpu_affinity(self, prometheus, vm_from_template_scope_class):
72-
validate_vmi_node_cpu_affinity_with_prometheus(
73-
vm=vm_from_template_scope_class,
50+
def test_kubevirt_vmi_node_cpu_affinity(
51+
self,
52+
prometheus,
53+
vm_with_cpu_spec,
54+
expected_cpu_affinity_metric_value,
55+
):
56+
validate_metrics_value(
7457
prometheus=prometheus,
58+
metric_name=KUBEVIRT_VMI_NODE_CPU_AFFINITY.format(vm_name=vm_with_cpu_spec.name),
59+
expected_value=expected_cpu_affinity_metric_value,
7560
)
7661

7762

0 commit comments

Comments
 (0)