Skip to content

Adding windows vms for testing network metrics #584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
771ff0d
Adding windows vms for testing network metrics
OhadRevah Mar 25, 2025
8a274a5
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Apr 6, 2025
44f11bb
Changed windows_for_test to deploy win11 with instanceType
OhadRevah Apr 9, 2025
fb02d84
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Apr 9, 2025
94c4b80
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 9, 2025
b061fc0
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Apr 27, 2025
fb063e4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 27, 2025
53a4b52
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Apr 27, 2025
ef2e2c4
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Apr 29, 2025
830bc60
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 4, 2025
86ceb9a
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 5, 2025
e1a7ca6
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 18, 2025
9009b28
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 20, 2025
c319678
Added tier3 mareker to windows test.
OhadRevah May 20, 2025
0fc94d7
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 20, 2025
c11e8a0
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 21, 2025
ac2e4e2
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 21, 2025
d2471ee
Updated error message for validate_vmi_network_receive_and_transmit_p…
OhadRevah May 21, 2025
1dbebae
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 21, 2025
5c8c2ea
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 21, 2025
3b84607
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 22, 2025
2238a0f
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 27, 2025
af011b2
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 29, 2025
430804c
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah May 29, 2025
48f097c
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 3, 2025
0eef3d8
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 3, 2025
1a56ef7
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 4, 2025
e8c9348
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 4, 2025
01ee037
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2025
994eb3d
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 4, 2025
f74f91d
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 4, 2025
648d7b7
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 5, 2025
482bece
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 5, 2025
052aeda
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 5, 2025
0876da9
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 8, 2025
45399d3
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 9, 2025
23c7f60
Merge branch 'main' into addingWindowsVmsToNetworkMetrics
OhadRevah Jun 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions tests/observability/metrics/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
disk_file_system_info,
enable_swap_fedora_vm,
fail_if_not_zero_restartcount,
get_interface_name_from_vm,
get_metric_sum_value,
get_mutation_component_value_from_prometheus,
get_not_running_prometheus_pods,
Expand All @@ -67,6 +68,7 @@
CDI_UPLOAD_TMP_PVC,
CLUSTER_NETWORK_ADDONS_OPERATOR,
COUNT_FIVE,
IPV4_STR,
KUBEVIRT_VMI_MEMORY_DOMAIN_BYTES,
KUBEVIRT_VMI_MEMORY_PGMAJFAULT_TOTAL,
KUBEVIRT_VMI_MEMORY_PGMINFAULT_TOTAL,
Expand Down Expand Up @@ -108,6 +110,7 @@
unique_name,
)
from utilities.monitoring import get_metrics_value
from utilities.network import get_ip_from_vm_or_virt_handler_pod, ping
from utilities.ssp import verify_ssp_pod_is_running
from utilities.storage import (
create_dv,
Expand Down Expand Up @@ -674,13 +677,23 @@ def generated_network_traffic(vm_for_test):
run_vm_commands(vms=[vm_for_test], commands=[f"ping -c 20 {vm_for_test.privileged_vmi.interfaces[0]['ipAddress']}"])


@pytest.fixture(scope="class")
def vm_for_test_interface_name(vm_for_test):
interface_name = vm_for_test.privileged_vmi.virt_launcher_pod.execute(
command=shlex.split("bash -c \"virsh domiflist 1 | grep ethernet | awk '{print $1}'\"")
@pytest.fixture()
def generated_network_traffic_windows_vm(windows_vm_for_test):
ping(
src_vm=windows_vm_for_test,
dst_ip=get_ip_from_vm_or_virt_handler_pod(family=IPV4_STR, vm=windows_vm_for_test),
windows=True,
)
assert interface_name, f"Interface not found for vm {vm_for_test.name}"
return interface_name


@pytest.fixture(scope="class")
def linux_vm_for_test_interface_name(vm_for_test):
return get_interface_name_from_vm(vm=vm_for_test)


@pytest.fixture(scope="class")
def windows_vm_for_test_interface_name(windows_vm_for_test):
return get_interface_name_from_vm(vm=windows_vm_for_test)


@pytest.fixture(scope="class")
Expand Down
3 changes: 3 additions & 0 deletions tests/observability/metrics/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@
KUBEVIRT_VMSNAPSHOT_PERSISTENTVOLUMECLAIM_LABELS = (
"kubevirt_vmsnapshot_persistentvolumeclaim_labels{{vm_name='{vm_name}'}}"
)
KUBEVIRT_VMI_NETWORK_RECEIVE_PACKETS_TOTAL = "kubevirt_vmi_network_receive_packets_total"
KUBEVIRT_VMI_NETWORK_TRANSMIT_PACKETS_TOTAL = "kubevirt_vmi_network_transmit_packets_total"
KUBEVIRT_VMI_MIGRATIONS_IN_SCHEDULING_PHASE = "kubevirt_vmi_migrations_in_scheduling_phase"
KUBEVIRT_VMI_MIGRATIONS_IN_RUNNING_PHASE = "kubevirt_vmi_migrations_in_running_phase"
KUBEVIRT_VMI_MIGRATION_DATA_TOTAL_BYTES = "kubevirt_vmi_migration_data_total_bytes{{name='{vm_name}'}}"

BINDING_NAME = "binding_name"
BINDING_TYPE = "binding_type"
RSS_MEMORY_COMMAND = shlex.split("bash -c \"cat /sys/fs/cgroup/memory.stat | grep '^anon ' | awk '{print $2}'\"")
67 changes: 59 additions & 8 deletions tests/observability/metrics/test_network_metrics.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import pytest

from tests.observability.metrics.constants import (
KUBEVIRT_VMI_NETWORK_RECEIVE_PACKETS_TOTAL,
KUBEVIRT_VMI_NETWORK_TRANSMIT_PACKETS_TOTAL,
)
from tests.observability.metrics.utils import (
validate_network_traffic_metrics_value,
validate_vmi_network_receive_and_transmit_packets_total,
)

RX_PACKETS_METRIC = {"metric_name": KUBEVIRT_VMI_NETWORK_RECEIVE_PACKETS_TOTAL, "packets_kind": "rx_packets"}
TX_PACKETS_METRIC = {"metric_name": KUBEVIRT_VMI_NETWORK_TRANSMIT_PACKETS_TOTAL, "packets_kind": "tx_packets"}


@pytest.mark.parametrize(
"vm_for_test",
Expand All @@ -15,35 +22,79 @@
],
indirect=True,
)
@pytest.mark.usefixtures("vm_for_test", "vm_for_test_interface_name")
class TestVmiNetworkMetrics:
@pytest.mark.usefixtures("vm_for_test", "linux_vm_for_test_interface_name")
class TestVmiNetworkMetricsLinux:
@pytest.mark.parametrize(
"metric_dict",
[
pytest.param(
{"metric_name": "kubevirt_vmi_network_receive_packets_total", "packets_kind": "rx_packets"},
RX_PACKETS_METRIC,
marks=(pytest.mark.polarion("CNV-11176")),
),
pytest.param(
{"metric_name": "kubevirt_vmi_network_transmit_packets_total", "packets_kind": "tx_packets"},
TX_PACKETS_METRIC,
marks=(pytest.mark.polarion("CNV-11220")),
),
],
indirect=False,
)
def test_kubevirt_vmi_network_receive_and_transmit_packets_total(
self, prometheus, metric_dict, vm_for_test, vm_for_test_interface_name, generated_network_traffic
self, prometheus, metric_dict, vm_for_test, linux_vm_for_test_interface_name, generated_network_traffic
):
validate_vmi_network_receive_and_transmit_packets_total(
metric_dict=metric_dict, vm=vm_for_test, vm_interface_name=vm_for_test_interface_name, prometheus=prometheus
metric_dict=metric_dict,
vm=vm_for_test,
vm_interface_name=linux_vm_for_test_interface_name,
prometheus=prometheus,
)

@pytest.mark.polarion("CNV-11177")
def test_kubevirt_vmi_network_traffic_bytes_total(
self, prometheus, vm_for_test, vm_for_test_interface_name, generated_network_traffic
self, prometheus, vm_for_test, linux_vm_for_test_interface_name, generated_network_traffic
):
validate_network_traffic_metrics_value(
prometheus=prometheus,
vm=vm_for_test,
interface_name=vm_for_test_interface_name,
interface_name=linux_vm_for_test_interface_name,
)


@pytest.mark.tier3
class TestVmiNetworkMetricsWindows:
@pytest.mark.parametrize(
"metric_dict",
[
pytest.param(
RX_PACKETS_METRIC,
marks=(pytest.mark.polarion("CNV-11843")),
),
pytest.param(
TX_PACKETS_METRIC,
marks=(pytest.mark.polarion("CNV-11844")),
),
],
)
def test_kubevirt_vmi_network_receive_and_transmit_packets_total_windows_vm(
self,
prometheus,
windows_vm_for_test,
windows_vm_for_test_interface_name,
generated_network_traffic_windows_vm,
metric_dict,
):
validate_vmi_network_receive_and_transmit_packets_total(
metric_dict=metric_dict,
vm=windows_vm_for_test,
vm_interface_name=windows_vm_for_test_interface_name,
prometheus=prometheus,
)

@pytest.mark.polarion("CNV-11846")
def test_kubevirt_vmi_network_traffic_bytes_total_windows_vm(
self, prometheus, windows_vm_for_test, windows_vm_for_test_interface_name, generated_network_traffic_windows_vm
):
validate_network_traffic_metrics_value(
prometheus=prometheus,
vm=windows_vm_for_test,
interface_name=windows_vm_for_test_interface_name,
)
27 changes: 18 additions & 9 deletions tests/observability/metrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,27 +1011,28 @@ def validate_vmi_network_receive_and_transmit_packets_total(
vm=vm,
interface_name=vm_interface_name,
)
sample = None
sample_value = None
packets_kind = metric_dict["packets_kind"]
metric_packets_value = None
try:
match_counter = 0
metric_packets_value = None
for sample in samples:
if sample:
metric_packets_value = (
prometheus.query(query=f"{metric_dict['metric_name']}{{name='{vm.name}'}}")
.get("data")
.get("result")[0]
.get("value")[1]
metric_packets_value = get_metrics_value(
prometheus=prometheus, metrics_name=f"{metric_dict['metric_name']}{{name='{vm.name}'}}"
)
sample_value = sample[packets_kind]
if is_domifstat_compared_prometheus_values(
domifstat_network_packets_received=int(sample[metric_dict["packets_kind"]]),
domifstat_network_packets_received=int(sample_value),
prometheus_metric_packets_value=int(metric_packets_value),
):
match_counter += 1
if match_counter > 5:
return
except TimeoutExpiredError:
LOGGER.error(f"Expected metric packets values: {sample}")
LOGGER.error(
f"Expected metric packets value for {packets_kind}: {sample_value}, actual: {metric_packets_value}"
)
raise


Expand Down Expand Up @@ -1272,6 +1273,14 @@ def validate_vnic_info(prometheus: Prometheus, vnic_info_to_compare: dict[str, s
assert not mismatch_vnic_info, f"There is a mismatch between expected and actual results:\n {mismatch_vnic_info}"


def get_interface_name_from_vm(vm: VirtualMachineForTests) -> str:
interface_name = vm.privileged_vmi.virt_launcher_pod.execute(
command=shlex.split("bash -c \"virsh domiflist 1 | grep ethernet | awk '{print $1}'\"")
)
assert interface_name, f"Interface not found for vm {vm.name}"
return interface_name


def get_metric_labels_non_empty_value(prometheus: Prometheus, metric_name: str) -> dict[str, str]:
samples = TimeoutSampler(
wait_timeout=TIMEOUT_5MIN,
Expand Down
13 changes: 12 additions & 1 deletion tests/virt/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import logging
import re
import shlex
Expand Down Expand Up @@ -33,6 +35,7 @@
)
from utilities.infra import get_pod_by_name_prefix
from utilities.virt import (
VirtualMachineForTests,
fetch_pid_from_linux_vm,
fetch_pid_from_windows_vm,
kill_processes_by_name_linux,
Expand Down Expand Up @@ -149,7 +152,15 @@ def _get_wsl2_running_status():
raise


def verify_wsl2_guest_works(vm):
def verify_wsl2_guest_works(vm: VirtualMachineForTests) -> None:
"""
Verifies that WSL2 is functioning on windows vm.
Args:
vm: An instance of `VirtualMachineForTests`
Raises:
TimeoutExpiredError: If WSL2 fails to return the expected output within
the specified timeout period.
"""
echo_string = "TEST"
samples = TimeoutSampler(
wait_timeout=TIMEOUT_1MIN,
Expand Down
18 changes: 9 additions & 9 deletions utilities/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ def cloud_init_network_data(data):
return network_data


def ping(src_vm, dst_ip, packet_size=None, count=None, quiet_output=True, interface=None):
def ping(src_vm, dst_ip, packet_size=None, count=None, quiet_output=True, interface=None, windows=False):
"""
Ping from source VM to destination IP.

Expand All @@ -733,19 +733,19 @@ def ping(src_vm, dst_ip, packet_size=None, count=None, quiet_output=True, interf
packet_size: Number of data bytes to send.
count: Amount of packets.
quiet_output: Quiet output, Nothing is displayed except the summary lines at startup time and when finished.
interface: interface (ping -I option)
interface: interface (ping -I option),
windows: bool that indicate if it is windows then the command of ping will be slight different

Returns:
float or None: The packet loss amount in a number (Range - 0 to 100).
"""
ping_ipv6 = "-6" if get_valid_ip_address(dst_ip=dst_ip, family=IPV6_STR) else ""

ping_cmd = f"ping {'-q' if quiet_output else ''} {ping_ipv6} -c {count if count else '3'} {dst_ip}"
if packet_size:
ping_cmd += f" -s {packet_size} -M do"
if interface:
ping_cmd += f" -I {interface}"

packet_size = f"-s {packet_size} -M do" if packet_size else ""
interface = f"-I {interface}" if interface else ""
ping_cmd = (
f"ping {'-q' if quiet_output else ''} {ping_ipv6} {'-n' if windows else '-c'} "
f"{count if count else '3'} {dst_ip} {packet_size} {interface}"
)
_, out, err = src_vm.ssh_exec.run_command(command=shlex.split(ping_cmd))
out_to_process = err or out
match = re.search(r"(\d*\.?\d+)%", out_to_process)
Expand Down