Skip to content

Fixed failure in test_rook_ceph_log_rotate #12064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
51 changes: 31 additions & 20 deletions tests/functional/z_cluster/test_rook_ceph_log_rotate.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -85,36 +84,35 @@ 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
Verify if log rotation has occurred.

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 inode changed (rotation happened), else 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}"
)
pod_obj.exec_cmd_on_pod(
command=f"dd if=/dev/urandom of=/var/log/ceph/{expected_string}.log bs=1M count=560",

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
return True

# stored at index 3 during setup
return inode_now != self.podtype_id[pod_type][3]

def test_rook_ceph_log_rotate(self):
"""
Expand Down Expand Up @@ -165,15 +163,28 @@ 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))
)

# 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()
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,
namespace=config.ENV_DATA["cluster_namespace"],
Expand Down