Skip to content
Open
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
5 changes: 3 additions & 2 deletions tests/storage/cdi_clone/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ocp_resources.datavolume import DataVolume

from tests.storage.constants import QUAY_FEDORA_CONTAINER_IMAGE
from tests.storage.stop_status_utils import dv_stop_status_restart_threshold
from utilities.constants import REGISTRY_STR, Images
from utilities.storage import create_dv, data_volume

Expand Down Expand Up @@ -37,7 +38,7 @@ def fedora_dv_with_filesystem_volume_mode(
volume_mode=DataVolume.VolumeMode.FILE,
client=unprivileged_client,
) as dv:
dv.wait_for_dv_success()
dv.wait_for_dv_success(stop_status_func=dv_stop_status_restart_threshold, dv=dv)
yield dv


Expand All @@ -57,5 +58,5 @@ def fedora_dv_with_block_volume_mode(
volume_mode=DataVolume.VolumeMode.BLOCK,
client=unprivileged_client,
) as dv:
dv.wait_for_dv_success()
dv.wait_for_dv_success(stop_status_func=dv_stop_status_restart_threshold, dv=dv)
yield dv
23 changes: 19 additions & 4 deletions tests/storage/cdi_clone/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ocp_resources.datavolume import DataVolume

from tests.os_params import FEDORA_LATEST, WINDOWS_11, WINDOWS_11_TEMPLATE_LABELS
from tests.storage.stop_status_utils import dv_stop_status_restart_threshold
from tests.storage.utils import (
assert_pvc_snapshot_clone_annotation,
assert_use_populator,
Expand Down Expand Up @@ -93,7 +94,11 @@ def test_successful_clone_of_large_image(
storage_class=data_volume_multi_storage_scope_function.storage_class,
client=namespace.client,
) as cdv:
cdv.wait_for_dv_success(timeout=WINDOWS_CLONE_TIMEOUT)
cdv.wait_for_dv_success(
timeout=WINDOWS_CLONE_TIMEOUT,
stop_status_func=dv_stop_status_restart_threshold,
dv=cdv,
)


@pytest.mark.sno
Expand Down Expand Up @@ -125,7 +130,10 @@ def test_successful_vm_restart_with_cloned_dv(
cdv.wait_for_status(status=DataVolume.Status.PENDING_POPULATION, timeout=TIMEOUT_1MIN)
cdv.pvc.wait()
else:
cdv.wait_for_dv_success()
cdv.wait_for_dv_success(
stop_status_func=dv_stop_status_restart_threshold,
dv=cdv,
)
with create_vm_from_dv(
client=unprivileged_client,
dv=cdv,
Expand Down Expand Up @@ -180,7 +188,11 @@ def test_successful_vm_from_cloned_dv_windows(
source_pvc=data_volume_multi_storage_scope_function.name,
storage_class=data_volume_multi_storage_scope_function.storage_class,
) as cdv:
cdv.wait_for_dv_success(timeout=WINDOWS_CLONE_TIMEOUT)
cdv.wait_for_dv_success(
timeout=WINDOWS_CLONE_TIMEOUT,
stop_status_func=dv_stop_status_restart_threshold,
dv=cdv,
)
create_windows_vm_validate_guest_agent_info(
dv=cdv,
namespace=namespace,
Expand Down Expand Up @@ -227,7 +239,10 @@ def test_successful_snapshot_clone(
source_pvc=data_volume_snapshot_capable_storage_scope_function.name,
storage_class=storage_class,
) as cdv:
cdv.wait_for_dv_success()
cdv.wait_for_dv_success(
stop_status_func=dv_stop_status_restart_threshold,
dv=cdv,
)
if OS_FLAVOR_WINDOWS not in data_volume_snapshot_capable_storage_scope_function.url.split("/")[-1]:
with create_vm_from_dv(
client=unprivileged_client,
Expand Down
34 changes: 34 additions & 0 deletions tests/storage/stop_status_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import annotations

import logging
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from ocp_resources.datavolume import DataVolume

LOGGER = logging.getLogger(__name__)


def dv_stop_status_restart_threshold(dv: DataVolume, restart_count_threshold: int = 3) -> bool:
"""Function for detecting excessive DV restarts.

Args:
dv: The DataVolume to check.
restart_count_threshold: The threshold for restart count (default: 3).

Returns:
True if restarts exceed threshold.

Example::
dv.wait_for_dv_success(
stop_status_func=dv_stop_status_after_three_restarts,
dv=dv,
restart_count_threshold=4,
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
"""
dv_status = getattr(dv.instance, "status", None)
restart_count = getattr(dv_status, "restartCount", 0) or 0
if restart_count >= restart_count_threshold:
LOGGER.error(f"DV {dv.name} has {restart_count} restarts, stopping")
return True
return False