diff --git a/ocs_ci/helpers/helpers.py b/ocs_ci/helpers/helpers.py index 9066c589ac8..1f0c3bf5447 100644 --- a/ocs_ci/helpers/helpers.py +++ b/ocs_ci/helpers/helpers.py @@ -4451,32 +4451,38 @@ def check_selinux_relabeling(pod_obj): logger.info(f"{key} is present in inspect logs of application pod running node") -def verify_log_exist_in_pod_logs( - pod_name, +def verify_log_exist_in_pods_logs( + pod_names, expected_log, container=None, namespace=config.ENV_DATA["cluster_namespace"], all_containers_flag=True, + since=None, ): """ - Verify log exist in pod logs. + Verify log exist in pods logs. Args: - pod_name (str): Name of the pod + pod_names (list): Name of the pod expected_log (str): the expected logs in "oc logs" command container (str): Name of the container namespace (str): Namespace of the pod all_containers_flag (bool): fetch logs from all containers of the resource + since (str): only return logs newer than a relative duration like 5s, 2m, or 3h. Returns: bool: return True if log exist otherwise False """ - pod_logs = pod.get_pod_logs( - pod_name, - namespace=namespace, - container=container, - all_containers=all_containers_flag, - ) - logger.info(f"logs osd:{pod_logs}") - return expected_log in pod_logs + for pod_name in pod_names: + pod_logs = pod.get_pod_logs( + pod_name, + namespace=namespace, + container=container, + all_containers=all_containers_flag, + since=since, + ) + logger.info(f"logs osd:{pod_logs}") + if expected_log in pod_logs: + return True + return False diff --git a/ocs_ci/ocs/resources/pod.py b/ocs_ci/ocs/resources/pod.py index 72a31042207..4e4bef014fc 100644 --- a/ocs_ci/ocs/resources/pod.py +++ b/ocs_ci/ocs/resources/pod.py @@ -1746,6 +1746,7 @@ def get_pod_logs( namespace=config.ENV_DATA["cluster_namespace"], previous=False, all_containers=False, + since=None, ): """ Get logs from a given pod @@ -1755,9 +1756,11 @@ def get_pod_logs( namespace (str): Namespace of the pod previous (bool): True, if pod previous log required. False otherwise. all_containers (bool): fetch logs from all containers of the resource + since (str): only return logs newer than a relative duration like 5s, 2m, or 3h. Returns: str: Output from 'oc get logs command + """ pod = OCP(kind=constants.POD, namespace=namespace) cmd = f"logs {pod_name}" @@ -1767,6 +1770,8 @@ def get_pod_logs( cmd += " --previous" if all_containers: cmd += " --all-containers=true" + if since: + cmd += f" --since={since}" return pod.exec_oc_cmd(cmd, out_yaml_format=False) diff --git a/tests/functional/pv/space_reclaim/test_rook_reclaim_namespace.py b/tests/functional/pv/space_reclaim/test_rook_reclaim_namespace.py new file mode 100644 index 00000000000..ad3138cf833 --- /dev/null +++ b/tests/functional/pv/space_reclaim/test_rook_reclaim_namespace.py @@ -0,0 +1,127 @@ +import logging +import time + +import pytest + + +from ocs_ci.ocs import constants +from ocs_ci.utility.utils import TimeoutSampler +from ocs_ci.ocs.resources.pod import get_csi_provisioner_pod +from ocs_ci.framework.pytest_customization.marks import green_squad +from ocs_ci.helpers.helpers import ( + create_reclaim_space_job, + verify_log_exist_in_pods_logs, +) +from ocs_ci.framework.testlib import ( + ManageTest, + tier2, + bugzilla, + skipif_ocs_version, +) + +log = logging.getLogger(__name__) + + +@green_squad +@tier2 +@bugzilla("2214838") +@skipif_ocs_version("<4.13") +@pytest.mark.polarion_id("OCS-5424") +class TestRookReclaimNamespace(ManageTest): + """ + Test Rook Reclaim Namespace + + """ + + @pytest.fixture(autouse=True) + def teardown(self, request): + def finalizer(): + try: + self.reclaim_job_after_pod_delete.delete() + self.reclaim_job_before_pod_delete.delete() + except Exception as e: + log.info(f"Exception: {e}") + + request.addfinalizer(finalizer) + + def test_rook_reclaim_namespace(self, pvc_factory, pod_factory, teardown_factory): + """ + Test Process: + + 1.Create RBD PVC with filesystem mode + 2.Create Pod using that PVC + 3.Create reclaimspacejob CR to run on that PVC + 4.Verify reclaimspacejob successful completion + 5.Check logs of csi-rbdplugin-provisioner-xxx/csi-rbdplugin pods. + 6.Verify sparsify is skipped. + 7.Delete pod + 8.Delete reclaimspacejob CR + 9.Recreate reclaimspacejob CR + 10.Sleep 120 seconds so the logs in csi-rbdplugin-provisioner-xxx/csi-rbdplugin will be updated + 11.Verify logs does not show 'skipping sparsify operation' message. + """ + log.info("Create RBD PVC with filesystem mode") + pvc_obj = pvc_factory( + interface=constants.CEPHBLOCKPOOL, + status=constants.STATUS_BOUND, + size=2, + ) + pod_dict_path = constants.NGINX_POD_YAML + raw_block_pv = False + + log.info( + f"Created new pod sc_name={constants.CEPHFILESYSTEM} size=10Gi, " + f"access_mode={constants.ACCESS_MODE_RWX}, volume_mode={constants.VOLUME_MODE_FILESYSTEM}" + ) + pod_obj = pod_factory( + interface=constants.CEPHFILESYSTEM, + pvc=pvc_obj, + status=constants.STATUS_RUNNING, + pod_dict_path=pod_dict_path, + raw_block_pv=raw_block_pv, + ) + + log.info(f"Create reclaimspacejob CR to run on pvc {pvc_obj.name}") + self.reclaim_job_before_pod_delete = create_reclaim_space_job( + pvc_name=pvc_obj.name + ) + expected_log = "skipping sparsify operation" + pod_names = get_csi_provisioner_pod(interface=constants.CEPHBLOCKPOOL) + + log.info( + f"Check logs of csi-rbdplugin-provisioner-xxx/csi-rbdplugin pods {pod_names}" + ) + sample = TimeoutSampler( + timeout=100, + sleep=5, + func=verify_log_exist_in_pods_logs, + pod_names=pod_names, + expected_log=expected_log, + ) + if not sample.wait_for_func_status(result=True): + raise ValueError( + f"The expected log '{expected_log}' does not exist in {pod_names} pods" + ) + + log.info(f"Delete pod {pod_obj.name}") + pod_obj.delete() + + log.info(f"Delete reclaimspacejob CR {self.reclaim_job_before_pod_delete.name}") + self.reclaim_job_before_pod_delete.delete() + + log.info("Recreate reclaimspacejob CR") + self.reclaim_job_after_pod_delete = create_reclaim_space_job( + pvc_name=pvc_obj.name + ) + + log.info(f"Sleep 120 seconds so the logs in {pod_names} will be updated") + time.sleep(120) + + log.info("Verify logs does not show 'skipping sparsify operation' message.") + log_exist = verify_log_exist_in_pods_logs( + pod_names=pod_names, expected_log=expected_log, since="120s" + ) + if log_exist: + raise ValueError( + f"The expected log '{expected_log}' exist in {pod_names} pods after reclaimspacejob deletion" + ) diff --git a/tests/functional/z_cluster/test_rook_ceph_osd_flapping.py b/tests/functional/z_cluster/test_rook_ceph_osd_flapping.py index 07abab5c645..5d5f570fb20 100644 --- a/tests/functional/z_cluster/test_rook_ceph_osd_flapping.py +++ b/tests/functional/z_cluster/test_rook_ceph_osd_flapping.py @@ -9,7 +9,7 @@ from ocs_ci.helpers.helpers import ( run_cmd_verify_cli_output, clear_crash_warning_and_osd_removal_leftovers, - verify_log_exist_in_pod_logs, + verify_log_exist_in_pods_logs, ) from ocs_ci.ocs.cluster import ceph_health_check from ocs_ci.ocs.resources import pod @@ -93,8 +93,8 @@ def test_rook_ceph_osd_flapping(self): sample = TimeoutSampler( timeout=60, sleep=5, - func=verify_log_exist_in_pod_logs, - pod_name=self.osd_pod_obj.name, + func=verify_log_exist_in_pods_logs, + pod_names=[self.osd_pod_obj.name], expected_log=expected_log, )