Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
106 changes: 1 addition & 105 deletions tests/observability/metrics/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
from ocp_resources.data_source import DataSource
from ocp_resources.datavolume import DataVolume
from ocp_resources.deployment import Deployment
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
from ocp_resources.pod import Pod
Expand All @@ -25,43 +24,35 @@
ZERO_CPU_CORES,
disk_file_system_info,
enable_swap_fedora_vm,
fail_if_not_zero_restartcount,
metric_result_output_dict_by_mountpoint,
restart_cdi_worker_pod,
wait_for_metric_vmi_request_cpu_cores_output,
)
from tests.observability.utils import validate_metrics_value
from tests.utils import create_vms
from utilities import console
from utilities.constants import (
CDI_UPLOAD_TMP_PVC,
NODE_STR,
ONE_CPU_CORE,
OS_FLAVOR_FEDORA,
PVC,
SOURCE_POD,
SSP_OPERATOR,
TIMEOUT_2MIN,
TIMEOUT_4MIN,
TIMEOUT_15SEC,
TIMEOUT_30MIN,
TWO_CPU_CORES,
TWO_CPU_SOCKETS,
TWO_CPU_THREADS,
VIRT_TEMPLATE_VALIDATOR,
Images,
)
from utilities.hco import ResourceEditorValidateHCOReconcile
from utilities.infra import create_ns, get_http_image_url, get_node_selector_dict, get_pod_by_name_prefix, unique_name
from utilities.infra import create_ns, get_node_selector_dict, get_pod_by_name_prefix, unique_name
from utilities.monitoring import get_metrics_value
from utilities.network import assert_ping_successful
from utilities.ssp import verify_ssp_pod_is_running
from utilities.storage import (
create_dv,
data_volume_template_with_source_ref_dict,
is_snapshot_supported_by_sc,
vm_snapshot,
wait_for_cdi_worker_pod,
)
from utilities.virt import (
VirtualMachineForTests,
Expand Down Expand Up @@ -202,101 +193,6 @@ def virt_up_metrics_values(request, prometheus):
return int(query_response[0]["value"][1])


@pytest.fixture()
def windows_dv_with_block_volume_mode(
namespace,
unprivileged_client,
storage_class_with_block_volume_mode,
):
with create_dv(
dv_name="test-dv-windows-image",
namespace=namespace.name,
url=get_http_image_url(image_directory=Images.Windows.UEFI_WIN_DIR, image_name=Images.Windows.WIN2k19_IMG),
size=Images.Windows.DEFAULT_DV_SIZE,
storage_class=storage_class_with_block_volume_mode,
client=unprivileged_client,
volume_mode=DataVolume.VolumeMode.BLOCK,
) as dv:
dv.wait_for_dv_success(timeout=TIMEOUT_30MIN)
yield dv


@pytest.fixture()
def cloned_dv_from_block_to_fs(
unprivileged_client,
windows_dv_with_block_volume_mode,
storage_class_with_filesystem_volume_mode,
):
with create_dv(
source=PVC,
dv_name="cloned-test-dv-windows-image",
namespace=windows_dv_with_block_volume_mode.namespace,
source_pvc=windows_dv_with_block_volume_mode.name,
source_namespace=windows_dv_with_block_volume_mode.namespace,
size=windows_dv_with_block_volume_mode.size,
storage_class=storage_class_with_filesystem_volume_mode,
client=unprivileged_client,
volume_mode=DataVolume.VolumeMode.FILE,
) as cdv:
cdv.wait_for_status(status=DataVolume.Status.CLONE_IN_PROGRESS, timeout=TIMEOUT_2MIN)
yield cdv


@pytest.fixture()
def running_cdi_worker_pod(cloned_dv_from_block_to_fs):
for pod_name in [CDI_UPLOAD_TMP_PVC, SOURCE_POD]:
wait_for_cdi_worker_pod(
pod_name=pod_name,
storage_ns_name=cloned_dv_from_block_to_fs.namespace,
).wait_for_status(status=Pod.Status.RUNNING, timeout=TIMEOUT_2MIN)


@pytest.fixture()
def restarted_cdi_dv_clone(
unprivileged_client,
cloned_dv_from_block_to_fs,
running_cdi_worker_pod,
):
restart_cdi_worker_pod(
unprivileged_client=unprivileged_client,
dv=cloned_dv_from_block_to_fs,
pod_prefix=CDI_UPLOAD_TMP_PVC,
)


@pytest.fixture()
def ready_uploaded_dv(unprivileged_client, namespace):
with create_dv(
source=UPLOAD_STR,
dv_name=f"{UPLOAD_STR}-dv",
namespace=namespace.name,
storage_class=py_config["default_storage_class"],
client=unprivileged_client,
) as dv:
dv.wait_for_status(status=DataVolume.Status.UPLOAD_READY, timeout=TIMEOUT_2MIN)
yield dv


@pytest.fixture()
def restarted_cdi_dv_upload(unprivileged_client, ready_uploaded_dv):
restart_cdi_worker_pod(
unprivileged_client=unprivileged_client,
dv=ready_uploaded_dv,
pod_prefix=CDI_UPLOAD_PRIME,
)
ready_uploaded_dv.wait_for_status(status=DataVolume.Status.UPLOAD_READY, timeout=TIMEOUT_2MIN)


@pytest.fixture()
def zero_clone_dv_restart_count(cloned_dv_from_block_to_fs):
fail_if_not_zero_restartcount(dv=cloned_dv_from_block_to_fs)


@pytest.fixture()
def zero_upload_dv_restart_count(ready_uploaded_dv):
fail_if_not_zero_restartcount(dv=ready_uploaded_dv)


@pytest.fixture()
def connected_vm_console_successfully(vm_for_test, prometheus):
with console.Console(vm=vm_for_test) as vmc:
Expand Down
52 changes: 0 additions & 52 deletions tests/observability/metrics/test_cdi_metrics.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
import pytest

from tests.observability.metrics.utils import expected_metric_labels_and_values
from tests.observability.utils import validate_metrics_value
from utilities.constants import CDI_OPERATOR


@pytest.mark.polarion("CNV-10557")
def test_kubevirt_cdi_clone_pods_high_restart(
skip_test_if_no_block_sc,
prometheus,
zero_clone_dv_restart_count,
restarted_cdi_dv_clone,
):
validate_metrics_value(
prometheus=prometheus,
expected_value="1",
metric_name="kubevirt_cdi_clone_pods_high_restart",
)


@pytest.mark.polarion("CNV-10717")
def test_kubevirt_cdi_upload_pods_high_restart(
prometheus,
zero_upload_dv_restart_count,
restarted_cdi_dv_upload,
):
validate_metrics_value(
prometheus=prometheus,
expected_value="1",
metric_name="kubevirt_cdi_upload_pods_high_restart",
)


@pytest.mark.polarion("CNV-11744")
Expand All @@ -40,26 +11,3 @@ def test_metric_kubevirt_cdi_storageprofile_info(prometheus, storage_class_label
f"{{storageclass='{storage_class_labels_for_testing['storageclass']}'}}",
expected_labels_and_values=storage_class_labels_for_testing,
)


@pytest.mark.parametrize(
"scaled_deployment",
[
pytest.param(
{"deployment_name": CDI_OPERATOR, "replicas": 0},
marks=(pytest.mark.polarion("CNV-11722")),
id="Test_kubevirt_cdi_operator_up",
),
],
indirect=True,
)
def test_kubevirt_cdi_operator_up(
prometheus,
disabled_virt_operator,
scaled_deployment,
):
validate_metrics_value(
prometheus=prometheus,
expected_value="0",
metric_name="kubevirt_cdi_operator_up",
)
29 changes: 1 addition & 28 deletions tests/observability/metrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
from datetime import datetime, timezone
from typing import Any, Optional

import pytest
from kubernetes.dynamic import DynamicClient
from ocp_resources.datavolume import DataVolume
from ocp_resources.resource import Resource
from ocp_resources.virtual_machine import VirtualMachine
from ocp_utilities.monitoring import Prometheus
from pyhelper_utils.shell import run_command, run_ssh_commands
from pyhelper_utils.shell import run_ssh_commands
from timeout_sampler import TimeoutExpiredError, TimeoutSampler

from tests.observability.constants import KUBEVIRT_VIRT_OPERATOR_READY
Expand All @@ -37,9 +35,7 @@
USED,
VIRT_HANDLER,
)
from utilities.infra import get_pod_by_name_prefix
from utilities.monitoring import get_metrics_value
from utilities.storage import wait_for_dv_expected_restart_count
from utilities.virt import VirtualMachineForTests

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -314,29 +310,6 @@ def get_resource_object(
)


def restart_cdi_worker_pod(unprivileged_client: DynamicClient, dv: DataVolume, pod_prefix: str) -> None:
initial_dv_restartcount = dv.instance.get("status", {}).get("restartCount", 0)
for iteration in range(TOTAL_4_ITERATIONS - initial_dv_restartcount):
pod = get_pod_by_name_prefix(
dyn_client=unprivileged_client,
pod_prefix=pod_prefix,
namespace=dv.namespace,
)
dv_restartcount = dv.instance.get("status", {}).get("restartCount", 0)
run_command(
command=shlex.split(f"oc exec -n {dv.namespace} {pod.name} -- kill 1"),
check=False,
)
wait_for_dv_expected_restart_count(dv=dv, expected_result=dv_restartcount + 1)


def fail_if_not_zero_restartcount(dv: DataVolume) -> None:
restartcount = dv.instance.get("status", {}).get("restartCount", 0)

if restartcount != 0:
pytest.fail(f"dv {dv.name} restartcount is not zero,\n actual restartcount: {restartcount}")


def assert_virtctl_version_equal_metric_output(
virtctl_server_version: dict[str, str], metric_output: list[dict[str, dict[str, str]]]
) -> None:
Expand Down
17 changes: 0 additions & 17 deletions utilities/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,23 +972,6 @@ def get_storage_class_with_specified_volume_mode(volume_mode, sc_names):
LOGGER.error(f"No {sc_with_volume_mode} among {sc_names}")


def wait_for_dv_expected_restart_count(dv, expected_result):
try:
for sample in TimeoutSampler(
wait_timeout=TIMEOUT_3MIN,
sleep=TIMEOUT_20SEC,
func=lambda: dv.instance.get("status", {}).get("restartCount"),
):
if sample and sample >= expected_result:
return
except TimeoutExpiredError:
LOGGER.error(
f"error while restarting dv: {dv.name} ,expected restartCount: {expected_result}, "
f"actual restartCount: {sample}"
)
raise


@contextmanager
def create_vm_from_dv(
dv,
Expand Down