Skip to content

Commit 5bd5ec2

Browse files
committed
CherryPicked: [cnv-4.20] Modify windows vm deployment to include virtio
Modify the fixture for creating windows vm to include virtio and wsl original PR: RedHatQE#3303
1 parent ce14de0 commit 5bd5ec2

File tree

3 files changed

+71
-51
lines changed

3 files changed

+71
-51
lines changed

tests/observability/metrics/conftest.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
get_vm_comparison_info_dict,
3535
get_vmi_guest_os_kernel_release_info_metric_from_vm,
3636
metric_result_output_dict_by_mountpoint,
37+
network_packets_received,
3738
vnic_info_from_vm_or_vmi,
3839
)
3940
from tests.observability.utils import validate_metrics_value
@@ -233,17 +234,30 @@ def generated_network_traffic_windows_vm(windows_vm_for_test):
233234
src_vm=windows_vm_for_test,
234235
dst_ip=get_ip_from_vm_or_virt_handler_pod(family=IPV4_STR, vm=windows_vm_for_test),
235236
windows=True,
237+
quiet_output=False,
236238
)
237239

238240

239241
@pytest.fixture(scope="class")
240242
def linux_vm_for_test_interface_name(vm_for_test):
241-
return vm_for_test.vmi.interfaces[0].interfaceName
243+
return vm_for_test.vmi.interfaces[0].podInterfaceName
242244

243245

244246
@pytest.fixture(scope="class")
245247
def windows_vm_for_test_interface_name(windows_vm_for_test):
246-
return windows_vm_for_test.vmi.interfaces[0].interfaceName
248+
return windows_vm_for_test.vmi.interfaces[0].podInterfaceName
249+
250+
251+
@pytest.fixture()
252+
def network_packet_received_windows_vm(windows_vm_for_test, windows_vm_for_test_interface_name):
253+
return network_packets_received(
254+
vm=windows_vm_for_test, interface_name=windows_vm_for_test_interface_name, windows_wsl=True
255+
)
256+
257+
258+
@pytest.fixture()
259+
def network_packet_received_linux_vm(vm_for_test, linux_vm_for_test_interface_name):
260+
return network_packets_received(vm=vm_for_test, interface_name=linux_vm_for_test_interface_name)
247261

248262

249263
@pytest.fixture(scope="class")

tests/observability/metrics/test_network_metrics.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,31 @@ class TestVmiNetworkMetricsLinux:
1717
@pytest.mark.polarion("CNV-11177")
1818
@pytest.mark.s390x
1919
def test_kubevirt_vmi_network_traffic_bytes_total(
20-
self, prometheus, vm_for_test, linux_vm_for_test_interface_name, generated_network_traffic
20+
self,
21+
prometheus,
22+
vm_for_test,
23+
linux_vm_for_test_interface_name,
24+
generated_network_traffic,
25+
network_packet_received_linux_vm,
2126
):
2227
validate_network_traffic_metrics_value(
2328
prometheus=prometheus,
2429
vm=vm_for_test,
25-
interface_name=linux_vm_for_test_interface_name,
30+
network_packet_received=network_packet_received_linux_vm,
2631
)
2732

2833

2934
@pytest.mark.tier3
3035
class TestVmiNetworkMetricsWindows:
3136
@pytest.mark.polarion("CNV-11846")
3237
def test_kubevirt_vmi_network_traffic_bytes_total_windows_vm(
33-
self, prometheus, windows_vm_for_test, windows_vm_for_test_interface_name, generated_network_traffic_windows_vm
38+
self,
39+
prometheus,
40+
windows_vm_for_test,
41+
windows_vm_for_test_interface_name,
42+
generated_network_traffic_windows_vm,
43+
network_packet_received_windows_vm,
3444
):
3545
validate_network_traffic_metrics_value(
36-
prometheus=prometheus,
37-
vm=windows_vm_for_test,
38-
interface_name=windows_vm_for_test_interface_name,
46+
prometheus=prometheus, vm=windows_vm_for_test, network_packet_received=network_packet_received_windows_vm
3947
)

tests/observability/metrics/utils.py

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import math
33
import re
44
import shlex
5-
import time
65
import urllib
76
from contextlib import contextmanager
87
from datetime import datetime, timezone
@@ -31,6 +30,7 @@
3130
CAPACITY,
3231
NODE_STR,
3332
OS_FLAVOR_WINDOWS,
33+
REGISTRY_STR,
3434
TIMEOUT_1MIN,
3535
TIMEOUT_2MIN,
3636
TIMEOUT_4MIN,
@@ -39,6 +39,7 @@
3939
TIMEOUT_15SEC,
4040
TIMEOUT_20SEC,
4141
TIMEOUT_30SEC,
42+
TIMEOUT_40MIN,
4243
USED,
4344
VIRT_HANDLER,
4445
Images,
@@ -47,7 +48,7 @@
4748
cleanup_artifactory_secret_and_config_map,
4849
get_artifactory_config_map,
4950
get_artifactory_secret,
50-
get_http_image_url,
51+
get_test_artifact_server_url,
5152
)
5253
from utilities.monitoring import get_metrics_value
5354
from utilities.virt import VirtualMachineForTests, running_vm
@@ -323,65 +324,57 @@ def validate_metric_value_within_range(
323324
raise
324325

325326

326-
def network_packets_received(vm: VirtualMachineForTests, interface_name: str) -> dict[str, str]:
327-
ip_link_show_content = run_ssh_commands(host=vm.ssh_exec, commands=shlex.split("ip -s link show"))[0]
327+
def network_packets_received(
328+
vm: VirtualMachineForTests, interface_name: str, windows_wsl: bool = False
329+
) -> dict[str, str]:
330+
ip_link_show_content = run_ssh_commands(
331+
host=vm.ssh_exec, commands=shlex.split(f"{'wsl' if windows_wsl else ''} ip -s link show")
332+
)[0]
333+
328334
pattern = re.compile(
329335
rf".*?{re.escape(interface_name)}:.*?" # Match the line with the interface name
330-
r"(?:RX:\s+bytes\s+packets\s+errors\s+dropped\s+.*?(\d+)\s+(\d+)\s+(\d+)\s+(\d+)).*?" # Capture RX stats
331-
r"(?:TX:\s+bytes\s+packets\s+errors\s+dropped\s+.*?(\d+)\s+(\d+)\s+(\d+)\s+(\d+))", # Capture TX stats
336+
r"RX:.*?\n\s+(?P<rx_bytes>\d+)\s+(?P<rx_packets>\d+)\s+(?P<rx_errs>\d+)\s+(?P<rx_drop>\d+)\s+\d+\s+\d+.*?"
337+
r"TX:.*?\n\s+(?P<tx_bytes>\d+)\s+(?P<tx_packets>\d+)\s+(?P<tx_errs>\d+)\s+(?P<tx_drop>\d+)",
332338
re.DOTALL | re.IGNORECASE,
333339
)
334340
match = pattern.search(string=ip_link_show_content)
341+
335342
if match:
336-
rx_bytes, rx_packets, rx_errs, rx_drop, tx_bytes, tx_packets, tx_errs, tx_drop = match.groups()
337-
return {
338-
"rx_bytes": rx_bytes,
339-
"rx_packets": rx_packets,
340-
"rx_errs": rx_errs,
341-
"rx_drop": rx_drop,
342-
"tx_bytes": tx_bytes,
343-
"tx_packets": tx_packets,
344-
"tx_errs": tx_errs,
345-
"tx_drop": tx_drop,
346-
}
347-
return {}
343+
result = match.groupdict()
344+
LOGGER.info(f"Successfully parsed network stats: {result}")
345+
return result
346+
raise ValueError(f"No match found for interface '{interface_name}' in ip link show output : {ip_link_show_content}")
348347

349348

350349
def compare_network_traffic_bytes_and_metrics(
351-
prometheus: Prometheus, vm: VirtualMachineForTests, vm_interface_name: str
350+
prometheus: Prometheus, vm: VirtualMachineForTests, network_packet_received: dict[str, str]
352351
) -> bool:
353-
packet_received = network_packets_received(vm=vm, interface_name=vm_interface_name)
354352
rx_tx_indicator = False
355-
LOGGER.info("Waiting for metric kubevirt_vmi_network_traffic_bytes_total to update")
356-
time.sleep(TIMEOUT_15SEC)
357353
metric_result = (
358354
prometheus.query(query=f"kubevirt_vmi_network_traffic_bytes_total{{name='{vm.name}'}}")
359355
.get("data")
360356
.get("result")
361357
)
362358
for entry in metric_result:
363359
entry_value = entry.get("value")[1]
364-
if math.isclose(
365-
int(entry_value), int(packet_received[f"{entry.get('metric').get('type')}_bytes"]), rel_tol=0.05
366-
):
360+
if int(entry_value) >= int(network_packet_received[f"{entry.get('metric').get('type')}_bytes"]):
367361
rx_tx_indicator = True
368362
else:
369363
break
370-
if rx_tx_indicator:
371-
return True
372-
return False
364+
365+
return rx_tx_indicator
373366

374367

375368
def validate_network_traffic_metrics_value(
376-
prometheus: Prometheus, vm: VirtualMachineForTests, interface_name: str
369+
prometheus: Prometheus, vm: VirtualMachineForTests, network_packet_received: dict[str, str]
377370
) -> None:
378371
samples = TimeoutSampler(
379372
wait_timeout=TIMEOUT_4MIN,
380373
sleep=TIMEOUT_10SEC,
381374
func=compare_network_traffic_bytes_and_metrics,
382375
prometheus=prometheus,
383376
vm=vm,
384-
vm_interface_name=interface_name,
377+
network_packet_received=network_packet_received,
385378
)
386379
try:
387380
for sample in samples:
@@ -664,14 +657,14 @@ def create_windows11_wsl2_vm(
664657
artifactory_secret = get_artifactory_secret(namespace=namespace)
665658
artifactory_config_map = get_artifactory_config_map(namespace=namespace)
666659
dv = DataVolume(
660+
client=client,
667661
name=dv_name,
668662
namespace=namespace,
669-
storage_class=storage_class,
670-
source="http",
671-
url=get_http_image_url(image_directory=Images.Windows.DIR, image_name=Images.Windows.WIN11_WSL2_IMG),
672-
size=Images.Windows.DEFAULT_DV_SIZE,
673-
client=client,
674663
api_name="storage",
664+
source=REGISTRY_STR,
665+
size=Images.Windows.CONTAINER_DISK_DV_SIZE,
666+
storage_class=storage_class,
667+
url=f"{get_test_artifact_server_url(schema=REGISTRY_STR)}/docker/windows-qe/win_11:virtio",
675668
secret=artifactory_secret,
676669
cert_configmap=artifactory_config_map.name,
677670
)
@@ -681,15 +674,17 @@ def create_windows11_wsl2_vm(
681674
name=vm_name,
682675
namespace=namespace,
683676
client=client,
684-
vm_instance_type=VirtualMachineClusterInstancetype(name="u1.xlarge"),
685-
vm_preference=VirtualMachineClusterPreference(name="windows.11"),
677+
vm_instance_type=VirtualMachineClusterInstancetype(client=client, name="u1.large"),
678+
vm_preference=VirtualMachineClusterPreference(client=client, name="windows.11"),
686679
data_volume_template={"metadata": dv.res["metadata"], "spec": dv.res["spec"]},
687680
) as vm:
688-
running_vm(vm=vm)
689-
yield vm
690-
cleanup_artifactory_secret_and_config_map(
691-
artifactory_secret=artifactory_secret, artifactory_config_map=artifactory_config_map
692-
)
681+
try:
682+
running_vm(vm=vm, dv_wait_timeout=TIMEOUT_40MIN)
683+
yield vm
684+
finally:
685+
cleanup_artifactory_secret_and_config_map(
686+
artifactory_secret=artifactory_secret, artifactory_config_map=artifactory_config_map
687+
)
693688

694689

695690
def get_vm_comparison_info_dict(vm: VirtualMachineForTests) -> dict[str, str]:
@@ -734,7 +729,10 @@ def get_pvc_size_bytes(vm: VirtualMachineForTests) -> str:
734729

735730

736731
def validate_metric_value_greater_than_initial_value(
737-
prometheus: Prometheus, metric_name: str, initial_value: float, timeout: int = TIMEOUT_4MIN
732+
prometheus: Prometheus,
733+
metric_name: str,
734+
initial_value: float,
735+
timeout: int = TIMEOUT_4MIN,
738736
) -> None:
739737
samples = TimeoutSampler(
740738
wait_timeout=timeout,

0 commit comments

Comments
 (0)