diff --git a/ocs_ci/ocs/bucket_utils.py b/ocs_ci/ocs/bucket_utils.py index 35af84bd9ab..787a218e4cd 100644 --- a/ocs_ci/ocs/bucket_utils.py +++ b/ocs_ci/ocs/bucket_utils.py @@ -140,6 +140,41 @@ def retrieve_test_objects_to_pod(podobj, target_dir): return downloaded_objects +def check_objects_in_bucket(bucket_name, objects_list, mcg_obj, s3pod, timeout=60): + """ + Checks object list present in bucket and compare it with uploaded object Lists + """ + + def _check_objects_in_bucket(bucket_name, objects_list, mcg_obj, s3pod): + obj_list = list_objects_from_bucket( + s3pod, + f"s3://{bucket_name}", + s3_obj=mcg_obj, + ) + if set(objects_list).issubset(obj_list): + logger.info(f"Object list {obj_list}") + return True + else: + return False + + try: + return any( + result + for result in TimeoutSampler( + timeout, + 10, + _check_objects_in_bucket, + bucket_name, + objects_list, + mcg_obj, + s3pod, + ) + ) + except TimeoutExpiredError: + logger.error("Objects are not synced within the time limit.") + return False + + def retrieve_anon_s3_resource(): """ Returns an anonymous boto3 S3 resource by creating one and disabling signing diff --git a/tests/manage/mcg/test_namespace_crd.py b/tests/manage/mcg/test_namespace_crd.py index 5743e3fda49..777350162dc 100644 --- a/tests/manage/mcg/test_namespace_crd.py +++ b/tests/manage/mcg/test_namespace_crd.py @@ -29,6 +29,7 @@ check_cached_objects_by_name, s3_delete_object, retrieve_verification_mode, + check_objects_in_bucket, wait_for_cache, ) from ocs_ci.framework.pytest_customization.marks import ( @@ -986,13 +987,19 @@ def test_respin_mcg_pod_and_check_data_integrity_crd( original_folder = test_directory_setup.origin_dir result_folder = test_directory_setup.result_dir logger.info("Upload files to NS bucket") - self.write_files_to_pod_and_upload( + uploaded_obj_list = self.write_files_to_pod_and_upload( mcg_obj, awscli_pod_session, bucket_to_write=ns_bucket, original_dir=original_folder, amount=3, ) + logger.info("list uploaded objects") + obj_ls = check_objects_in_bucket( + ns_bucket, uploaded_obj_list, mcg_obj, awscli_pod_session, timeout=60 + ) + if not obj_ls: + raise UnexpectedBehaviour("Failed to sync objects") logger.info(f"Respin mcg resource {mcg_pod}") noobaa_pods = pod.get_noobaa_pods()