Skip to content

Commit c603ae0

Browse files
authored
Wait for DataSource availability after re-enabling common boot image (#4860)
##### Short description: enable_common_boot_image_import_spec_wait_for_data_import_cron waits for DataImportCrons, SSP conditions and HCO conditions but none of these reflect DataSource state. CDI populates DataSource.Spec.Source asynchronously after the import completes so in slow environments tests can hit flaky behavior. ##### More details: ##### What this PR does / why we need it: Wait for DataSource after re-enabling enableCommonBootImageImport. Without this, downstream tests can hit StopIteration on an empty DataSource.Spec.Source during the recovery window.(This behavior is observed few times in CI) ##### Which issue(s) this PR fixes: cnv-tests-runner-containerized/6117/testReport/ --this failure is seen often ##### Special notes for reviewer: makes tests stable. Current we failing lanes and jira tickets has more details ##### jira-ticket: https://redhat.atlassian.net/browse/CNV-87599 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Ensures boot sources are re-imported and verified after automatic data-import cycles to avoid missed updates. * **Improvements** * More precise timeout handling for readiness checks and clearer, structured logging on failures. * Docstrings and status semantics clarified for reliability and maintainability. * **Tests** * Unit tests updated to assert the new verification step runs during enablement flows. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/RedHatQE/openshift-virtualization-tests/pull/4860?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Geetika Kapoor <gkapoor@redhat.com>
1 parent 9a862bf commit c603ae0

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

utilities/hco.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
wait_for_deleted_data_import_crons,
3636
wait_for_ssp_conditions,
3737
)
38+
from utilities.storage import verify_boot_sources_reimported
3839

3940
LOGGER = logging.getLogger(__name__)
4041

@@ -381,6 +382,11 @@ def enable_common_boot_image_import_spec_wait_for_data_import_cron(hco_resource,
381382
wait_for_at_least_one_auto_update_data_import_cron(admin_client=admin_client, namespace=namespace)
382383
wait_for_ssp_conditions(admin_client=admin_client, hco_namespace=hco_namespace)
383384
wait_for_hco_conditions(admin_client=admin_client, hco_namespace=hco_namespace)
385+
assert verify_boot_sources_reimported(
386+
admin_client=admin_client,
387+
namespace=namespace.name,
388+
consecutive_checks_count=1,
389+
)
384390

385391

386392
def update_common_boot_image_import_spec(hco_resource, enable):

utilities/storage.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,18 @@ def get_data_sources_managed_by_data_import_cron(client: DynamicClient, namespac
11201120
def verify_boot_sources_reimported(
11211121
admin_client: DynamicClient, namespace: str, consecutive_checks_count: int = 6
11221122
) -> bool:
1123-
"""
1124-
Verify that the boot sources are re-imported while changing a storage class.
1123+
"""Verify all DataImportCron-managed DataSources reach Ready=True.
1124+
1125+
Checks DataSources sequentially each with its own timeout. Stops on the first
1126+
DataSource that does not become ready.
1127+
1128+
Args:
1129+
admin_client: Cluster admin client.
1130+
namespace: Namespace containing the DataImportCron-managed DataSources.
1131+
consecutive_checks_count: Consecutive Ready=True polls required for stability.
1132+
1133+
Returns:
1134+
True if all DataSources reached Ready=True otherwise false
11251135
"""
11261136
try:
11271137
for data_source in get_data_sources_managed_by_data_import_cron(client=admin_client, namespace=namespace):
@@ -1136,13 +1146,11 @@ def verify_boot_sources_reimported(
11361146
resource_name=data_source.name,
11371147
)
11381148
return True
1139-
except (TimeoutExpiredError, Exception) as exception:
1140-
fail_message = (
1141-
"Failed to re-import boot sources, exiting the pytest execution"
1142-
if isinstance(exception, TimeoutExpiredError)
1143-
else str(exception)
1149+
except TimeoutExpiredError as exception:
1150+
LOGGER.error(
1151+
f"Boot source DataSource did not reach Ready=True within {TIMEOUT_10MIN}s. "
1152+
f"namespace={namespace!r}, data_source={data_source.name!r}, timeout_error={exception!r}"
11441153
)
1145-
LOGGER.error(fail_message)
11461154
return False
11471155

11481156

utilities/unittests/test_hco.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,10 @@ class TestEnableCommonBootImageImportSpecWaitForDataImportCron:
802802
@patch("utilities.hco.wait_for_at_least_one_auto_update_data_import_cron")
803803
@patch("utilities.hco.update_common_boot_image_import_spec")
804804
@patch("utilities.hco.Namespace")
805+
@patch("utilities.hco.verify_boot_sources_reimported", return_value=True)
805806
def test_enable_spec(
806807
self,
808+
mock_verify_boot,
807809
mock_namespace_class,
808810
mock_update_spec,
809811
mock_wait_dic,
@@ -822,6 +824,11 @@ def test_enable_spec(
822824
mock_wait_dic.assert_called_once()
823825
mock_wait_ssp.assert_called_once()
824826
mock_wait_hco.assert_called_once()
827+
mock_verify_boot.assert_called_once_with(
828+
admin_client=mock_admin_client,
829+
namespace=mock_namespace.name,
830+
consecutive_checks_count=1,
831+
)
825832

826833

827834
class TestUpdateCommonBootImageImportSpec:

0 commit comments

Comments
 (0)