From 18c19d9e569eedd47e1e0c9293b3b05f63b58dad Mon Sep 17 00:00:00 2001 From: Aviadp Date: Mon, 5 May 2025 17:48:30 +0300 Subject: [PATCH 1/2] replaced the file count tracking logic with inode tracking, making the test more reliable as requested Signed-off-by: Aviadp --- .../z_cluster/test_rook_ceph_log_rotate.py | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/tests/functional/z_cluster/test_rook_ceph_log_rotate.py b/tests/functional/z_cluster/test_rook_ceph_log_rotate.py index b5f0b7d349d..c988593b0bf 100644 --- a/tests/functional/z_cluster/test_rook_ceph_log_rotate.py +++ b/tests/functional/z_cluster/test_rook_ceph_log_rotate.py @@ -1,7 +1,6 @@ import logging import time import pytest -import re from ocs_ci.ocs.constants import MANAGED_SERVICE_PLATFORMS from ocs_ci.ocs.resources.storage_cluster import verify_storage_cluster @@ -85,36 +84,29 @@ def get_pod_obj_based_on_id(self, pod_type): def verify_new_log_created(self, pod_type): """ - Verify new log created on /var/log/ceph + Rotation succeeded when the inode of .log changes. Args: pod_type (str): The type of pod [osd/mon/mgr/rgw/mds] Returns: - bool: True if a new log created, otherwise False - + bool: True if log rotation occurred (inode changed), otherwise False """ pod_obj = self.get_pod_obj_based_on_id(pod_type) - output_cmd = pod_obj.exec_cmd_on_pod(command="ls -lh /var/log/ceph") expected_string = ( self.podtype_id[pod_type][2] if pod_type == "rgw" else f"{self.podtype_id[pod_type][2]}{self.podtype_id[pod_type][1]}" ) - cnt_logs = len(re.findall(expected_string, output_cmd)) - if cnt_logs != int(self.podtype_id[pod_type][3]) + 1: - log.info(output_cmd) - log.error( - f"pod_type:{pod_type} cnt_logs_before_fill_log:" - f"{self.podtype_id[pod_type][3]} cnt_logs_after_fill_log:{cnt_logs}" - ) + inode_now = int( pod_obj.exec_cmd_on_pod( - command=f"dd if=/dev/urandom of=/var/log/ceph/{expected_string}.log bs=1M count=560", + command=f"stat -c %i /var/log/ceph/{expected_string}.log", out_yaml_format=False, container_name="log-collector", - ) - return False - return True + ).strip() + ) + # stored at index 3 during setup + return inode_now != self.podtype_id[pod_type][3] def test_rook_ceph_log_rotate(self): """ @@ -165,15 +157,21 @@ def test_rook_ceph_log_rotate(self): for pod_type in self.podtype_id: pod_obj = self.get_pod_obj_based_on_id(pod_type) - output_cmd = pod_obj.exec_cmd_on_pod(command="ls -l /var/log/ceph") expected_string = ( self.podtype_id[pod_type][2] if pod_type == "rgw" else f"{self.podtype_id[pod_type][2]}{self.podtype_id[pod_type][1]}" ) - self.podtype_id[pod_type].append( - len(re.findall(expected_string, output_cmd)) + # new check: remember the inode of the *active* log file + inode = int( + pod_obj.exec_cmd_on_pod( + command=f"stat -c %i /var/log/ceph/{expected_string}.log", + out_yaml_format=False, + container_name="log-collector", + ).strip() ) + self.podtype_id[pod_type].append(inode) + storagecluster_obj = OCP( resource_name=constants.DEFAULT_CLUSTERNAME, namespace=config.ENV_DATA["cluster_namespace"], From 3d787bb8cd8b575113163e7f9ed8ce17301b1cc2 Mon Sep 17 00:00:00 2001 From: Aviadp Date: Mon, 5 May 2025 18:11:01 +0300 Subject: [PATCH 2/2] Updated docstring, Added error handling, Split operations for readability Signed-off-by: Aviadp --- .../z_cluster/test_rook_ceph_log_rotate.py | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/functional/z_cluster/test_rook_ceph_log_rotate.py b/tests/functional/z_cluster/test_rook_ceph_log_rotate.py index c988593b0bf..c7f5e1fd751 100644 --- a/tests/functional/z_cluster/test_rook_ceph_log_rotate.py +++ b/tests/functional/z_cluster/test_rook_ceph_log_rotate.py @@ -84,13 +84,13 @@ def get_pod_obj_based_on_id(self, pod_type): def verify_new_log_created(self, pod_type): """ - Rotation succeeded when the inode of .log changes. + Verify if log rotation has occurred. Args: pod_type (str): The type of pod [osd/mon/mgr/rgw/mds] Returns: - bool: True if log rotation occurred (inode changed), otherwise False + bool: True if inode changed (rotation happened), else False """ pod_obj = self.get_pod_obj_based_on_id(pod_type) expected_string = ( @@ -98,13 +98,19 @@ def verify_new_log_created(self, pod_type): if pod_type == "rgw" else f"{self.podtype_id[pod_type][2]}{self.podtype_id[pod_type][1]}" ) - inode_now = int( - pod_obj.exec_cmd_on_pod( + + try: + cmd_output = pod_obj.exec_cmd_on_pod( command=f"stat -c %i /var/log/ceph/{expected_string}.log", out_yaml_format=False, container_name="log-collector", ).strip() - ) + inode_now = int(cmd_output) + except (ValueError, TypeError) as e: + log.error(f"Failed to get inode for {pod_type}: {e}") + log.error(f"Command output: {cmd_output}") + return False + # stored at index 3 during setup return inode_now != self.podtype_id[pod_type][3] @@ -162,15 +168,22 @@ def test_rook_ceph_log_rotate(self): if pod_type == "rgw" else f"{self.podtype_id[pod_type][2]}{self.podtype_id[pod_type][1]}" ) - # new check: remember the inode of the *active* log file - inode = int( - pod_obj.exec_cmd_on_pod( + + # Get the initial inode of the active log file + try: + cmd_output = pod_obj.exec_cmd_on_pod( command=f"stat -c %i /var/log/ceph/{expected_string}.log", out_yaml_format=False, container_name="log-collector", ).strip() - ) - self.podtype_id[pod_type].append(inode) + initial_inode = int(cmd_output) + except (ValueError, TypeError) as e: + log.error(f"Failed to get initial inode for {pod_type}: {e}") + log.error(f"Command output: {cmd_output}") + initial_inode = -1 # Use sentinel value to indicate error + + # Store the initial inode + self.podtype_id[pod_type].append(initial_inode) storagecluster_obj = OCP( resource_name=constants.DEFAULT_CLUSTERNAME,